descriptor = MetaAnnotationUtils.findAnnotationDescriptor(type, Persistent.class);
-
- if (descriptor != null && descriptor.getComposedAnnotation() != null) {
-
- Annotation composed = descriptor.getComposedAnnotation();
-
- for (Method method : descriptor.getComposedAnnotationType().getDeclaredMethods()) {
-
- keyspace = AnnotationUtils.findAnnotation(method, KeySpace.class);
-
- if (keyspace != null) {
- return AnnotationUtils.getValue(composed, method.getName());
- }
- }
- }
-
return null;
}
-
- /**
- * {@code MetaAnnotationUtils} is a collection of utility methods that complements the standard support already
- * available in {@link AnnotationUtils}.
- *
- * Whereas {@code AnnotationUtils} provides utilities for getting or finding an annotation,
- * {@code MetaAnnotationUtils} goes a step further by providing support for determining the root class on
- * which an annotation is declared, either directly or indirectly via a composed
- * annotation. This additional information is encapsulated in an {@link AnnotationDescriptor}.
- *
- * The additional information provided by an {@code AnnotationDescriptor} is required by the
- * Spring TestContext Framework in order to be able to support class hierarchy traversals for annotations
- * such as {@link org.springframework.test.context.ContextConfiguration @ContextConfiguration},
- * {@link org.springframework.test.context.TestExecutionListeners @TestExecutionListeners}, and
- * {@link org.springframework.test.context.ActiveProfiles @ActiveProfiles} which offer support for merging and
- * overriding various inherited annotation attributes (e.g.,
- * {@link org.springframework.test.context.ContextConfiguration#inheritLocations}).
- *
- * @author Sam Brannen
- * @since 4.0
- * @see AnnotationUtils
- * @see AnnotationDescriptor
- */
- static abstract class MetaAnnotationUtils {
-
- private MetaAnnotationUtils() {
- /* no-op */
- }
-
- /**
- * Find the {@link AnnotationDescriptor} for the supplied {@code annotationType} on the supplied {@link Class},
- * traversing its annotations and superclasses if no annotation can be found on the given class itself.
- *
- * This method explicitly handles class-level annotations which are not declared as
- * {@linkplain java.lang.annotation.Inherited inherited} as
- * well as meta-annotations.
- *
- * The algorithm operates as follows:
- *
- * - Search for the annotation on the given class and return a corresponding {@code AnnotationDescriptor} if
- * found.
- *
- Recursively search through all annotations that the given class declares.
- *
- Recursively search through the superclass hierarchy of the given class.
- *
- *
- * In this context, the term recursively means that the search process continues by returning to step #1
- * with the current annotation or superclass as the class to look for annotations on.
- *
- * If the supplied {@code clazz} is an interface, only the interface itself will be checked; the inheritance
- * hierarchy for interfaces will not be traversed.
- *
- * @param clazz the class to look for annotations on
- * @param annotationType the type of annotation to look for
- * @return the corresponding annotation descriptor if the annotation was found; otherwise {@code null}
- * @see AnnotationUtils#findAnnotationDeclaringClass(Class, Class)
- * @see #findAnnotationDescriptorForTypes(Class, Class...)
- */
- public static AnnotationDescriptor findAnnotationDescriptor(Class> clazz,
- Class annotationType) {
- return findAnnotationDescriptor(clazz, new HashSet<>(), annotationType);
- }
-
- /**
- * Perform the search algorithm for {@link #findAnnotationDescriptor(Class, Class)}, avoiding endless recursion by
- * tracking which annotations have already been visited.
- *
- * @param clazz the class to look for annotations on
- * @param visited the set of annotations that have already been visited
- * @param annotationType the type of annotation to look for
- * @return the corresponding annotation descriptor if the annotation was found; otherwise {@code null}
- */
- private static AnnotationDescriptor findAnnotationDescriptor(Class> clazz,
- Set visited, Class annotationType) {
-
- Assert.notNull(annotationType, "Annotation type must not be null");
-
- if (clazz == null || clazz.equals(Object.class)) {
- return null;
- }
-
- // Declared locally?
- if (AnnotationUtils.isAnnotationDeclaredLocally(annotationType, clazz)) {
- return new AnnotationDescriptor<>(clazz, clazz.getAnnotation(annotationType));
- }
-
- // Declared on a composed annotation (i.e., as a meta-annotation)?
- for (Annotation composedAnnotation : clazz.getDeclaredAnnotations()) {
- if (!AnnotationUtils.isInJavaLangAnnotationPackage(composedAnnotation) && visited.add(composedAnnotation)) {
- AnnotationDescriptor descriptor = findAnnotationDescriptor(composedAnnotation.annotationType(), visited,
- annotationType);
- if (descriptor != null) {
- return new AnnotationDescriptor<>(clazz, descriptor.getDeclaringClass(), composedAnnotation,
- descriptor.getAnnotation());
- }
- }
- }
-
- // Declared on a superclass?
- return findAnnotationDescriptor(clazz.getSuperclass(), visited, annotationType);
- }
-
- /**
- * Find the {@link UntypedAnnotationDescriptor} for the first {@link Class} in the inheritance hierarchy of the
- * specified {@code clazz} (including the specified {@code clazz} itself) which declares at least one of the
- * specified {@code annotationTypes}.
- *
- * This method traverses the annotations and superclasses of the specified {@code clazz} if no annotation can be
- * found on the given class itself.
- *
- * This method explicitly handles class-level annotations which are not declared as
- * {@linkplain java.lang.annotation.Inherited inherited} as
- * well as meta-annotations.
- *
- * The algorithm operates as follows:
- *
- * - Search for a local declaration of one of the annotation types on the given class and return a corresponding
- * {@code UntypedAnnotationDescriptor} if found.
- *
- Recursively search through all annotations that the given class declares.
- *
- Recursively search through the superclass hierarchy of the given class.
- *
- *
- * In this context, the term recursively means that the search process continues by returning to step #1
- * with the current annotation or superclass as the class to look for annotations on.
- *
- * If the supplied {@code clazz} is an interface, only the interface itself will be checked; the inheritance
- * hierarchy for interfaces will not be traversed.
- *
- * @param clazz the class to look for annotations on
- * @param annotationTypes the types of annotations to look for
- * @return the corresponding annotation descriptor if one of the annotations was found; otherwise {@code null}
- * @see AnnotationUtils#findAnnotationDeclaringClassForTypes(java.util.List, Class)
- * @see #findAnnotationDescriptor(Class, Class)
- */
- public static UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(Class> clazz,
- Class extends Annotation>... annotationTypes) {
- return findAnnotationDescriptorForTypes(clazz, new HashSet<>(), annotationTypes);
- }
-
- /**
- * Perform the search algorithm for {@link #findAnnotationDescriptorForTypes(Class, Class...)}, avoiding endless
- * recursion by tracking which annotations have already been visited.
- *
- * @param clazz the class to look for annotations on
- * @param visited the set of annotations that have already been visited
- * @param annotationTypes the types of annotations to look for
- * @return the corresponding annotation descriptor if one of the annotations was found; otherwise {@code null}
- */
- private static UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(Class> clazz,
- Set visited, Class extends Annotation>... annotationTypes) {
-
- assertNonEmptyAnnotationTypeArray(annotationTypes, "The list of annotation types must not be empty");
-
- if (clazz == null || clazz.equals(Object.class)) {
- return null;
- }
-
- // Declared locally?
- for (Class extends Annotation> annotationType : annotationTypes) {
- if (AnnotationUtils.isAnnotationDeclaredLocally(annotationType, clazz)) {
- return new UntypedAnnotationDescriptor(clazz, clazz.getAnnotation(annotationType));
- }
- }
-
- // Declared on a composed annotation (i.e., as a meta-annotation)?
- for (Annotation composedAnnotation : clazz.getDeclaredAnnotations()) {
- if (!AnnotationUtils.isInJavaLangAnnotationPackage(composedAnnotation) && visited.add(composedAnnotation)) {
- UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
- composedAnnotation.annotationType(), visited, annotationTypes);
- if (descriptor != null) {
- return new UntypedAnnotationDescriptor(clazz, descriptor.getDeclaringClass(), composedAnnotation,
- descriptor.getAnnotation());
- }
- }
- }
-
- // Declared on a superclass?
- return findAnnotationDescriptorForTypes(clazz.getSuperclass(), visited, annotationTypes);
- }
-
- /**
- * Descriptor for an {@link Annotation}, including the {@linkplain #getDeclaringClass() class} on which the
- * annotation is declared as well as the actual {@linkplain #getAnnotation() annotation} instance.
- *
- * If the annotation is used as a meta-annotation, the descriptor also includes the
- * {@linkplain #getComposedAnnotation() composed annotation} on which the annotation is present. In such cases, the
- * root declaring class is not directly annotated with the annotation but rather indirectly via the
- * composed annotation.
- *
- * Given the following example, if we are searching for the {@code @Transactional} annotation on the
- * {@code TransactionalTests} class, then the properties of the {@code AnnotationDescriptor} would be as follows.
- *
- * - rootDeclaringClass: {@code TransactionalTests} class object
- * - declaringClass: {@code TransactionalTests} class object
- * - composedAnnotation: {@code null}
- * - annotation: instance of the {@code Transactional} annotation
- *
- *
- *
- * @Transactional
- * @ContextConfiguration({ "/test-datasource.xml", "/repository-config.xml" })
- * public class TransactionalTests {}
- *
- *
- * Given the following example, if we are searching for the {@code @Transactional} annotation on the
- * {@code UserRepositoryTests} class, then the properties of the {@code AnnotationDescriptor} would be as follows.
- *
- * - rootDeclaringClass: {@code UserRepositoryTests} class object
- * - declaringClass: {@code RepositoryTests} class object
- * - composedAnnotation: instance of the {@code RepositoryTests} annotation
- * - annotation: instance of the {@code Transactional} annotation
- *
- *
- *
- * @Transactional
- * @ContextConfiguration({ "/test-datasource.xml", "/repository-config.xml" })
- * @Retention(RetentionPolicy.RUNTIME)
- * public @interface RepositoryTests {
- * }
- *
- * @RepositoryTests
- * public class UserRepositoryTests {}
- *
- *
- * @author Sam Brannen
- * @since 4.0
- */
- public static class AnnotationDescriptor {
-
- private final Class> rootDeclaringClass;
- private final Class> declaringClass;
- private final Annotation composedAnnotation;
- private final T annotation;
- private final AnnotationAttributes annotationAttributes;
-
- public AnnotationDescriptor(Class> rootDeclaringClass, T annotation) {
- this(rootDeclaringClass, rootDeclaringClass, null, annotation);
- }
-
- public AnnotationDescriptor(Class> rootDeclaringClass, Class> declaringClass, Annotation composedAnnotation,
- T annotation) {
- Assert.notNull(rootDeclaringClass, "rootDeclaringClass must not be null");
- Assert.notNull(annotation, "annotation must not be null");
-
- this.rootDeclaringClass = rootDeclaringClass;
- this.declaringClass = declaringClass;
- this.composedAnnotation = composedAnnotation;
- this.annotation = annotation;
- this.annotationAttributes = AnnotatedElementUtils.findMergedAnnotationAttributes(rootDeclaringClass,
- annotation.annotationType(), false, false);
- }
-
- public Class> getRootDeclaringClass() {
- return this.rootDeclaringClass;
- }
-
- public Class> getDeclaringClass() {
- return this.declaringClass;
- }
-
- public T getAnnotation() {
- return this.annotation;
- }
-
- public Class extends Annotation> getAnnotationType() {
- return this.annotation.annotationType();
- }
-
- public AnnotationAttributes getAnnotationAttributes() {
- return this.annotationAttributes;
- }
-
- public Annotation getComposedAnnotation() {
- return this.composedAnnotation;
- }
-
- public Class extends Annotation> getComposedAnnotationType() {
- return this.composedAnnotation == null ? null : this.composedAnnotation.annotationType();
- }
-
- /**
- * Provide a textual representation of this {@code AnnotationDescriptor}.
- */
- @Override
- public String toString() {
- return new ToStringCreator(this)//
- .append("rootDeclaringClass", rootDeclaringClass)//
- .append("declaringClass", declaringClass)//
- .append("composedAnnotation", composedAnnotation)//
- .append("annotation", annotation)//
- .toString();
- }
- }
-
- /**
- * Untyped extension of {@code AnnotationDescriptor} that is used to describe the declaration of one of
- * several candidate annotation types where the actual annotation type cannot be predetermined.
- *
- * @author Sam Brannen
- * @since 4.0
- */
- public static class UntypedAnnotationDescriptor extends AnnotationDescriptor {
-
- public UntypedAnnotationDescriptor(Class> rootDeclaringClass, Annotation annotation) {
- this(rootDeclaringClass, rootDeclaringClass, null, annotation);
- }
-
- public UntypedAnnotationDescriptor(Class> rootDeclaringClass, Class> declaringClass,
- Annotation composedAnnotation, Annotation annotation) {
- super(rootDeclaringClass, declaringClass, composedAnnotation, annotation);
- }
- }
-
- private static void assertNonEmptyAnnotationTypeArray(Class>[] annotationTypes, String message) {
- if (ObjectUtils.isEmpty(annotationTypes)) {
- throw new IllegalArgumentException(message);
- }
-
- for (Class> clazz : annotationTypes) {
- if (!Annotation.class.isAssignableFrom(clazz)) {
- throw new IllegalArgumentException("Array elements must be of type Annotation");
- }
- }
- }
- }
}
diff --git a/src/main/java/org/springframework/data/keyvalue/core/mapping/BasicKeyValuePersistentEntity.java b/src/main/java/org/springframework/data/keyvalue/core/mapping/BasicKeyValuePersistentEntity.java
index d9f8bb3..5629d19 100644
--- a/src/main/java/org/springframework/data/keyvalue/core/mapping/BasicKeyValuePersistentEntity.java
+++ b/src/main/java/org/springframework/data/keyvalue/core/mapping/BasicKeyValuePersistentEntity.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 the original author or authors.
+ * Copyright 2015-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,8 +48,9 @@ public class BasicKeyValuePersistentEntity> getIdentifyingTypes() {
- return Collections.> singleton(KeyValueRepository.class);
+ return Collections.singleton(KeyValueRepository.class);
}
/*
@@ -109,9 +110,10 @@ public abstract class KeyValueRepositoryConfigurationExtension extends Repositor
AnnotationMetadata metadata = config.getEnableAnnotationMetadata();
- Map queryCreatorAnnotationAttributes = metadata.getAnnotationAttributes(QueryCreatorType.class.getName());
+ Map queryCreatorAnnotationAttributes = metadata
+ .getAnnotationAttributes(QueryCreatorType.class.getName());
- if (queryCreatorAnnotationAttributes == null) {
+ if (CollectionUtils.isEmpty(queryCreatorAnnotationAttributes)) {
return SpelQueryCreator.class;
}
@@ -130,7 +132,8 @@ public abstract class KeyValueRepositoryConfigurationExtension extends Repositor
AnnotationMetadata metadata = config.getEnableAnnotationMetadata();
- Map queryCreatorAnnotationAttributes = metadata.getAnnotationAttributes(QueryCreatorType.class.getName());
+ Map queryCreatorAnnotationAttributes = metadata
+ .getAnnotationAttributes(QueryCreatorType.class.getName());
if (queryCreatorAnnotationAttributes == null) {
return KeyValuePartTreeQuery.class;
@@ -163,7 +166,8 @@ public abstract class KeyValueRepositoryConfigurationExtension extends Repositor
AbstractBeanDefinition beanDefinition = getDefaultKeyValueTemplateBeanDefinition(configurationSource);
if (beanDefinition != null) {
- registerIfNotAlreadyRegistered(beanDefinition, registry, keyValueTemplateName.get(), configurationSource.getSource());
+ registerIfNotAlreadyRegistered(beanDefinition, registry, keyValueTemplateName.get(),
+ configurationSource.getSource());
}
}
}
diff --git a/src/main/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQuery.java b/src/main/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQuery.java
index 82d09f2..dbd3504 100644
--- a/src/main/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQuery.java
+++ b/src/main/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQuery.java
@@ -157,7 +157,7 @@ public class KeyValuePartTreeQuery implements RepositoryQuery {
query.setRows(instance.getRows());
}
- query.setSort(sort == null || sort.isUnsorted() ? instance.getSort() : sort);
+ query.setSort(sort.isUnsorted() ? instance.getSort() : sort);
return query;
}
diff --git a/src/main/java/org/springframework/data/keyvalue/repository/support/SimpleKeyValueRepository.java b/src/main/java/org/springframework/data/keyvalue/repository/support/SimpleKeyValueRepository.java
index 74d1396..7e8550b 100644
--- a/src/main/java/org/springframework/data/keyvalue/repository/support/SimpleKeyValueRepository.java
+++ b/src/main/java/org/springframework/data/keyvalue/repository/support/SimpleKeyValueRepository.java
@@ -154,12 +154,7 @@ public class SimpleKeyValueRepository implements KeyValueRepository result = new ArrayList<>();
for (ID id : ids) {
-
- Optional candidate = findById(id);
-
- if (candidate.isPresent()) {
- result.add(candidate.get());
- }
+ findById(id).ifPresent(result::add);
}
return result;
diff --git a/src/test/java/org/springframework/data/keyvalue/CustomKeySpaceAnnotation.java b/src/test/java/org/springframework/data/keyvalue/CustomKeySpaceAnnotation.java
deleted file mode 100644
index 3cdc121..0000000
--- a/src/test/java/org/springframework/data/keyvalue/CustomKeySpaceAnnotation.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2015 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.data.keyvalue;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.springframework.data.annotation.Persistent;
-import org.springframework.data.keyvalue.annotation.KeySpace;
-
-/**
- * Custom composed {@link Persistent} annotation using {@link KeySpace} on name attribute.
- *
- * @author Christoph Strobl
- */
-@Persistent
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ ElementType.TYPE })
-public @interface CustomKeySpaceAnnotation {
-
- @KeySpace
- String name() default "";
-}
diff --git a/src/test/java/org/springframework/data/keyvalue/SubclassOfTypeWithCustomComposedKeySpaceAnnotation.java b/src/test/java/org/springframework/data/keyvalue/SubclassOfTypeWithCustomComposedKeySpaceAnnotation.java
index 67e507c..4fef516 100644
--- a/src/test/java/org/springframework/data/keyvalue/SubclassOfTypeWithCustomComposedKeySpaceAnnotation.java
+++ b/src/test/java/org/springframework/data/keyvalue/SubclassOfTypeWithCustomComposedKeySpaceAnnotation.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 the original author or authors.
+ * Copyright 2015-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,10 +18,13 @@ package org.springframework.data.keyvalue;
import org.springframework.data.keyvalue.annotation.KeySpace;
/**
- * Class that inherits its {@link KeySpace} from a super class annotated with a custom {@link CustomKeySpaceAnnotation} annotation.
+ * Class that inherits its {@link KeySpace} from a super class annotated with a custom {@link CustomKeySpaceAnnotation}
+ * annotation.
+ *
* @author Christoph Strobl
*/
-public class SubclassOfTypeWithCustomComposedKeySpaceAnnotation extends TypeWithCustomComposedKeySpaceAnnotation {
+public class SubclassOfTypeWithCustomComposedKeySpaceAnnotation
+ extends TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor {
public SubclassOfTypeWithCustomComposedKeySpaceAnnotation(String name) {
super(name);
diff --git a/src/test/java/org/springframework/data/keyvalue/TypeWithCustomComposedKeySpaceAnnotation.java b/src/test/java/org/springframework/data/keyvalue/TypeWithCustomComposedKeySpaceAnnotation.java
deleted file mode 100644
index 0887983..0000000
--- a/src/test/java/org/springframework/data/keyvalue/TypeWithCustomComposedKeySpaceAnnotation.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2015 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.data.keyvalue;
-
-import org.springframework.data.annotation.Id;
-import org.springframework.data.annotation.Persistent;
-import org.springframework.util.ObjectUtils;
-
-/**
- * A {@link Persistent} type with {@link CustomKeySpaceAnnotation}.
- *
- * @author Christoph Strobl
- */
-@CustomKeySpaceAnnotation(name = "aliased")
-public class TypeWithCustomComposedKeySpaceAnnotation {
-
- @Id String id;
- String name;
-
- public TypeWithCustomComposedKeySpaceAnnotation(String name) {
- this.name = name;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ObjectUtils.nullSafeHashCode(this.id);
- result = prime * result + ObjectUtils.nullSafeHashCode(this.name);
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof TypeWithCustomComposedKeySpaceAnnotation)) {
- return false;
- }
- TypeWithCustomComposedKeySpaceAnnotation other = (TypeWithCustomComposedKeySpaceAnnotation) obj;
- if (!ObjectUtils.nullSafeEquals(this.id, other.id)) {
- return false;
- }
- if (!ObjectUtils.nullSafeEquals(this.name, other.name)) {
- return false;
- }
- return true;
- }
-
-}
diff --git a/src/test/java/org/springframework/data/keyvalue/core/KeyValuePersistenceExceptionTranslatorUnitTests.java b/src/test/java/org/springframework/data/keyvalue/core/KeyValuePersistenceExceptionTranslatorUnitTests.java
index 8a09d95..487654d 100644
--- a/src/test/java/org/springframework/data/keyvalue/core/KeyValuePersistenceExceptionTranslatorUnitTests.java
+++ b/src/test/java/org/springframework/data/keyvalue/core/KeyValuePersistenceExceptionTranslatorUnitTests.java
@@ -38,7 +38,7 @@ public class KeyValuePersistenceExceptionTranslatorUnitTests {
instanceOf(DataRetrievalFailureException.class));
}
- @Test // DATACMNS-525
+ @Test(expected = IllegalArgumentException.class) // DATACMNS-525, DATAKV-192
public void translateExeptionShouldReturnNullWhenGivenNull() {
assertThat(translator.translateExceptionIfPossible(null), nullValue());
}
diff --git a/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateTests.java b/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateTests.java
index fc76141..a6fa884 100644
--- a/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateTests.java
+++ b/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateTests.java
@@ -32,6 +32,7 @@ import java.util.Optional;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.springframework.core.annotation.AliasFor;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Persistent;
@@ -261,12 +262,13 @@ public class KeyValueTemplateTests {
}
+ @KeySpace
@Persistent
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
- static @interface ExplicitKeySpace {
+ @interface ExplicitKeySpace {
- @KeySpace
+ @AliasFor(annotation = KeySpace.class, value = "value")
String name() default "";
}
diff --git a/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java b/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java
index b64977f..7ef3daa 100644
--- a/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java
+++ b/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java
@@ -17,7 +17,6 @@ package org.springframework.data.keyvalue.core;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
-import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import lombok.AllArgsConstructor;
@@ -35,7 +34,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
-import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.context.ApplicationEventPublisher;
@@ -43,7 +41,6 @@ import org.springframework.dao.DuplicateKeyException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.annotation.Id;
import org.springframework.data.keyvalue.SubclassOfTypeWithCustomComposedKeySpaceAnnotation;
-import org.springframework.data.keyvalue.TypeWithCustomComposedKeySpaceAnnotation;
import org.springframework.data.keyvalue.TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor;
import org.springframework.data.keyvalue.core.event.KeyValueEvent;
import org.springframework.data.keyvalue.core.event.KeyValueEvent.AfterDeleteEvent;
@@ -70,11 +67,9 @@ public class KeyValueTemplateUnitTests {
private static final Foo FOO_ONE = new Foo("one");
private static final Foo FOO_TWO = new Foo("two");
- private static final TypeWithCustomComposedKeySpaceAnnotation ALIASED = new TypeWithCustomComposedKeySpaceAnnotation(
- "super");
private static final TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor ALIASED_USING_ALIAS_FOR = new TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor(
"super");
- private static final SubclassOfTypeWithCustomComposedKeySpaceAnnotation SUBCLASS_OF_ALIASED = new SubclassOfTypeWithCustomComposedKeySpaceAnnotation(
+ private static final SubclassOfTypeWithCustomComposedKeySpaceAnnotation SUBCLASS_OF_ALIASED_USING_ALIAS_FOR = new SubclassOfTypeWithCustomComposedKeySpaceAnnotation(
"sub");
private static final KeyValueQuery STRING_QUERY = new KeyValueQuery<>("foo == 'two'");
@@ -300,34 +295,35 @@ public class KeyValueTemplateUnitTests {
@Test // DATACMNS-525
public void insertShouldRespectTypeAlias() {
- template.insert("1", ALIASED);
+ template.insert("1", ALIASED_USING_ALIAS_FOR);
- verify(adapterMock, times(1)).put("1", ALIASED, "aliased");
+ verify(adapterMock, times(1)).put("1", ALIASED_USING_ALIAS_FOR, "aliased");
}
@Test // DATACMNS-525
public void insertShouldRespectTypeAliasOnSubClass() {
- template.insert("1", SUBCLASS_OF_ALIASED);
+ template.insert("1", SUBCLASS_OF_ALIASED_USING_ALIAS_FOR);
- verify(adapterMock, times(1)).put("1", SUBCLASS_OF_ALIASED, "aliased");
+ verify(adapterMock, times(1)).put("1", SUBCLASS_OF_ALIASED_USING_ALIAS_FOR, "aliased");
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test // DATACMNS-525
public void findAllOfShouldRespectTypeAliasAndFilterNonMatchingTypes() {
- Collection foo = Arrays.asList(ALIASED, SUBCLASS_OF_ALIASED);
+ Collection foo = Arrays.asList(ALIASED_USING_ALIAS_FOR, SUBCLASS_OF_ALIASED_USING_ALIAS_FOR);
when(adapterMock.getAllOf("aliased")).thenReturn(foo);
- assertThat(template.findAll(SUBCLASS_OF_ALIASED.getClass()), containsInAnyOrder(SUBCLASS_OF_ALIASED));
+ assertThat(template.findAll(SUBCLASS_OF_ALIASED_USING_ALIAS_FOR.getClass()),
+ containsInAnyOrder(SUBCLASS_OF_ALIASED_USING_ALIAS_FOR));
}
@Test // DATACMNS-525
public void insertSouldRespectTypeAliasAndFilterNonMatching() {
- template.insert("1", ALIASED);
- assertThat(template.findById("1", SUBCLASS_OF_ALIASED.getClass()), is(Optional.empty()));
+ template.insert("1", ALIASED_USING_ALIAS_FOR);
+ assertThat(template.findById("1", SUBCLASS_OF_ALIASED_USING_ALIAS_FOR.getClass()), is(Optional.empty()));
}
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
@@ -359,7 +355,7 @@ public class KeyValueTemplateUnitTests {
@SuppressWarnings("rawtypes")
public void shouldNotPublishEventsWhenEventsToPublishIsSetToEmptyList() {
- template.setEventTypesToPublish(Collections.> emptySet());
+ template.setEventTypesToPublish(Collections.emptySet());
template.insert("1", FOO_ONE);
@@ -371,7 +367,7 @@ public class KeyValueTemplateUnitTests {
template.insert("1", FOO_ONE);
- verify(publisherMock, atLeastOnce()).publishEvent(Matchers.any(KeyValueEvent.class));
+ verify(publisherMock, atLeastOnce()).publishEvent(any());
}
@Test // DATAKV-91, DATAKV-104
@@ -400,7 +396,7 @@ public class KeyValueTemplateUnitTests {
assertThat(captor.getValue().getKey(), is("1"));
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
- assertThat(captor.getValue().getPayload(), is((Object) FOO_ONE));
+ assertThat(captor.getValue().getPayload(), is(FOO_ONE));
}
@Test // DATAKV-91, DATAKV-104, DATAKV-187
diff --git a/src/test/java/org/springframework/data/keyvalue/core/SpelPropertyComperatorUnitTests.java b/src/test/java/org/springframework/data/keyvalue/core/SpelPropertyComperatorUnitTests.java
index 6e1be47..9453369 100644
--- a/src/test/java/org/springframework/data/keyvalue/core/SpelPropertyComperatorUnitTests.java
+++ b/src/test/java/org/springframework/data/keyvalue/core/SpelPropertyComperatorUnitTests.java
@@ -35,8 +35,8 @@ public class SpelPropertyComperatorUnitTests {
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
- private static final SomeType ONE = new SomeType("one", Integer.valueOf(1), 1);
- private static final SomeType TWO = new SomeType("two", Integer.valueOf(2), 2);
+ private static final SomeType ONE = new SomeType("one", 1, 1);
+ private static final SomeType TWO = new SomeType("two", 2, 2);
private static final WrapperType WRAPPER_ONE = new WrapperType("w-one", ONE);
private static final WrapperType WRAPPER_TWO = new WrapperType("w-two", TWO);
diff --git a/src/test/java/org/springframework/data/keyvalue/core/SpelQueryEngineUnitTests.java b/src/test/java/org/springframework/data/keyvalue/core/SpelQueryEngineUnitTests.java
index 119e9d0..ed1608d 100644
--- a/src/test/java/org/springframework/data/keyvalue/core/SpelQueryEngineUnitTests.java
+++ b/src/test/java/org/springframework/data/keyvalue/core/SpelQueryEngineUnitTests.java
@@ -18,7 +18,6 @@ package org.springframework.data.keyvalue.core;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.*;
-import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;
import java.lang.reflect.Method;
diff --git a/src/test/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolverUnitTests.java b/src/test/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolverUnitTests.java
index 100fa23..45438b6 100644
--- a/src/test/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolverUnitTests.java
+++ b/src/test/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolverUnitTests.java
@@ -52,11 +52,6 @@ public class AnnotationBasedKeySpaceResolverUnitTests {
assertThat(resolver.resolveKeySpace(EntityWithDefaultKeySpace.class), is("daenerys"));
}
- @Test // DATACMNS-525
- public void shouldResolveKeySpaceCorrectly() {
- assertThat(resolver.resolveKeySpace(EntityWithSetKeySpace.class), is("viserys"));
- }
-
@Test // DATAKV-105
public void shouldReturnNullWhenNoKeySpaceFoundOnComposedPersistentAnnotation() {
assertThat(resolver.resolveKeySpace(TypeWithInhteritedPersistentAnnotationNotHavingKeySpace.class), nullValue());
@@ -92,40 +87,24 @@ public class AnnotationBasedKeySpaceResolverUnitTests {
assertThat(resolver.resolveKeySpace(EntityWithInheritedKeySpaceUsingAliasFor.class), is("viserys"));
}
- @PersistentAnnotationWithExplicitKeySpace
+ @PersistentAnnotationWithExplicitKeySpaceUsingAliasFor
static class EntityWithDefaultKeySpace {
}
- @PersistentAnnotationWithExplicitKeySpace(firstname = "viserys")
- static class EntityWithSetKeySpace {
-
- }
-
- static class EntityWithInheritedKeySpace extends EntityWithSetKeySpace {
-
- }
-
- @PersistentAnnotationWithExplicitKeySpace(firstname = "viserys")
+ @PersistentAnnotationWithExplicitKeySpaceUsingAliasFor(firstname = "viserys")
static class EntityWithSetKeySpaceUsingAliasFor {
}
+ static class EntityWithInheritedKeySpace extends EntityWithSetKeySpaceUsingAliasFor {
+
+ }
+
static class EntityWithInheritedKeySpaceUsingAliasFor extends EntityWithSetKeySpaceUsingAliasFor {
}
- @Persistent
- @Retention(RetentionPolicy.RUNTIME)
- @Target({ ElementType.TYPE })
- static @interface PersistentAnnotationWithExplicitKeySpace {
-
- @KeySpace
- String firstname() default "daenerys";
-
- String lastnamne() default "targaryen";
- }
-
@Persistent
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
diff --git a/src/test/java/org/springframework/data/keyvalue/repository/SimpleKeyValueRepositoryUnitTests.java b/src/test/java/org/springframework/data/keyvalue/repository/SimpleKeyValueRepositoryUnitTests.java
index 8e1a011..7cb6212 100644
--- a/src/test/java/org/springframework/data/keyvalue/repository/SimpleKeyValueRepositoryUnitTests.java
+++ b/src/test/java/org/springframework/data/keyvalue/repository/SimpleKeyValueRepositoryUnitTests.java
@@ -17,9 +17,6 @@ package org.springframework.data.keyvalue.repository;
import static org.hamcrest.core.Is.*;
import static org.junit.Assert.*;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
import lombok.Data;
diff --git a/src/test/java/org/springframework/data/keyvalue/repository/query/CachingKeyValuePartTreeQueryUnitTests.java b/src/test/java/org/springframework/data/keyvalue/repository/query/CachingKeyValuePartTreeQueryUnitTests.java
index 93743f4..08d8856 100644
--- a/src/test/java/org/springframework/data/keyvalue/repository/query/CachingKeyValuePartTreeQueryUnitTests.java
+++ b/src/test/java/org/springframework/data/keyvalue/repository/query/CachingKeyValuePartTreeQueryUnitTests.java
@@ -18,7 +18,6 @@ package org.springframework.data.keyvalue.repository.query;
import static org.hamcrest.core.IsNot.*;
import static org.hamcrest.core.IsSame.*;
import static org.junit.Assert.*;
-import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.lang.reflect.Method;
diff --git a/src/test/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreatorUnitTests.java b/src/test/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreatorUnitTests.java
index b0f1547..f975415 100644
--- a/src/test/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreatorUnitTests.java
+++ b/src/test/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreatorUnitTests.java
@@ -314,7 +314,7 @@ public class SpelQueryCreatorUnitTests {
}
private Evaluation evaluate(String methodName, Object... args) throws Exception {
- return new Evaluation((SpelExpression) createQueryForMethodWithArgs(methodName, args).getCriteria());
+ return new Evaluation(createQueryForMethodWithArgs(methodName, args).getCriteria());
}
private KeyValueQuery createQueryForMethodWithArgs(String methodName, Object... args)
diff --git a/src/test/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtilsUnitTests.java b/src/test/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtilsUnitTests.java
index c942e8c..647abc1 100644
--- a/src/test/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtilsUnitTests.java
+++ b/src/test/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtilsUnitTests.java
@@ -70,7 +70,7 @@ public class KeyValueQuerydslUtilsUnitTests {
OrderSpecifier>[] specifiers = toOrderSpecifier(sort, builder);
assertThat(specifiers,
- IsArrayContainingInOrder.> arrayContaining(QPerson.person.firstname.asc()));
+ IsArrayContainingInOrder.arrayContaining(QPerson.person.firstname.asc()));
}
@Test // DATACMNS-525
@@ -81,7 +81,7 @@ public class KeyValueQuerydslUtilsUnitTests {
OrderSpecifier>[] specifiers = toOrderSpecifier(sort, builder);
assertThat(specifiers,
- IsArrayContainingInOrder.> arrayContaining(QPerson.person.firstname.desc()));
+ IsArrayContainingInOrder.arrayContaining(QPerson.person.firstname.desc()));
}
@Test // DATACMNS-525
@@ -91,7 +91,7 @@ public class KeyValueQuerydslUtilsUnitTests {
OrderSpecifier>[] specifiers = toOrderSpecifier(sort, builder);
- assertThat(specifiers, IsArrayContainingInOrder.> arrayContaining(QPerson.person.firstname.desc(),
+ assertThat(specifiers, IsArrayContainingInOrder.arrayContaining(QPerson.person.firstname.desc(),
QPerson.person.age.asc()));
}
@@ -103,6 +103,6 @@ public class KeyValueQuerydslUtilsUnitTests {
OrderSpecifier>[] specifiers = toOrderSpecifier(sort, builder);
assertThat(specifiers,
- IsArrayContainingInOrder.> arrayContaining(QPerson.person.firstname.desc().nullsLast()));
+ IsArrayContainingInOrder.arrayContaining(QPerson.person.firstname.desc().nullsLast()));
}
}
diff --git a/src/test/java/org/springframework/data/map/QuerydslKeyValueRepositoryUnitTests.java b/src/test/java/org/springframework/data/map/QuerydslKeyValueRepositoryUnitTests.java
index 9f3990a..d7e9c79 100644
--- a/src/test/java/org/springframework/data/map/QuerydslKeyValueRepositoryUnitTests.java
+++ b/src/test/java/org/springframework/data/map/QuerydslKeyValueRepositoryUnitTests.java
@@ -76,7 +76,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
assertThat(page1.getContent(), hasSize(1));
assertThat(page1.hasNext(), is(true));
- Page page2 = ((QPersonRepository) repository).findAll(QPerson.person.age.eq(CERSEI.getAge()),
+ Page page2 = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()),
page1.nextPageable());
assertThat(page2.getTotalElements(), is(2L));