Consistent Class array vs vararg declarations (and related polishing)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -74,8 +74,7 @@ import static org.springframework.test.context.junit4.JUnitTestingUtils.*;
|
||||
*/
|
||||
public class SpringJUnit4ConcurrencyTests {
|
||||
|
||||
// @formatter:off
|
||||
private final Class<?>[] testClasses = new Class[] {
|
||||
private final Class<?>[] testClasses = new Class<?>[] {
|
||||
// Basics
|
||||
SpringJUnit4ClassRunnerAppCtxTests.class,
|
||||
InheritedConfigSpringJUnit4ClassRunnerAppCtxTests.class,
|
||||
@@ -94,7 +93,7 @@ public class SpringJUnit4ConcurrencyTests {
|
||||
WebAppResourceTests.class,
|
||||
SampleTests.class
|
||||
};
|
||||
// @formatter:on
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void abortIfLongRunningTestGroupIsNotEnabled() {
|
||||
@@ -109,7 +108,7 @@ public class SpringJUnit4ConcurrencyTests {
|
||||
final int TESTS = countAnnotatedMethods(Test.class) - IGNORED;
|
||||
|
||||
runTestsAndAssertCounters(new ParallelComputer(true, true), TESTS, FAILED, TESTS, IGNORED, ABORTED,
|
||||
this.testClasses);
|
||||
this.testClasses);
|
||||
}
|
||||
|
||||
private int countAnnotatedMethods(Class<? extends Annotation> annotationType) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -57,8 +57,8 @@ public class DelegatingSmartContextLoaderTests {
|
||||
|
||||
@Test
|
||||
public void processContextConfigurationWithDefaultXmlConfigGeneration() {
|
||||
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(XmlTestCase.class,
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class);
|
||||
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(
|
||||
XmlTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class);
|
||||
loader.processContextConfiguration(configAttributes);
|
||||
assertEquals(1, configAttributes.getLocations().length);
|
||||
assertEmpty(configAttributes.getClasses());
|
||||
@@ -66,8 +66,8 @@ public class DelegatingSmartContextLoaderTests {
|
||||
|
||||
@Test
|
||||
public void processContextConfigurationWithDefaultConfigurationClassGeneration() {
|
||||
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(ConfigClassTestCase.class,
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class);
|
||||
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(
|
||||
ConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class);
|
||||
loader.processContextConfiguration(configAttributes);
|
||||
assertEquals(1, configAttributes.getClasses().length);
|
||||
assertEmpty(configAttributes.getLocations());
|
||||
@@ -79,16 +79,16 @@ public class DelegatingSmartContextLoaderTests {
|
||||
expectedException.expectMessage(containsString("both default locations AND default configuration classes were detected"));
|
||||
|
||||
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(
|
||||
ImproperDuplicateDefaultXmlAndConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null,
|
||||
true, ContextLoader.class);
|
||||
ImproperDuplicateDefaultXmlAndConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY,
|
||||
true, null, true, ContextLoader.class);
|
||||
loader.processContextConfiguration(configAttributes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void processContextConfigurationWithLocation() {
|
||||
String[] locations = new String[] { "classpath:/foo.xml" };
|
||||
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(getClass(), locations,
|
||||
EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class);
|
||||
String[] locations = new String[] {"classpath:/foo.xml"};
|
||||
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(
|
||||
getClass(), locations, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class);
|
||||
loader.processContextConfiguration(configAttributes);
|
||||
assertArrayEquals(locations, configAttributes.getLocations());
|
||||
assertEmpty(configAttributes.getClasses());
|
||||
@@ -96,9 +96,9 @@ public class DelegatingSmartContextLoaderTests {
|
||||
|
||||
@Test
|
||||
public void processContextConfigurationWithConfigurationClass() {
|
||||
Class<?>[] classes = new Class<?>[] { getClass() };
|
||||
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(getClass(),
|
||||
EMPTY_STRING_ARRAY, classes, true, null, true, ContextLoader.class);
|
||||
Class<?>[] classes = new Class<?>[] {getClass()};
|
||||
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(
|
||||
getClass(), EMPTY_STRING_ARRAY, classes, true, null, true, ContextLoader.class);
|
||||
loader.processContextConfiguration(configAttributes);
|
||||
assertArrayEquals(classes, configAttributes.getClasses());
|
||||
assertEmpty(configAttributes.getLocations());
|
||||
@@ -118,8 +118,8 @@ public class DelegatingSmartContextLoaderTests {
|
||||
expectedException.expectMessage(startsWith("Neither"));
|
||||
expectedException.expectMessage(containsString("was able to load an ApplicationContext from"));
|
||||
|
||||
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
|
||||
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(
|
||||
getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
loader.loadContext(mergedConfig);
|
||||
}
|
||||
|
||||
@@ -133,12 +133,13 @@ public class DelegatingSmartContextLoaderTests {
|
||||
expectedException.expectMessage(endsWith("declare either 'locations' or 'classes' but not both."));
|
||||
|
||||
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(),
|
||||
new String[] { "test.xml" }, new Class[] { getClass() }, EMPTY_STRING_ARRAY, loader);
|
||||
new String[] {"test.xml"}, new Class<?>[] {getClass()}, EMPTY_STRING_ARRAY, loader);
|
||||
loader.loadContext(mergedConfig);
|
||||
}
|
||||
|
||||
private void assertApplicationContextLoadsAndContainsFooString(MergedContextConfiguration mergedConfig)
|
||||
throws Exception {
|
||||
|
||||
ApplicationContext applicationContext = loader.loadContext(mergedConfig);
|
||||
assertNotNull(applicationContext);
|
||||
assertEquals("foo", applicationContext.getBean(String.class));
|
||||
@@ -149,16 +150,16 @@ public class DelegatingSmartContextLoaderTests {
|
||||
@Test
|
||||
public void loadContextWithXmlConfig() throws Exception {
|
||||
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(
|
||||
XmlTestCase.class,
|
||||
new String[] { "classpath:/org/springframework/test/context/support/DelegatingSmartContextLoaderTests$XmlTestCase-context.xml" },
|
||||
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
XmlTestCase.class,
|
||||
new String[] {"classpath:/org/springframework/test/context/support/DelegatingSmartContextLoaderTests$XmlTestCase-context.xml"},
|
||||
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
assertApplicationContextLoadsAndContainsFooString(mergedConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadContextWithConfigurationClass() throws Exception {
|
||||
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(ConfigClassTestCase.class,
|
||||
EMPTY_STRING_ARRAY, new Class<?>[] { ConfigClassTestCase.Config.class }, EMPTY_STRING_ARRAY, loader);
|
||||
EMPTY_STRING_ARRAY, new Class<?>[] {ConfigClassTestCase.Config.class}, EMPTY_STRING_ARRAY, loader);
|
||||
assertApplicationContextLoadsAndContainsFooString(mergedConfig);
|
||||
}
|
||||
|
||||
@@ -192,7 +193,6 @@ public class DelegatingSmartContextLoaderTests {
|
||||
}
|
||||
|
||||
static class NotAConfigClass {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -44,19 +44,21 @@ import static org.springframework.test.util.MetaAnnotationUtils.*;
|
||||
*/
|
||||
public class MetaAnnotationUtilsTests {
|
||||
|
||||
private void assertAtComponentOnComposedAnnotation(Class<?> rootDeclaringClass, String name,
|
||||
Class<? extends Annotation> composedAnnotationType) {
|
||||
private void assertAtComponentOnComposedAnnotation(
|
||||
Class<?> rootDeclaringClass, String name, Class<? extends Annotation> composedAnnotationType) {
|
||||
|
||||
assertAtComponentOnComposedAnnotation(rootDeclaringClass, rootDeclaringClass, name, composedAnnotationType);
|
||||
}
|
||||
|
||||
private void assertAtComponentOnComposedAnnotation(Class<?> startClass, Class<?> rootDeclaringClass, String name,
|
||||
Class<? extends Annotation> composedAnnotationType) {
|
||||
assertAtComponentOnComposedAnnotation(rootDeclaringClass, rootDeclaringClass, composedAnnotationType, name,
|
||||
composedAnnotationType);
|
||||
private void assertAtComponentOnComposedAnnotation(
|
||||
Class<?> startClass, Class<?> rootDeclaringClass, String name, Class<? extends Annotation> composedAnnotationType) {
|
||||
|
||||
assertAtComponentOnComposedAnnotation(startClass, rootDeclaringClass, composedAnnotationType, name, composedAnnotationType);
|
||||
}
|
||||
|
||||
private void assertAtComponentOnComposedAnnotation(Class<?> startClass, Class<?> rootDeclaringClass,
|
||||
Class<?> declaringClass, String name, Class<? extends Annotation> composedAnnotationType) {
|
||||
|
||||
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(startClass, Component.class);
|
||||
assertNotNull("AnnotationDescriptor should not be null", descriptor);
|
||||
assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass());
|
||||
@@ -67,25 +69,29 @@ public class MetaAnnotationUtilsTests {
|
||||
assertEquals("composedAnnotationType", composedAnnotationType, descriptor.getComposedAnnotationType());
|
||||
}
|
||||
|
||||
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass, String name,
|
||||
Class<? extends Annotation> composedAnnotationType) {
|
||||
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, startClass, name,
|
||||
composedAnnotationType);
|
||||
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(
|
||||
Class<?> startClass, String name, Class<? extends Annotation> composedAnnotationType) {
|
||||
|
||||
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(
|
||||
startClass, startClass, name, composedAnnotationType);
|
||||
}
|
||||
|
||||
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass,
|
||||
Class<?> rootDeclaringClass, String name, Class<? extends Annotation> composedAnnotationType) {
|
||||
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, rootDeclaringClass,
|
||||
composedAnnotationType, name, composedAnnotationType);
|
||||
|
||||
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(
|
||||
startClass, rootDeclaringClass, composedAnnotationType, name, composedAnnotationType);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass,
|
||||
Class<?> rootDeclaringClass, Class<?> declaringClass, String name,
|
||||
Class<? extends Annotation> composedAnnotationType) {
|
||||
|
||||
Class<Component> annotationType = Component.class;
|
||||
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class,
|
||||
annotationType, Order.class, Transactional.class);
|
||||
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
|
||||
startClass, Service.class, annotationType, Order.class, Transactional.class);
|
||||
|
||||
assertNotNull("UntypedAnnotationDescriptor should not be null", descriptor);
|
||||
assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass());
|
||||
assertEquals("declaringClass", declaringClass, descriptor.getDeclaringClass());
|
||||
@@ -96,28 +102,27 @@ public class MetaAnnotationUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAnnotationDescriptorWithNoAnnotationPresent() throws Exception {
|
||||
public void findAnnotationDescriptorWithNoAnnotationPresent() {
|
||||
assertNull(findAnnotationDescriptor(NonAnnotatedInterface.class, Transactional.class));
|
||||
assertNull(findAnnotationDescriptor(NonAnnotatedClass.class, Transactional.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAnnotationDescriptorWithInheritedAnnotationOnClass() throws Exception {
|
||||
public void findAnnotationDescriptorWithInheritedAnnotationOnClass() {
|
||||
// Note: @Transactional is inherited
|
||||
assertEquals(InheritedAnnotationClass.class,
|
||||
findAnnotationDescriptor(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass());
|
||||
findAnnotationDescriptor(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass());
|
||||
assertEquals(InheritedAnnotationClass.class,
|
||||
findAnnotationDescriptor(SubInheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass());
|
||||
findAnnotationDescriptor(SubInheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAnnotationDescriptorWithInheritedAnnotationOnInterface() throws Exception {
|
||||
public void findAnnotationDescriptorWithInheritedAnnotationOnInterface() {
|
||||
// Note: @Transactional is inherited
|
||||
Transactional rawAnnotation = InheritedAnnotationInterface.class.getAnnotation(Transactional.class);
|
||||
|
||||
AnnotationDescriptor<Transactional> descriptor;
|
||||
|
||||
descriptor = findAnnotationDescriptor(InheritedAnnotationInterface.class, Transactional.class);
|
||||
AnnotationDescriptor<Transactional> descriptor =
|
||||
findAnnotationDescriptor(InheritedAnnotationInterface.class, Transactional.class);
|
||||
assertNotNull(descriptor);
|
||||
assertEquals(InheritedAnnotationInterface.class, descriptor.getRootDeclaringClass());
|
||||
assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass());
|
||||
@@ -137,22 +142,21 @@ public class MetaAnnotationUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAnnotationDescriptorForNonInheritedAnnotationOnClass() throws Exception {
|
||||
public void findAnnotationDescriptorForNonInheritedAnnotationOnClass() {
|
||||
// Note: @Order is not inherited.
|
||||
assertEquals(NonInheritedAnnotationClass.class,
|
||||
findAnnotationDescriptor(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass());
|
||||
findAnnotationDescriptor(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass());
|
||||
assertEquals(NonInheritedAnnotationClass.class,
|
||||
findAnnotationDescriptor(SubNonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass());
|
||||
findAnnotationDescriptor(SubNonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAnnotationDescriptorForNonInheritedAnnotationOnInterface() throws Exception {
|
||||
public void findAnnotationDescriptorForNonInheritedAnnotationOnInterface() {
|
||||
// Note: @Order is not inherited.
|
||||
Order rawAnnotation = NonInheritedAnnotationInterface.class.getAnnotation(Order.class);
|
||||
|
||||
AnnotationDescriptor<Order> descriptor;
|
||||
|
||||
descriptor = findAnnotationDescriptor(NonInheritedAnnotationInterface.class, Order.class);
|
||||
AnnotationDescriptor<Order> descriptor =
|
||||
findAnnotationDescriptor(NonInheritedAnnotationInterface.class, Order.class);
|
||||
assertNotNull(descriptor);
|
||||
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass());
|
||||
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getDeclaringClass());
|
||||
@@ -166,15 +170,16 @@ public class MetaAnnotationUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAnnotationDescriptorWithMetaComponentAnnotation() throws Exception {
|
||||
public void findAnnotationDescriptorWithMetaComponentAnnotation() {
|
||||
assertAtComponentOnComposedAnnotation(HasMetaComponentAnnotation.class, "meta1", Meta1.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAnnotationDescriptorWithLocalAndMetaComponentAnnotation() throws Exception {
|
||||
public void findAnnotationDescriptorWithLocalAndMetaComponentAnnotation() {
|
||||
Class<Component> annotationType = Component.class;
|
||||
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(HasLocalAndMetaComponentAnnotation.class,
|
||||
annotationType);
|
||||
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(
|
||||
HasLocalAndMetaComponentAnnotation.class, annotationType);
|
||||
|
||||
assertEquals(HasLocalAndMetaComponentAnnotation.class, descriptor.getRootDeclaringClass());
|
||||
assertEquals(annotationType, descriptor.getAnnotationType());
|
||||
assertNull(descriptor.getComposedAnnotation());
|
||||
@@ -188,12 +193,10 @@ public class MetaAnnotationUtilsTests {
|
||||
|
||||
@Test
|
||||
public void findAnnotationDescriptorForClassWithMetaAnnotatedInterface() {
|
||||
Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class,
|
||||
Component.class);
|
||||
Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component.class);
|
||||
AnnotationDescriptor<Component> descriptor =
|
||||
findAnnotationDescriptor(ClassWithMetaAnnotatedInterface.class, Component.class);
|
||||
|
||||
AnnotationDescriptor<Component> descriptor;
|
||||
|
||||
descriptor = findAnnotationDescriptor(ClassWithMetaAnnotatedInterface.class, Component.class);
|
||||
assertNotNull(descriptor);
|
||||
assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass());
|
||||
assertEquals(Meta1.class, descriptor.getDeclaringClass());
|
||||
@@ -204,7 +207,7 @@ public class MetaAnnotationUtilsTests {
|
||||
@Test
|
||||
public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndAnnotatedSuperclass() {
|
||||
AnnotationDescriptor<ContextConfiguration> descriptor = findAnnotationDescriptor(
|
||||
MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, ContextConfiguration.class);
|
||||
MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, ContextConfiguration.class);
|
||||
|
||||
assertNotNull("AnnotationDescriptor should not be null", descriptor);
|
||||
assertEquals("rootDeclaringClass", MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, descriptor.getRootDeclaringClass());
|
||||
@@ -213,20 +216,19 @@ public class MetaAnnotationUtilsTests {
|
||||
assertNotNull("composedAnnotation should not be null", descriptor.getComposedAnnotation());
|
||||
assertEquals("composedAnnotationType", MetaConfig.class, descriptor.getComposedAnnotationType());
|
||||
|
||||
assertArrayEquals("configured classes", new Class[] { String.class },
|
||||
descriptor.getAnnotationAttributes().getClassArray("classes"));
|
||||
assertArrayEquals("configured classes", new Class<?>[] {String.class},
|
||||
descriptor.getAnnotationAttributes().getClassArray("classes"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() {
|
||||
assertAtComponentOnComposedAnnotation(ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2",
|
||||
Meta2.class);
|
||||
assertAtComponentOnComposedAnnotation(ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAnnotationDescriptorForSubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() {
|
||||
assertAtComponentOnComposedAnnotation(SubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class,
|
||||
ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class);
|
||||
ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,8 +255,8 @@ public class MetaAnnotationUtilsTests {
|
||||
@Test
|
||||
public void findAnnotationDescriptorOnAnnotatedClassWithMissingTargetMetaAnnotation() {
|
||||
// InheritedAnnotationClass is NOT annotated or meta-annotated with @Component
|
||||
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(InheritedAnnotationClass.class,
|
||||
Component.class);
|
||||
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(
|
||||
InheritedAnnotationClass.class, Component.class);
|
||||
assertNull("Should not find @Component on InheritedAnnotationClass", descriptor);
|
||||
}
|
||||
|
||||
@@ -263,8 +265,8 @@ public class MetaAnnotationUtilsTests {
|
||||
*/
|
||||
@Test
|
||||
public void findAnnotationDescriptorOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() {
|
||||
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(MetaCycleAnnotatedClass.class,
|
||||
Component.class);
|
||||
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(
|
||||
MetaCycleAnnotatedClass.class, Component.class);
|
||||
assertNull("Should not find @Component on MetaCycleAnnotatedClass", descriptor);
|
||||
}
|
||||
|
||||
@@ -272,32 +274,30 @@ public class MetaAnnotationUtilsTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void findAnnotationDescriptorForTypesWithNoAnnotationPresent() throws Exception {
|
||||
public void findAnnotationDescriptorForTypesWithNoAnnotationPresent() {
|
||||
assertNull(findAnnotationDescriptorForTypes(NonAnnotatedInterface.class, Transactional.class, Component.class));
|
||||
assertNull(findAnnotationDescriptorForTypes(NonAnnotatedClass.class, Transactional.class, Order.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnClass() throws Exception {
|
||||
public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnClass() {
|
||||
// Note: @Transactional is inherited
|
||||
assertEquals(InheritedAnnotationClass.class,
|
||||
findAnnotationDescriptorForTypes(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass());
|
||||
assertEquals(
|
||||
InheritedAnnotationClass.class,
|
||||
findAnnotationDescriptorForTypes(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass());
|
||||
assertEquals(
|
||||
InheritedAnnotationClass.class,
|
||||
findAnnotationDescriptorForTypes(SubInheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass());
|
||||
InheritedAnnotationClass.class,
|
||||
findAnnotationDescriptorForTypes(SubInheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnInterface() throws Exception {
|
||||
public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnInterface() {
|
||||
// Note: @Transactional is inherited
|
||||
Transactional rawAnnotation = InheritedAnnotationInterface.class.getAnnotation(Transactional.class);
|
||||
|
||||
UntypedAnnotationDescriptor descriptor;
|
||||
|
||||
descriptor = findAnnotationDescriptorForTypes(InheritedAnnotationInterface.class, Transactional.class);
|
||||
UntypedAnnotationDescriptor descriptor =
|
||||
findAnnotationDescriptorForTypes(InheritedAnnotationInterface.class, Transactional.class);
|
||||
assertNotNull(descriptor);
|
||||
assertEquals(InheritedAnnotationInterface.class, descriptor.getRootDeclaringClass());
|
||||
assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass());
|
||||
@@ -318,23 +318,22 @@ public class MetaAnnotationUtilsTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnClass() throws Exception {
|
||||
public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnClass() {
|
||||
// Note: @Order is not inherited.
|
||||
assertEquals(NonInheritedAnnotationClass.class,
|
||||
findAnnotationDescriptorForTypes(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass());
|
||||
findAnnotationDescriptorForTypes(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass());
|
||||
assertEquals(NonInheritedAnnotationClass.class,
|
||||
findAnnotationDescriptorForTypes(SubNonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass());
|
||||
findAnnotationDescriptorForTypes(SubNonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnInterface() throws Exception {
|
||||
public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnInterface() {
|
||||
// Note: @Order is not inherited.
|
||||
Order rawAnnotation = NonInheritedAnnotationInterface.class.getAnnotation(Order.class);
|
||||
|
||||
UntypedAnnotationDescriptor descriptor;
|
||||
|
||||
descriptor = findAnnotationDescriptorForTypes(NonInheritedAnnotationInterface.class, Order.class);
|
||||
UntypedAnnotationDescriptor descriptor =
|
||||
findAnnotationDescriptorForTypes(NonInheritedAnnotationInterface.class, Order.class);
|
||||
assertNotNull(descriptor);
|
||||
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass());
|
||||
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getDeclaringClass());
|
||||
@@ -349,10 +348,10 @@ public class MetaAnnotationUtilsTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void findAnnotationDescriptorForTypesWithLocalAndMetaComponentAnnotation() throws Exception {
|
||||
public void findAnnotationDescriptorForTypesWithLocalAndMetaComponentAnnotation() {
|
||||
Class<Component> annotationType = Component.class;
|
||||
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
|
||||
HasLocalAndMetaComponentAnnotation.class, Transactional.class, annotationType, Order.class);
|
||||
HasLocalAndMetaComponentAnnotation.class, Transactional.class, annotationType, Order.class);
|
||||
assertEquals(HasLocalAndMetaComponentAnnotation.class, descriptor.getRootDeclaringClass());
|
||||
assertEquals(annotationType, descriptor.getAnnotationType());
|
||||
assertNull(descriptor.getComposedAnnotation());
|
||||
@@ -360,45 +359,45 @@ public class MetaAnnotationUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAnnotationDescriptorForTypesWithMetaComponentAnnotation() throws Exception {
|
||||
public void findAnnotationDescriptorForTypesWithMetaComponentAnnotation() {
|
||||
Class<HasMetaComponentAnnotation> startClass = HasMetaComponentAnnotation.class;
|
||||
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, "meta1", Meta1.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes() throws Exception {
|
||||
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes() {
|
||||
Class<?> startClass = MetaConfigWithDefaultAttributesTestCase.class;
|
||||
Class<ContextConfiguration> annotationType = ContextConfiguration.class;
|
||||
|
||||
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class,
|
||||
ContextConfiguration.class, Order.class, Transactional.class);
|
||||
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass,
|
||||
Service.class, ContextConfiguration.class, Order.class, Transactional.class);
|
||||
|
||||
assertNotNull(descriptor);
|
||||
assertEquals(startClass, descriptor.getRootDeclaringClass());
|
||||
assertEquals(annotationType, descriptor.getAnnotationType());
|
||||
assertArrayEquals(new Class[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value());
|
||||
assertArrayEquals(new Class[] { MetaConfig.DevConfig.class, MetaConfig.ProductionConfig.class },
|
||||
descriptor.getAnnotationAttributes().getClassArray("classes"));
|
||||
assertArrayEquals(new Class<?>[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value());
|
||||
assertArrayEquals(new Class<?>[] {MetaConfig.DevConfig.class, MetaConfig.ProductionConfig.class},
|
||||
descriptor.getAnnotationAttributes().getClassArray("classes"));
|
||||
assertNotNull(descriptor.getComposedAnnotation());
|
||||
assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes() throws Exception {
|
||||
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes() {
|
||||
Class<?> startClass = MetaConfigWithOverriddenAttributesTestCase.class;
|
||||
Class<ContextConfiguration> annotationType = ContextConfiguration.class;
|
||||
|
||||
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class,
|
||||
ContextConfiguration.class, Order.class, Transactional.class);
|
||||
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
|
||||
startClass, Service.class, ContextConfiguration.class, Order.class, Transactional.class);
|
||||
|
||||
assertNotNull(descriptor);
|
||||
assertEquals(startClass, descriptor.getRootDeclaringClass());
|
||||
assertEquals(annotationType, descriptor.getAnnotationType());
|
||||
assertArrayEquals(new Class[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value());
|
||||
assertArrayEquals(new Class[] { MetaAnnotationUtilsTests.class },
|
||||
descriptor.getAnnotationAttributes().getClassArray("classes"));
|
||||
assertArrayEquals(new Class<?>[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value());
|
||||
assertArrayEquals(new Class<?>[] {MetaAnnotationUtilsTests.class},
|
||||
descriptor.getAnnotationAttributes().getClassArray("classes"));
|
||||
assertNotNull(descriptor.getComposedAnnotation());
|
||||
assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType());
|
||||
}
|
||||
@@ -412,13 +411,11 @@ public class MetaAnnotationUtilsTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void findAnnotationDescriptorForTypesForClassWithMetaAnnotatedInterface() {
|
||||
Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class,
|
||||
Component.class);
|
||||
Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component.class);
|
||||
|
||||
UntypedAnnotationDescriptor descriptor;
|
||||
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
|
||||
ClassWithMetaAnnotatedInterface.class, Service.class, Component.class, Order.class, Transactional.class);
|
||||
|
||||
descriptor = findAnnotationDescriptorForTypes(ClassWithMetaAnnotatedInterface.class, Service.class,
|
||||
Component.class, Order.class, Transactional.class);
|
||||
assertNotNull(descriptor);
|
||||
assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass());
|
||||
assertEquals(Meta1.class, descriptor.getDeclaringClass());
|
||||
@@ -435,8 +432,8 @@ public class MetaAnnotationUtilsTests {
|
||||
@Test
|
||||
public void findAnnotationDescriptorForTypesForSubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() {
|
||||
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(
|
||||
SubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class,
|
||||
ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class);
|
||||
SubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class,
|
||||
ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -445,8 +442,8 @@ public class MetaAnnotationUtilsTests {
|
||||
@Test
|
||||
public void findAnnotationDescriptorForTypesOnMetaMetaAnnotatedClass() {
|
||||
Class<MetaMetaAnnotatedClass> startClass = MetaMetaAnnotatedClass.class;
|
||||
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, startClass, Meta2.class, "meta2",
|
||||
MetaMeta.class);
|
||||
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(
|
||||
startClass, startClass, Meta2.class, "meta2", MetaMeta.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -455,8 +452,8 @@ public class MetaAnnotationUtilsTests {
|
||||
@Test
|
||||
public void findAnnotationDescriptorForTypesOnMetaMetaMetaAnnotatedClass() {
|
||||
Class<MetaMetaMetaAnnotatedClass> startClass = MetaMetaMetaAnnotatedClass.class;
|
||||
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, startClass, Meta2.class, "meta2",
|
||||
MetaMetaMeta.class);
|
||||
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(
|
||||
startClass, startClass, Meta2.class, "meta2", MetaMetaMeta.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -467,8 +464,8 @@ public class MetaAnnotationUtilsTests {
|
||||
public void findAnnotationDescriptorForTypesOnAnnotatedClassWithMissingTargetMetaAnnotation() {
|
||||
// InheritedAnnotationClass is NOT annotated or meta-annotated with @Component,
|
||||
// @Service, or @Order, but it is annotated with @Transactional.
|
||||
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(InheritedAnnotationClass.class,
|
||||
Service.class, Component.class, Order.class);
|
||||
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
|
||||
InheritedAnnotationClass.class, Service.class, Component.class, Order.class);
|
||||
assertNull("Should not find @Component on InheritedAnnotationClass", descriptor);
|
||||
}
|
||||
|
||||
@@ -478,8 +475,8 @@ public class MetaAnnotationUtilsTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void findAnnotationDescriptorForTypesOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() {
|
||||
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(MetaCycleAnnotatedClass.class,
|
||||
Service.class, Component.class, Order.class);
|
||||
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
|
||||
MetaCycleAnnotatedClass.class, Service.class, Component.class, Order.class);
|
||||
assertNull("Should not find @Component on MetaCycleAnnotatedClass", descriptor);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user