@@ -75,7 +75,6 @@ static MergedTestPropertySources buildMergedTestPropertySources(Class<?> testCla
75
75
return new MergedTestPropertySources ();
76
76
}
77
77
78
- // else...
79
78
List <TestPropertySourceAttributes > attributesList = resolveTestPropertySourceAttributes (testClass );
80
79
String [] locations = mergeLocations (attributesList );
81
80
String [] properties = mergeProperties (attributesList );
@@ -84,71 +83,60 @@ static MergedTestPropertySources buildMergedTestPropertySources(Class<?> testCla
84
83
85
84
private static List <TestPropertySourceAttributes > resolveTestPropertySourceAttributes (Class <?> testClass ) {
86
85
Assert .notNull (testClass , "Class must not be null" );
86
+ List <TestPropertySourceAttributes > attributesList = new ArrayList <>();
87
+ Class <TestPropertySource > annotationType = TestPropertySource .class ;
87
88
88
- final List <TestPropertySourceAttributes > attributesList = new ArrayList <>();
89
- final Class <TestPropertySource > annotationType = TestPropertySource .class ;
90
89
AnnotationDescriptor <TestPropertySource > descriptor = findAnnotationDescriptor (testClass , annotationType );
91
90
Assert .notNull (descriptor , String .format (
92
- "Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]" ,
93
- annotationType .getName (), testClass .getName ()));
91
+ "Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]" ,
92
+ annotationType .getName (), testClass .getName ()));
94
93
95
94
while (descriptor != null ) {
96
95
TestPropertySource testPropertySource = descriptor .synthesizeAnnotation ();
97
96
Class <?> rootDeclaringClass = descriptor .getRootDeclaringClass ();
98
-
99
97
if (logger .isTraceEnabled ()) {
100
98
logger .trace (String .format ("Retrieved @TestPropertySource [%s] for declaring class [%s]." ,
101
99
testPropertySource , rootDeclaringClass .getName ()));
102
100
}
103
-
104
- TestPropertySourceAttributes attributes = new TestPropertySourceAttributes (rootDeclaringClass ,
105
- testPropertySource );
101
+ TestPropertySourceAttributes attributes =
102
+ new TestPropertySourceAttributes (rootDeclaringClass , testPropertySource );
106
103
if (logger .isTraceEnabled ()) {
107
104
logger .trace ("Resolved TestPropertySource attributes: " + attributes );
108
105
}
109
106
attributesList .add (attributes );
110
-
111
107
descriptor = findAnnotationDescriptor (rootDeclaringClass .getSuperclass (), annotationType );
112
108
}
113
109
114
110
return attributesList ;
115
111
}
116
112
117
113
private static String [] mergeLocations (List <TestPropertySourceAttributes > attributesList ) {
118
- final List <String > locations = new ArrayList <>();
119
-
114
+ List <String > locations = new ArrayList <>();
120
115
for (TestPropertySourceAttributes attrs : attributesList ) {
121
116
if (logger .isTraceEnabled ()) {
122
117
logger .trace (String .format ("Processing locations for TestPropertySource attributes %s" , attrs ));
123
118
}
124
-
125
119
String [] locationsArray = TestContextResourceUtils .convertToClasspathResourcePaths (
126
- attrs .getDeclaringClass (), attrs .getLocations ());
120
+ attrs .getDeclaringClass (), attrs .getLocations ());
127
121
locations .addAll (0 , Arrays .<String > asList (locationsArray ));
128
-
129
122
if (!attrs .isInheritLocations ()) {
130
123
break ;
131
124
}
132
125
}
133
-
134
126
return StringUtils .toStringArray (locations );
135
127
}
136
128
137
129
private static String [] mergeProperties (List <TestPropertySourceAttributes > attributesList ) {
138
- final List <String > properties = new ArrayList <>();
139
-
130
+ List <String > properties = new ArrayList <>();
140
131
for (TestPropertySourceAttributes attrs : attributesList ) {
141
132
if (logger .isTraceEnabled ()) {
142
133
logger .trace (String .format ("Processing inlined properties for TestPropertySource attributes %s" , attrs ));
143
134
}
144
-
145
- properties .addAll (0 , Arrays .<String > asList (attrs .getProperties ()));
146
-
135
+ properties .addAll (0 , Arrays .<String >asList (attrs .getProperties ()));
147
136
if (!attrs .isInheritProperties ()) {
148
137
break ;
149
138
}
150
139
}
151
-
152
140
return StringUtils .toStringArray (properties );
153
141
}
154
142
@@ -168,8 +156,8 @@ private static String[] mergeProperties(List<TestPropertySourceAttributes> attri
168
156
* @throws IllegalStateException if an error occurs while processing a properties file
169
157
*/
170
158
public static void addPropertiesFilesToEnvironment (ConfigurableApplicationContext context , String ... locations ) {
171
- Assert .notNull (context , "context must not be null" );
172
- Assert .notNull (locations , "locations must not be null" );
159
+ Assert .notNull (context , "' context' must not be null" );
160
+ Assert .notNull (locations , "' locations' must not be null" );
173
161
addPropertiesFilesToEnvironment (context .getEnvironment (), context , locations );
174
162
}
175
163
@@ -196,9 +184,9 @@ public static void addPropertiesFilesToEnvironment(ConfigurableApplicationContex
196
184
public static void addPropertiesFilesToEnvironment (ConfigurableEnvironment environment ,
197
185
ResourceLoader resourceLoader , String ... locations ) {
198
186
199
- Assert .notNull (environment , "environment must not be null" );
200
- Assert .notNull (resourceLoader , "resourceLoader must not be null" );
201
- Assert .notNull (locations , "locations must not be null" );
187
+ Assert .notNull (environment , "' environment' must not be null" );
188
+ Assert .notNull (resourceLoader , "' resourceLoader' must not be null" );
189
+ Assert .notNull (locations , "' locations' must not be null" );
202
190
try {
203
191
for (String location : locations ) {
204
192
String resolvedLocation = environment .resolveRequiredPlaceholders (location );
@@ -225,8 +213,8 @@ public static void addPropertiesFilesToEnvironment(ConfigurableEnvironment envir
225
213
* @see #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])
226
214
*/
227
215
public static void addInlinedPropertiesToEnvironment (ConfigurableApplicationContext context , String ... inlinedProperties ) {
228
- Assert .notNull (context , "context must not be null" );
229
- Assert .notNull (inlinedProperties , "inlinedProperties must not be null" );
216
+ Assert .notNull (context , "' context' must not be null" );
217
+ Assert .notNull (inlinedProperties , "' inlinedProperties' must not be null" );
230
218
addInlinedPropertiesToEnvironment (context .getEnvironment (), inlinedProperties );
231
219
}
232
220
@@ -247,13 +235,15 @@ public static void addInlinedPropertiesToEnvironment(ConfigurableApplicationCont
247
235
* @see #convertInlinedPropertiesToMap
248
236
*/
249
237
public static void addInlinedPropertiesToEnvironment (ConfigurableEnvironment environment , String ... inlinedProperties ) {
250
- Assert .notNull (environment , "environment must not be null" );
251
- Assert .notNull (inlinedProperties , "inlinedProperties must not be null" );
238
+ Assert .notNull (environment , "' environment' must not be null" );
239
+ Assert .notNull (inlinedProperties , "' inlinedProperties' must not be null" );
252
240
if (!ObjectUtils .isEmpty (inlinedProperties )) {
253
241
if (logger .isDebugEnabled ()) {
254
- logger .debug ("Adding inlined properties to environment: " + ObjectUtils .nullSafeToString (inlinedProperties ));
242
+ logger .debug ("Adding inlined properties to environment: " +
243
+ ObjectUtils .nullSafeToString (inlinedProperties ));
255
244
}
256
- MapPropertySource ps = (MapPropertySource ) environment .getPropertySources ().get (INLINED_PROPERTIES_PROPERTY_SOURCE_NAME );
245
+ MapPropertySource ps = (MapPropertySource )
246
+ environment .getPropertySources ().get (INLINED_PROPERTIES_PROPERTY_SOURCE_NAME );
257
247
if (ps == null ) {
258
248
ps = new MapPropertySource (INLINED_PROPERTIES_PROPERTY_SOURCE_NAME , new LinkedHashMap <>());
259
249
environment .getPropertySources ().addFirst (ps );
@@ -280,7 +270,7 @@ public static void addInlinedPropertiesToEnvironment(ConfigurableEnvironment env
280
270
* @see #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])
281
271
*/
282
272
public static Map <String , Object > convertInlinedPropertiesToMap (String ... inlinedProperties ) {
283
- Assert .notNull (inlinedProperties , "inlinedProperties must not be null" );
273
+ Assert .notNull (inlinedProperties , "' inlinedProperties' must not be null" );
284
274
Map <String , Object > map = new LinkedHashMap <>();
285
275
Properties props = new Properties ();
286
276
0 commit comments