@@ -51,14 +51,14 @@ public class ContextConfigurationAttributes {
51
51
52
52
private final boolean inheritLocations ;
53
53
54
- private final Class <? extends ContextLoader > contextLoaderClass ;
55
-
56
54
private final Class <? extends ApplicationContextInitializer <? extends ConfigurableApplicationContext >>[] initializers ;
57
55
58
56
private final boolean inheritInitializers ;
59
57
60
58
private final String name ;
61
59
60
+ private final Class <? extends ContextLoader > contextLoaderClass ;
61
+
62
62
63
63
/**
64
64
* Construct a new {@link ContextConfigurationAttributes} instance for the
@@ -69,8 +69,8 @@ public class ContextConfigurationAttributes {
69
69
*/
70
70
public ContextConfigurationAttributes (Class <?> declaringClass , ContextConfiguration contextConfiguration ) {
71
71
this (declaringClass , resolveLocations (declaringClass , contextConfiguration ), contextConfiguration .classes (),
72
- contextConfiguration .inheritLocations (), contextConfiguration .initializers (),
73
- contextConfiguration .inheritInitializers (), contextConfiguration .name (), contextConfiguration .loader ());
72
+ contextConfiguration .inheritLocations (), contextConfiguration .initializers (),
73
+ contextConfiguration .inheritInitializers (), contextConfiguration .name (), contextConfiguration .loader ());
74
74
}
75
75
76
76
/**
@@ -84,11 +84,11 @@ public ContextConfigurationAttributes(Class<?> declaringClass, ContextConfigurat
84
84
@ SuppressWarnings ("unchecked" )
85
85
public ContextConfigurationAttributes (Class <?> declaringClass , AnnotationAttributes annAttrs ) {
86
86
this (declaringClass ,
87
- resolveLocations (declaringClass , annAttrs .getStringArray ("locations" ), annAttrs .getStringArray ("value" )),
88
- annAttrs .getClassArray ("classes" ), annAttrs .getBoolean ("inheritLocations" ),
89
- (Class <? extends ApplicationContextInitializer <? extends ConfigurableApplicationContext >>[]) annAttrs .getClassArray ("initializers" ),
90
- annAttrs .getBoolean ("inheritInitializers" ), annAttrs .getString ("name" ),
91
- (Class <? extends ContextLoader >) annAttrs .getClass ("loader" ));
87
+ resolveLocations (declaringClass , annAttrs .getStringArray ("locations" ), annAttrs .getStringArray ("value" )),
88
+ annAttrs .getClassArray ("classes" ), annAttrs .getBoolean ("inheritLocations" ),
89
+ (Class <? extends ApplicationContextInitializer <? extends ConfigurableApplicationContext >>[]) annAttrs .getClassArray ("initializers" ),
90
+ annAttrs .getBoolean ("inheritInitializers" ), annAttrs .getString ("name" ),
91
+ (Class <? extends ContextLoader >) annAttrs .getClass ("loader" ));
92
92
}
93
93
94
94
/**
@@ -119,7 +119,6 @@ public ContextConfigurationAttributes(Class<?> declaringClass, String[] location
119
119
* {@linkplain Class test class} that declared the
120
120
* {@link ContextConfiguration @ContextConfiguration} annotation and its
121
121
* corresponding attributes.
122
- *
123
122
* @param declaringClass the test class that declared {@code @ContextConfiguration}
124
123
* @param locations the resource locations declared via {@code @ContextConfiguration}
125
124
* @param classes the annotated classes declared via {@code @ContextConfiguration}
@@ -134,8 +133,9 @@ public ContextConfigurationAttributes(
134
133
Class <?> declaringClass , String [] locations , Class <?>[] classes , boolean inheritLocations ,
135
134
Class <? extends ApplicationContextInitializer <? extends ConfigurableApplicationContext >>[] initializers ,
136
135
boolean inheritInitializers , Class <? extends ContextLoader > contextLoaderClass ) {
136
+
137
137
this (declaringClass , locations , classes , inheritLocations , initializers , inheritInitializers , null ,
138
- contextLoaderClass );
138
+ contextLoaderClass );
139
139
}
140
140
141
141
/**
@@ -164,11 +164,11 @@ public ContextConfigurationAttributes(
164
164
165
165
if (!ObjectUtils .isEmpty (locations ) && !ObjectUtils .isEmpty (classes ) && logger .isDebugEnabled ()) {
166
166
logger .debug (String .format (
167
- "Test class [%s] has been configured with @ContextConfiguration's 'locations' (or 'value') %s "
168
- + "and 'classes' %s attributes. Most SmartContextLoader implementations support "
169
- + "only one declaration of resources per @ContextConfiguration annotation." ,
170
- declaringClass .getName (), ObjectUtils .nullSafeToString (locations ),
171
- ObjectUtils .nullSafeToString (classes )));
167
+ "Test class [%s] has been configured with @ContextConfiguration's 'locations' (or 'value') %s " +
168
+ "and 'classes' %s attributes. Most SmartContextLoader implementations support " +
169
+ "only one declaration of resources per @ContextConfiguration annotation." ,
170
+ declaringClass .getName (), ObjectUtils .nullSafeToString (locations ),
171
+ ObjectUtils .nullSafeToString (classes )));
172
172
}
173
173
174
174
this .declaringClass = declaringClass ;
@@ -177,7 +177,7 @@ public ContextConfigurationAttributes(
177
177
this .inheritLocations = inheritLocations ;
178
178
this .initializers = initializers ;
179
179
this .inheritInitializers = inheritInitializers ;
180
- this .name = StringUtils .hasText (name ) ? name : null ;
180
+ this .name = ( StringUtils .hasText (name ) ? name : null ) ;
181
181
this .contextLoaderClass = contextLoaderClass ;
182
182
}
183
183
@@ -245,6 +245,17 @@ public Class<?>[] getClasses() {
245
245
return this .classes ;
246
246
}
247
247
248
+ /**
249
+ * Determine if this {@code ContextConfigurationAttributes} instance has
250
+ * class-based resources.
251
+ * @return {@code true} if the {@link #getClasses() classes} array is not empty
252
+ * @see #hasResources()
253
+ * @see #hasLocations()
254
+ */
255
+ public boolean hasClasses () {
256
+ return !ObjectUtils .isEmpty (getClasses ());
257
+ }
258
+
248
259
/**
249
260
* Set the <em>processed</em> resource locations, effectively overriding the
250
261
* original value declared via {@link ContextConfiguration @ContextConfiguration}.
@@ -280,17 +291,6 @@ public boolean hasLocations() {
280
291
return !ObjectUtils .isEmpty (getLocations ());
281
292
}
282
293
283
- /**
284
- * Determine if this {@code ContextConfigurationAttributes} instance has
285
- * class-based resources.
286
- * @return {@code true} if the {@link #getClasses() classes} array is not empty
287
- * @see #hasResources()
288
- * @see #hasLocations()
289
- */
290
- public boolean hasClasses () {
291
- return !ObjectUtils .isEmpty (getClasses ());
292
- }
293
-
294
294
/**
295
295
* Determine if this {@code ContextConfigurationAttributes} instance has
296
296
* either path-based resource locations or class-based resources.
@@ -300,7 +300,7 @@ public boolean hasClasses() {
300
300
* @see #hasClasses()
301
301
*/
302
302
public boolean hasResources () {
303
- return hasLocations () || hasClasses ();
303
+ return ( hasLocations () || hasClasses () );
304
304
}
305
305
306
306
/**
@@ -310,7 +310,7 @@ public boolean hasResources() {
310
310
* @see ContextConfiguration#inheritLocations
311
311
*/
312
312
public boolean isInheritLocations () {
313
- return inheritLocations ;
313
+ return this . inheritLocations ;
314
314
}
315
315
316
316
/**
@@ -320,7 +320,7 @@ public boolean isInheritLocations() {
320
320
* @since 3.2
321
321
*/
322
322
public Class <? extends ApplicationContextInitializer <? extends ConfigurableApplicationContext >>[] getInitializers () {
323
- return initializers ;
323
+ return this . initializers ;
324
324
}
325
325
326
326
/**
@@ -330,17 +330,7 @@ public Class<? extends ApplicationContextInitializer<? extends ConfigurableAppli
330
330
* @since 3.2
331
331
*/
332
332
public boolean isInheritInitializers () {
333
- return inheritInitializers ;
334
- }
335
-
336
- /**
337
- * Get the {@code ContextLoader} class that was declared via
338
- * {@link ContextConfiguration @ContextConfiguration}.
339
- * @return the {@code ContextLoader} class
340
- * @see ContextConfiguration#loader
341
- */
342
- public Class <? extends ContextLoader > getContextLoaderClass () {
343
- return contextLoaderClass ;
333
+ return this .inheritInitializers ;
344
334
}
345
335
346
336
/**
@@ -354,6 +344,16 @@ public String getName() {
354
344
return this .name ;
355
345
}
356
346
347
+ /**
348
+ * Get the {@code ContextLoader} class that was declared via
349
+ * {@link ContextConfiguration @ContextConfiguration}.
350
+ * @return the {@code ContextLoader} class
351
+ * @see ContextConfiguration#loader
352
+ */
353
+ public Class <? extends ContextLoader > getContextLoaderClass () {
354
+ return this .contextLoaderClass ;
355
+ }
356
+
357
357
358
358
/**
359
359
* Determine if the supplied object is equal to this
@@ -367,47 +367,22 @@ public String getName() {
367
367
* {@link #getContextLoaderClass() ContextLoader class}.
368
368
*/
369
369
@ Override
370
- public boolean equals (Object obj ) {
371
- if (this == obj ) {
370
+ public boolean equals (Object other ) {
371
+ if (this == other ) {
372
372
return true ;
373
373
}
374
- if (!(obj instanceof ContextConfigurationAttributes )) {
375
- return false ;
376
- }
377
-
378
- ContextConfigurationAttributes that = (ContextConfigurationAttributes ) obj ;
379
- if (this .declaringClass == null ) {
380
- if (that .declaringClass != null ) {
381
- return false ;
382
- }
383
- }
384
- else if (!this .declaringClass .equals (that .declaringClass )) {
374
+ if (!(other instanceof ContextConfigurationAttributes )) {
385
375
return false ;
386
376
}
387
- if (!Arrays .equals (this .locations , that .locations )) {
388
- return false ;
389
- }
390
- if (!Arrays .equals (this .classes , that .classes )) {
391
- return false ;
392
- }
393
- if (this .inheritLocations != that .inheritLocations ) {
394
- return false ;
395
- }
396
- if (!Arrays .equals (this .initializers , that .initializers )) {
397
- return false ;
398
- }
399
- if (this .inheritInitializers != that .inheritInitializers ) {
400
- return false ;
401
- }
402
- if (this .contextLoaderClass == null ) {
403
- if (that .contextLoaderClass != null ) {
404
- return false ;
405
- }
406
- }
407
- else if (!this .contextLoaderClass .equals (that .contextLoaderClass )) {
408
- return false ;
409
- }
410
- return true ;
377
+ ContextConfigurationAttributes otherAttr = (ContextConfigurationAttributes ) other ;
378
+ return (ObjectUtils .nullSafeEquals (this .declaringClass , otherAttr .declaringClass ) &&
379
+ Arrays .equals (this .classes , otherAttr .classes )) &&
380
+ Arrays .equals (this .locations , otherAttr .locations ) &&
381
+ this .inheritLocations == otherAttr .inheritLocations &&
382
+ Arrays .equals (this .initializers , otherAttr .initializers ) &&
383
+ this .inheritInitializers == otherAttr .inheritInitializers &&
384
+ ObjectUtils .nullSafeEquals (this .name , otherAttr .name ) &&
385
+ ObjectUtils .nullSafeEquals (this .contextLoaderClass , otherAttr .contextLoaderClass );
411
386
}
412
387
413
388
/**
@@ -418,10 +393,9 @@ else if (!this.contextLoaderClass.equals(that.contextLoaderClass)) {
418
393
@ Override
419
394
public int hashCode () {
420
395
int result = this .declaringClass .hashCode ();
421
- result = 31 * result + Arrays .hashCode (this .locations );
422
396
result = 31 * result + Arrays .hashCode (this .classes );
397
+ result = 31 * result + Arrays .hashCode (this .locations );
423
398
result = 31 * result + Arrays .hashCode (this .initializers );
424
- result = 31 * result + this .contextLoaderClass .hashCode ();
425
399
return result ;
426
400
}
427
401
@@ -433,8 +407,8 @@ public int hashCode() {
433
407
public String toString () {
434
408
return new ToStringCreator (this )
435
409
.append ("declaringClass" , this .declaringClass .getName ())
436
- .append ("locations" , ObjectUtils .nullSafeToString (this .locations ))
437
410
.append ("classes" , ObjectUtils .nullSafeToString (this .classes ))
411
+ .append ("locations" , ObjectUtils .nullSafeToString (this .locations ))
438
412
.append ("inheritLocations" , this .inheritLocations )
439
413
.append ("initializers" , ObjectUtils .nullSafeToString (this .initializers ))
440
414
.append ("inheritInitializers" , this .inheritInitializers )
0 commit comments