DATACMNS-867 - Further fixes.
This commit is contained in:
@@ -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
|
||||
|
||||
@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
|
||||
@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
|
||||
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 {
|
||||
|
||||
@@ -22,6 +22,7 @@ import rx.Observable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -48,7 +49,7 @@ public class ReactiveRepositoryInformationUnitTests {
|
||||
|
||||
Method method = RxJava1InterfaceWithGenerics.class.getMethod("deleteAll");
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(RxJava1InterfaceWithGenerics.class);
|
||||
DefaultRepositoryInformation information = new DefaultRepositoryInformation(metadata, REPOSITORY, null);
|
||||
DefaultRepositoryInformation information = new DefaultRepositoryInformation(metadata, REPOSITORY, Optional.empty());
|
||||
|
||||
Method reference = information.getTargetClassMethod(method);
|
||||
assertEquals(ReactiveCrudRepository.class, reference.getDeclaringClass());
|
||||
@@ -60,7 +61,8 @@ public class ReactiveRepositoryInformationUnitTests {
|
||||
|
||||
Method method = RxJava1InterfaceWithGenerics.class.getMethod("save", Observable.class);
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(RxJava1InterfaceWithGenerics.class);
|
||||
DefaultRepositoryInformation information = new ReactiveRepositoryInformation(metadata, REPOSITORY, null);
|
||||
DefaultRepositoryInformation information = new ReactiveRepositoryInformation(metadata, REPOSITORY,
|
||||
Optional.empty());
|
||||
|
||||
Method reference = information.getTargetClassMethod(method);
|
||||
assertEquals(ReactiveCrudRepository.class, reference.getDeclaringClass());
|
||||
@@ -73,7 +75,8 @@ public class ReactiveRepositoryInformationUnitTests {
|
||||
|
||||
Method method = ReactiveSortingRepository.class.getMethod("save", Publisher.class);
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(ReactiveJavaInterfaceWithGenerics.class);
|
||||
DefaultRepositoryInformation information = new ReactiveRepositoryInformation(metadata, REPOSITORY, null);
|
||||
DefaultRepositoryInformation information = new ReactiveRepositoryInformation(metadata, REPOSITORY,
|
||||
Optional.empty());
|
||||
|
||||
Method reference = information.getTargetClassMethod(method);
|
||||
assertEquals(ReactiveCrudRepository.class, reference.getDeclaringClass());
|
||||
@@ -86,7 +89,8 @@ public class ReactiveRepositoryInformationUnitTests {
|
||||
|
||||
Method method = ReactiveJavaInterfaceWithGenerics.class.getMethod("save", Iterable.class);
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(ReactiveJavaInterfaceWithGenerics.class);
|
||||
DefaultRepositoryInformation information = new ReactiveRepositoryInformation(metadata, REPOSITORY, null);
|
||||
DefaultRepositoryInformation information = new ReactiveRepositoryInformation(metadata, REPOSITORY,
|
||||
Optional.empty());
|
||||
|
||||
Method reference = information.getTargetClassMethod(method);
|
||||
assertEquals(ReactiveCrudRepository.class, reference.getDeclaringClass());
|
||||
@@ -99,7 +103,8 @@ public class ReactiveRepositoryInformationUnitTests {
|
||||
|
||||
Method method = ReactiveJavaInterfaceWithGenerics.class.getMethod("save", Object.class);
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(ReactiveJavaInterfaceWithGenerics.class);
|
||||
DefaultRepositoryInformation information = new ReactiveRepositoryInformation(metadata, REPOSITORY, null);
|
||||
DefaultRepositoryInformation information = new ReactiveRepositoryInformation(metadata, REPOSITORY,
|
||||
Optional.empty());
|
||||
|
||||
Method reference = information.getTargetClassMethod(method);
|
||||
assertEquals(ReactiveCrudRepository.class, reference.getDeclaringClass());
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.repository.core.support;
|
||||
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
Reference in New Issue
Block a user