File tree Expand file tree Collapse file tree
spring-core/src/test/java/com/baeldung/samplebeaninjectiontypes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import com .baeldung .samplebeaninjectionypes .AccountDetails ;
55import com .baeldung .samplebeaninjectionypes .BankAccountWithConstructorInjection ;
66import com .baeldung .samplebeaninjectionypes .BankAccountWithSetterInjection ;
7+ import org .junit .Before ;
78import org .junit .Test ;
89import org .springframework .context .ApplicationContext ;
910import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
1213import static org .junit .Assert .assertTrue ;
1314
1415public class SampleBeanInjectionTest {
16+ ApplicationContext context ;
17+
18+ @ Before
19+ public void before (){
20+ context = new ClassPathXmlApplicationContext ("dependencyinjectiontypes-context.xml" );
21+ }
1522
1623 @ Test
17- public void testSetterInjectionValid () {
24+ public void givenAutowiredAnnotation_WhenSetOnSetter_ThenDependencyValid () {
1825
19- ApplicationContext context = new ClassPathXmlApplicationContext ("samplebeaninjectiontypes-context.xml" );
2026 BankAccountWithSetterInjection bankAccountWithSetterInjection = (BankAccountWithSetterInjection ) context .getBean ("bankAccountWithSetterInjection" );
2127
2228 String owner = "John Doe" ;
@@ -27,9 +33,8 @@ public void testSetterInjectionValid() {
2733 }
2834
2935 @ Test
30- public void testConstructorInjectionValid () {
36+ public void givenAutowiredAnnotation_WhenSetOnConstructor_ThenDependencyValid () {
3137
32- ApplicationContext context = new ClassPathXmlApplicationContext ("samplebeaninjectiontypes-context.xml" );
3338 BankAccountWithConstructorInjection bankAccountWithConstructorInjection = (BankAccountWithConstructorInjection ) context .getBean ("bankAccountWithConstructorInjectionBean" );
3439
3540 String owner = "John Doe" ;
You can’t perform that action at this time.
0 commit comments