63
63
import org .springframework .util .ReflectionUtils ;
64
64
import org .springframework .util .StringUtils ;
65
65
66
- import static org .hamcrest .Matchers .*;
67
- import static org .junit .Assert .*;
66
+ import static org .hamcrest .Matchers .contains ;
67
+ import static org .hamcrest .Matchers .containsInAnyOrder ;
68
+ import static org .hamcrest .Matchers .equalTo ;
69
+ import static org .hamcrest .Matchers .not ;
70
+ import static org .hamcrest .Matchers .notNullValue ;
71
+ import static org .hamcrest .Matchers .nullValue ;
72
+ import static org .junit .Assert .assertEquals ;
73
+ import static org .junit .Assert .assertThat ;
74
+ import static org .junit .Assert .assertTrue ;
68
75
69
76
/**
70
77
* Tests for {@link ConfigFileApplicationListener}.
@@ -362,7 +369,8 @@ public void profilesAddedToEnvironmentAndViaProperty() throws Exception {
362
369
"spring.profiles.active:other" );
363
370
this .environment .addActiveProfile ("dev" );
364
371
this .initializer .onApplicationEvent (this .event );
365
- assertThat (Arrays .asList (this .environment .getActiveProfiles ()), containsInAnyOrder ("dev" , "other" ));
372
+ assertThat (Arrays .asList (this .environment .getActiveProfiles ()),
373
+ containsInAnyOrder ("dev" , "other" ));
366
374
assertThat (this .environment .getProperty ("my.property" ),
367
375
equalTo ("fromotherpropertiesfile" ));
368
376
validateProfilePrecedence (null , "dev" , "other" );
@@ -374,39 +382,48 @@ public void profilesAddedToEnvironmentAndViaPropertyDuplicate() throws Exception
374
382
"spring.profiles.active:dev,other" );
375
383
this .environment .addActiveProfile ("dev" );
376
384
this .initializer .onApplicationEvent (this .event );
377
- assertThat (Arrays .asList (this .environment .getActiveProfiles ()), containsInAnyOrder ("dev" , "other" ));
385
+ assertThat (Arrays .asList (this .environment .getActiveProfiles ()),
386
+ containsInAnyOrder ("dev" , "other" ));
378
387
assertThat (this .environment .getProperty ("my.property" ),
379
388
equalTo ("fromotherpropertiesfile" ));
380
389
validateProfilePrecedence (null , "dev" , "other" );
381
390
}
382
391
383
392
@ Test
384
- public void profilesAddedToEnvironmentAndViaPropertyDuplicateEnvironmentWins () throws Exception {
393
+ public void profilesAddedToEnvironmentAndViaPropertyDuplicateEnvironmentWins ()
394
+ throws Exception {
385
395
EnvironmentTestUtils .addEnvironment (this .environment ,
386
396
"spring.profiles.active:other,dev" );
387
397
this .environment .addActiveProfile ("other" );
388
398
this .initializer .onApplicationEvent (this .event );
389
- assertThat (Arrays .asList (this .environment .getActiveProfiles ()), containsInAnyOrder ("dev" , "other" ));
399
+ assertThat (Arrays .asList (this .environment .getActiveProfiles ()),
400
+ containsInAnyOrder ("dev" , "other" ));
390
401
assertThat (this .environment .getProperty ("my.property" ),
391
402
equalTo ("fromdevpropertiesfile" ));
392
403
validateProfilePrecedence (null , "other" , "dev" );
393
404
}
394
405
395
406
private void validateProfilePrecedence (String ... profiles ) {
396
- this .initializer .onApplicationEvent (new ApplicationPreparedEvent (
397
- new SpringApplication (), new String [0 ], new AnnotationConfigApplicationContext ()));
407
+ ApplicationPreparedEvent event = new ApplicationPreparedEvent (
408
+ new SpringApplication (), new String [0 ],
409
+ new AnnotationConfigApplicationContext ());
410
+ this .initializer .onApplicationEvent (event );
398
411
String log = this .out .toString ();
399
412
400
413
// First make sure that each profile got processed only once
401
414
for (String profile : profiles ) {
402
- assertThat ("Wrong number of occurrences for profile '" + profile + "' --> " + log ,
403
- StringUtils .countOccurrencesOf (log , createLogForProfile (profile )), equalTo (1 ));
415
+ String reason = "Wrong number of occurrences for profile '" + profile
416
+ + "' --> " + log ;
417
+ assertThat (reason ,
418
+ StringUtils .countOccurrencesOf (log , createLogForProfile (profile )),
419
+ equalTo (1 ));
404
420
}
405
421
// Make sure the order of loading is the right one
406
422
for (String profile : profiles ) {
407
423
String line = createLogForProfile (profile );
408
424
int index = log .indexOf (line );
409
- assertTrue ("Loading profile '" + profile + "' not found in '" + log + "'" , index != -1 );
425
+ assertTrue ("Loading profile '" + profile + "' not found in '" + log + "'" ,
426
+ index != -1 );
410
427
log = log .substring (index + line .length (), log .length ());
411
428
}
412
429
}
0 commit comments