PropertyUtilsTest.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:reflection-util 作者:
@Test
public void testGetAnnotationOfProperty() throws Exception {
    Nullable relationship = PropertyUtils.getAnnotationOfProperty(TestEntity.class, TestEntity::getSomeObject, Nullable.class);
    assertNotNull(relationship);

    Size size = PropertyUtils.getAnnotationOfProperty(TestEntity.class, TestEntity::getSomeObject, Size.class);
    assertNull(size);

    Size numberSize = PropertyUtils.getAnnotationOfProperty(TestEntity.class, TestEntity::getNumber, Size.class);
    assertNotNull(numberSize);
    assertThat(numberSize.min(), is(10));
    assertThat(numberSize.max(), is(20));

    Size stringSize = PropertyUtils.getAnnotationOfProperty(TestEntity.class, TestEntity::getString, Size.class);
    assertNotNull(stringSize);
    assertThat(stringSize.min(), is(0));
    assertThat(stringSize.max(), is(1000));

    assertTrue(Modifier.isPublic(BaseClass.class.getField(PropertyUtils.getPropertyName(DerivedClass.class, DerivedClass::getOtherStringProperty)).getModifiers()));
    Size otherStringSize = PropertyUtils.getAnnotationOfProperty(DerivedClass.class, DerivedClass::getOtherStringProperty, Size.class);
    assertNotNull(otherStringSize);
    assertThat(otherStringSize.min(), is(10));
    assertThat(otherStringSize.max(), is(20));

    Size baseClassStringSize = PropertyUtils.getAnnotationOfProperty(DerivedClass.class, BaseClass::getBaseClassStringProperty, Size.class);
    assertNotNull(baseClassStringSize);
    assertThat(baseClassStringSize.max(), is(30));

    Size interfaceStringSize = PropertyUtils.getAnnotationOfProperty(BaseInterface.class, BaseInterface::getSizeFromInterface, Size.class);
    assertNotNull(interfaceStringSize);
    assertThat(interfaceStringSize.max(), is(40));

    PropertyDescriptor propertyDescriptor = PropertyUtils.getPropertyDescriptor(TestEntity.class, TestEntity::getString);
    assertNotNull(PropertyUtils.getAnnotationOfProperty(new TestEntity(), propertyDescriptor, Size.class));
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号