20
20
21
21
import org .springframework .beans .testfixture .beans .Employee ;
22
22
import org .springframework .beans .testfixture .beans .Pet ;
23
- import org .springframework .context .ApplicationContext ;
23
+ import org .springframework .context .ConfigurableApplicationContext ;
24
24
import org .springframework .context .support .GenericGroovyApplicationContext ;
25
25
26
26
import static org .assertj .core .api .Assertions .assertThat ;
@@ -42,22 +42,23 @@ class GroovyControlGroupTests {
42
42
43
43
@ Test
44
44
void verifyScriptUsingGenericGroovyApplicationContext () {
45
- ApplicationContext ctx = new GenericGroovyApplicationContext (getClass (), "context.groovy" );
45
+ try (ConfigurableApplicationContext ctx = new GenericGroovyApplicationContext (getClass (), "context.groovy" )) {
46
+ String foo = ctx .getBean ("foo" , String .class );
47
+ assertThat (foo ).isEqualTo ("Foo" );
46
48
47
- String foo = ctx .getBean ("foo " , String .class );
48
- assertThat (foo ).isEqualTo ("Foo " );
49
+ String bar = ctx .getBean ("bar " , String .class );
50
+ assertThat (bar ).isEqualTo ("Bar " );
49
51
50
- String bar = ctx .getBean ("bar" , String .class );
51
- assertThat (bar ).isEqualTo ("Bar" );
52
+ Pet pet = ctx .getBean (Pet .class );
53
+ assertThat (pet ).as ("pet" ).isNotNull ();
54
+ assertThat (pet .getName ()).isEqualTo ("Dogbert" );
52
55
53
- Pet pet = ctx .getBean (Pet .class );
54
- assertThat (pet ).as ("pet" ).isNotNull ();
55
- assertThat (pet .getName ()).isEqualTo ("Dogbert" );
56
+ Employee employee = ctx .getBean (Employee .class );
57
+ assertThat (employee ).as ("employee" ).isNotNull ();
58
+ assertThat (employee .getName ()).isEqualTo ("Dilbert" );
59
+ assertThat (employee .getCompany ()).isEqualTo ("???" );
60
+ }
56
61
57
- Employee employee = ctx .getBean (Employee .class );
58
- assertThat (employee ).as ("employee" ).isNotNull ();
59
- assertThat (employee .getName ()).isEqualTo ("Dilbert" );
60
- assertThat (employee .getCompany ()).isEqualTo ("???" );
61
62
}
62
63
63
64
}
0 commit comments