|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2015 the original author or authors. |
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -54,23 +54,23 @@ public class AnnotationAttributesTests { |
|
|
|
nestedAttributes.put("name", "algernon"); |
|
|
|
nestedAttributes.put("name", "algernon"); |
|
|
|
|
|
|
|
|
|
|
|
attributes.put("name", "dave"); |
|
|
|
attributes.put("name", "dave"); |
|
|
|
attributes.put("names", new String[] { "dave", "frank", "hal" }); |
|
|
|
attributes.put("names", new String[] {"dave", "frank", "hal"}); |
|
|
|
attributes.put("bool1", true); |
|
|
|
attributes.put("bool1", true); |
|
|
|
attributes.put("bool2", false); |
|
|
|
attributes.put("bool2", false); |
|
|
|
attributes.put("color", Color.RED); |
|
|
|
attributes.put("color", Color.RED); |
|
|
|
attributes.put("class", Integer.class); |
|
|
|
attributes.put("class", Integer.class); |
|
|
|
attributes.put("classes", new Class<?>[] { Number.class, Short.class, Integer.class }); |
|
|
|
attributes.put("classes", new Class<?>[] {Number.class, Short.class, Integer.class}); |
|
|
|
attributes.put("number", 42); |
|
|
|
attributes.put("number", 42); |
|
|
|
attributes.put("anno", nestedAttributes); |
|
|
|
attributes.put("anno", nestedAttributes); |
|
|
|
attributes.put("annoArray", new AnnotationAttributes[] { nestedAttributes }); |
|
|
|
attributes.put("annoArray", new AnnotationAttributes[] {nestedAttributes}); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(attributes.getString("name"), equalTo("dave")); |
|
|
|
assertThat(attributes.getString("name"), equalTo("dave")); |
|
|
|
assertThat(attributes.getStringArray("names"), equalTo(new String[] { "dave", "frank", "hal" })); |
|
|
|
assertThat(attributes.getStringArray("names"), equalTo(new String[] {"dave", "frank", "hal"})); |
|
|
|
assertThat(attributes.getBoolean("bool1"), equalTo(true)); |
|
|
|
assertThat(attributes.getBoolean("bool1"), equalTo(true)); |
|
|
|
assertThat(attributes.getBoolean("bool2"), equalTo(false)); |
|
|
|
assertThat(attributes.getBoolean("bool2"), equalTo(false)); |
|
|
|
assertThat(attributes.<Color>getEnum("color"), equalTo(Color.RED)); |
|
|
|
assertThat(attributes.<Color>getEnum("color"), equalTo(Color.RED)); |
|
|
|
assertTrue(attributes.getClass("class").equals(Integer.class)); |
|
|
|
assertTrue(attributes.getClass("class").equals(Integer.class)); |
|
|
|
assertThat(attributes.getClassArray("classes"), equalTo(new Class[] { Number.class, Short.class, Integer.class })); |
|
|
|
assertThat(attributes.getClassArray("classes"), equalTo(new Class<?>[] {Number.class, Short.class, Integer.class})); |
|
|
|
assertThat(attributes.<Integer>getNumber("number"), equalTo(42)); |
|
|
|
assertThat(attributes.<Integer>getNumber("number"), equalTo(42)); |
|
|
|
assertThat(attributes.getAnnotation("anno").<Integer>getNumber("value"), equalTo(10)); |
|
|
|
assertThat(attributes.getAnnotation("anno").<Integer>getNumber("value"), equalTo(10)); |
|
|
|
assertThat(attributes.getAnnotationArray("annoArray")[0].getString("name"), equalTo("algernon")); |
|
|
|
assertThat(attributes.getAnnotationArray("annoArray")[0].getString("name"), equalTo("algernon")); |
|
|
|
@ -99,8 +99,8 @@ public class AnnotationAttributesTests { |
|
|
|
attributes.put("filters", filter); |
|
|
|
attributes.put("filters", filter); |
|
|
|
|
|
|
|
|
|
|
|
// Get back arrays of single elements
|
|
|
|
// Get back arrays of single elements
|
|
|
|
assertThat(attributes.getStringArray("names"), equalTo(new String[] { "Dogbert" })); |
|
|
|
assertThat(attributes.getStringArray("names"), equalTo(new String[] {"Dogbert"})); |
|
|
|
assertThat(attributes.getClassArray("classes"), equalTo(new Class[] { Number.class })); |
|
|
|
assertThat(attributes.getClassArray("classes"), equalTo(new Class<?>[] {Number.class})); |
|
|
|
|
|
|
|
|
|
|
|
AnnotationAttributes[] array = attributes.getAnnotationArray("nestedAttributes"); |
|
|
|
AnnotationAttributes[] array = attributes.getAnnotationArray("nestedAttributes"); |
|
|
|
assertNotNull(array); |
|
|
|
assertNotNull(array); |
|
|
|
@ -118,7 +118,7 @@ public class AnnotationAttributesTests { |
|
|
|
Filter filter = FilteredClass.class.getAnnotation(Filter.class); |
|
|
|
Filter filter = FilteredClass.class.getAnnotation(Filter.class); |
|
|
|
|
|
|
|
|
|
|
|
attributes.put("filter", filter); |
|
|
|
attributes.put("filter", filter); |
|
|
|
attributes.put("filters", new Filter[] { filter, filter }); |
|
|
|
attributes.put("filters", new Filter[] {filter, filter}); |
|
|
|
|
|
|
|
|
|
|
|
Filter retrievedFilter = attributes.getAnnotation("filter", Filter.class); |
|
|
|
Filter retrievedFilter = attributes.getAnnotation("filter", Filter.class); |
|
|
|
assertThat(retrievedFilter, equalTo(filter)); |
|
|
|
assertThat(retrievedFilter, equalTo(filter)); |
|
|
|
@ -257,7 +257,7 @@ public class AnnotationAttributesTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void getAliasedStringArray() { |
|
|
|
public void getAliasedStringArray() { |
|
|
|
final String[] INPUT = new String[] { "test.xml" }; |
|
|
|
final String[] INPUT = new String[] {"test.xml"}; |
|
|
|
final String[] EMPTY = new String[0]; |
|
|
|
final String[] EMPTY = new String[0]; |
|
|
|
|
|
|
|
|
|
|
|
attributes.clear(); |
|
|
|
attributes.clear(); |
|
|
|
@ -297,7 +297,7 @@ public class AnnotationAttributesTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void getAliasedStringArrayWithImplicitAliases() { |
|
|
|
public void getAliasedStringArrayWithImplicitAliases() { |
|
|
|
final String[] INPUT = new String[] { "test.xml" }; |
|
|
|
final String[] INPUT = new String[] {"test.xml"}; |
|
|
|
final String[] EMPTY = new String[0]; |
|
|
|
final String[] EMPTY = new String[0]; |
|
|
|
final List<String> aliases = Arrays.asList("value", "location1", "location2", "location3", "xmlFile", "groovyScript"); |
|
|
|
final List<String> aliases = Arrays.asList("value", "location1", "location2", "location3", "xmlFile", "groovyScript"); |
|
|
|
|
|
|
|
|
|
|
|
@ -352,8 +352,8 @@ public class AnnotationAttributesTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void getAliasedStringArrayWithDifferentAliasedValues() { |
|
|
|
public void getAliasedStringArrayWithDifferentAliasedValues() { |
|
|
|
attributes.put("location", new String[] { "1.xml" }); |
|
|
|
attributes.put("location", new String[] {"1.xml"}); |
|
|
|
attributes.put("value", new String[] { "2.xml" }); |
|
|
|
attributes.put("value", new String[] {"2.xml"}); |
|
|
|
|
|
|
|
|
|
|
|
exception.expect(AnnotationConfigurationException.class); |
|
|
|
exception.expect(AnnotationConfigurationException.class); |
|
|
|
exception.expectMessage(containsString("In annotation [" + ContextConfig.class.getName() + "]")); |
|
|
|
exception.expectMessage(containsString("In annotation [" + ContextConfig.class.getName() + "]")); |
|
|
|
@ -382,7 +382,7 @@ public class AnnotationAttributesTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void getAliasedClassArray() { |
|
|
|
public void getAliasedClassArray() { |
|
|
|
final Class<?>[] INPUT = new Class<?>[] { String.class }; |
|
|
|
final Class<?>[] INPUT = new Class<?>[] {String.class}; |
|
|
|
final Class<?>[] EMPTY = new Class<?>[0]; |
|
|
|
final Class<?>[] EMPTY = new Class<?>[0]; |
|
|
|
|
|
|
|
|
|
|
|
attributes.clear(); |
|
|
|
attributes.clear(); |
|
|
|
@ -422,7 +422,7 @@ public class AnnotationAttributesTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void getAliasedClassArrayWithImplicitAliases() { |
|
|
|
public void getAliasedClassArrayWithImplicitAliases() { |
|
|
|
final Class<?>[] INPUT = new Class<?>[] { String.class }; |
|
|
|
final Class<?>[] INPUT = new Class<?>[] {String.class}; |
|
|
|
final Class<?>[] EMPTY = new Class<?>[0]; |
|
|
|
final Class<?>[] EMPTY = new Class<?>[0]; |
|
|
|
final List<String> aliases = Arrays.asList("value", "location1", "location2", "location3", "xmlFile", "groovyScript"); |
|
|
|
final List<String> aliases = Arrays.asList("value", "location1", "location2", "location3", "xmlFile", "groovyScript"); |
|
|
|
|
|
|
|
|
|
|
|
@ -465,8 +465,8 @@ public class AnnotationAttributesTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void getAliasedClassArrayWithDifferentAliasedValues() { |
|
|
|
public void getAliasedClassArrayWithDifferentAliasedValues() { |
|
|
|
attributes.put("classes", new Class[] { String.class }); |
|
|
|
attributes.put("classes", new Class<?>[] {String.class}); |
|
|
|
attributes.put("value", new Class[] { Number.class }); |
|
|
|
attributes.put("value", new Class<?>[] {Number.class}); |
|
|
|
|
|
|
|
|
|
|
|
exception.expect(AnnotationConfigurationException.class); |
|
|
|
exception.expect(AnnotationConfigurationException.class); |
|
|
|
exception.expectMessage(containsString("In annotation [" + Filter.class.getName() + "]")); |
|
|
|
exception.expectMessage(containsString("In annotation [" + Filter.class.getName() + "]")); |
|
|
|
@ -477,6 +477,7 @@ public class AnnotationAttributesTests { |
|
|
|
getAliasedClassArray("classes"); |
|
|
|
getAliasedClassArray("classes"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Class<?>[] getAliasedClassArray(String attributeName) { |
|
|
|
private Class<?>[] getAliasedClassArray(String attributeName) { |
|
|
|
return attributes.getAliasedClassArray(attributeName, Filter.class, null); |
|
|
|
return attributes.getAliasedClassArray(attributeName, Filter.class, null); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -491,9 +492,11 @@ public class AnnotationAttributesTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum Color { |
|
|
|
enum Color { |
|
|
|
|
|
|
|
|
|
|
|
RED, WHITE, BLUE |
|
|
|
RED, WHITE, BLUE |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@interface Filter { |
|
|
|
@interface Filter { |
|
|
|
|
|
|
|
|
|
|
|
@ -506,10 +509,12 @@ public class AnnotationAttributesTests { |
|
|
|
String pattern(); |
|
|
|
String pattern(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Filter(pattern = "foo") |
|
|
|
@Filter(pattern = "foo") |
|
|
|
static class FilteredClass { |
|
|
|
static class FilteredClass { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Mock of {@code org.springframework.context.annotation.Scope}. |
|
|
|
* Mock of {@code org.springframework.context.annotation.Scope}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -523,6 +528,7 @@ public class AnnotationAttributesTests { |
|
|
|
String name() default "singleton"; |
|
|
|
String name() default "singleton"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Scope(name = "custom") |
|
|
|
@Scope(name = "custom") |
|
|
|
static class ScopedComponent { |
|
|
|
static class ScopedComponent { |
|
|
|
} |
|
|
|
} |
|
|
|
|