@ -110,22 +110,34 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
@@ -110,22 +110,34 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
@Test // DATACMNS-243
public void defaultsToFieldAccess ( ) {
assertThat ( getProperty ( FieldAccess . class , "name" ) . usePropertyAccess ( ) ) . isFalse ( ) ;
assertThat ( getProperty ( FieldAccess . class , "name" ) ) . hasValueSatisfying ( it - > {
assertThat ( it . usePropertyAccess ( ) ) . isFalse ( ) ;
} ) ;
}
@Test // DATACMNS-243
public void usesAccessTypeDeclaredOnTypeAsDefault ( ) {
assertThat ( getProperty ( PropertyAccess . class , "firstname" ) . usePropertyAccess ( ) ) . isTrue ( ) ;
assertThat ( getProperty ( PropertyAccess . class , "firstname" ) ) . hasValueSatisfying ( it - > {
assertThat ( it . usePropertyAccess ( ) ) . isTrue ( ) ;
} ) ;
}
@Test // DATACMNS-243
public void propertyAnnotationOverridesTypeConfiguration ( ) {
assertThat ( getProperty ( PropertyAccess . class , "lastname" ) . usePropertyAccess ( ) ) . isFalse ( ) ;
assertThat ( getProperty ( PropertyAccess . class , "lastname" ) ) . hasValueSatisfying ( it - > {
assertThat ( it . usePropertyAccess ( ) ) . isFalse ( ) ;
} ) ;
}
@Test // DATACMNS-243
public void fieldAnnotationOverridesTypeConfiguration ( ) {
assertThat ( getProperty ( PropertyAccess . class , "emailAddress" ) . usePropertyAccess ( ) ) . isFalse ( ) ;
assertThat ( getProperty ( PropertyAccess . class , "emailAddress" ) ) . hasValueSatisfying ( it - > {
assertThat ( it . usePropertyAccess ( ) ) . isFalse ( ) ;
} ) ;
}
@Test // DATACMNS-243
@ -135,22 +147,31 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
@@ -135,22 +147,31 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
@Test // DATACMNS-534
public void treatsNoAnnotationCorrectly ( ) {
assertThat ( getProperty ( ClassWithReadOnlyProperties . class , "noAnnotations" ) . isWritable ( ) ) . isTrue ( ) ;
assertThat ( getProperty ( ClassWithReadOnlyProperties . class , "noAnnotations" ) ) . hasValueSatisfying ( it - > {
assertThat ( it . isWritable ( ) ) . isTrue ( ) ;
} ) ;
}
@Test // DATACMNS-534
public void treatsTransientAsNotExisting ( ) {
assertThat ( getProperty ( ClassWithReadOnlyProperties . class , "transientProperty" ) ) . isNull ( ) ;
assertThat ( getProperty ( ClassWithReadOnlyProperties . class , "transientProperty" ) ) . isEmpty ( ) ;
}
@Test // DATACMNS-534
public void treatsReadOnlyAsNonWritable ( ) {
assertThat ( getProperty ( ClassWithReadOnlyProperties . class , "readOnlyProperty" ) . isWritable ( ) ) . isFalse ( ) ;
assertThat ( getProperty ( ClassWithReadOnlyProperties . class , "readOnlyProperty" ) ) . hasValueSatisfying ( it - > {
assertThat ( it . isWritable ( ) ) . isFalse ( ) ;
} ) ;
}
@Test // DATACMNS-534
public void considersPropertyWithReadOnlyMetaAnnotationReadOnly ( ) {
assertThat ( getProperty ( ClassWithReadOnlyProperties . class , "customReadOnlyProperty" ) . isWritable ( ) ) . isFalse ( ) ;
assertThat ( getProperty ( ClassWithReadOnlyProperties . class , "customReadOnlyProperty" ) ) . hasValueSatisfying ( it - > {
assertThat ( it . isWritable ( ) ) . isFalse ( ) ;
} ) ;
}
@Test // DATACMNS-556
@ -162,14 +183,17 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
@@ -162,14 +183,17 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
@SuppressWarnings ( "unchecked" )
public void cachesNonPresenceOfAnnotationOnField ( ) {
SamplePersistentProperty property = getProperty ( Sample . class , "getterWithoutField" ) ;
Optional < SamplePersistentProperty > property = getProperty ( Sample . class , "getterWithoutField" ) ;
assertThat ( property . findAnnotation ( MyAnnotation . class ) ) . isNotPresent ( ) ;
assertThat ( property ) . hasValueSatisfying ( it - > {
Map < Class < ? > , ? > field = ( Map < Class < ? > , ? > ) ReflectionTestUtils . getField ( property , "annotationCache" ) ;
assertThat ( it . findAnnotation ( MyAnnotation . class ) ) . isNotPresent ( ) ;
assertThat ( field . containsKey ( MyAnnotation . class ) ) . isTrue ( ) ;
assertThat ( field . get ( MyAnnotation . class ) ) . isEqualTo ( Optional . empty ( ) ) ;
Map < Class < ? > , ? > field = ( Map < Class < ? > , ? > ) ReflectionTestUtils . getField ( it , "annotationCache" ) ;
assertThat ( field . containsKey ( MyAnnotation . class ) ) . isTrue ( ) ;
assertThat ( field . get ( MyAnnotation . class ) ) . isEqualTo ( Optional . empty ( ) ) ;
} ) ;
}
@Test // DATACMNS-825
@ -214,8 +238,8 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
@@ -214,8 +238,8 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
return annotation . get ( ) ;
}
private SamplePersistentProperty getProperty ( Class < ? > type , String name ) {
return context . getRequiredPersistentEntity ( type ) . getPersistentProperty ( name ) . orElse ( null ) ;
private Optional < SamplePersistentProperty > getProperty ( Class < ? > type , String name ) {
return context . getRequiredPersistentEntity ( type ) . getPersistentProperty ( name ) ;
}
static class Sample {