diff --git a/spring-core/src/test/java/com/baeldung/samplebeaninjectiontypes/SampleBeanInjectionTest.java b/spring-core/src/test/java/com/baeldung/samplebeaninjectiontypes/SampleBeanInjectionTest.java index f054a89a85..fb7234e5c5 100644 --- a/spring-core/src/test/java/com/baeldung/samplebeaninjectiontypes/SampleBeanInjectionTest.java +++ b/spring-core/src/test/java/com/baeldung/samplebeaninjectiontypes/SampleBeanInjectionTest.java @@ -4,6 +4,7 @@ import com.baeldung.dependencyinjectiontypes.ArticleWithSetterInjection; import com.baeldung.samplebeaninjectionypes.AccountDetails; import com.baeldung.samplebeaninjectionypes.BankAccountWithConstructorInjection; import com.baeldung.samplebeaninjectionypes.BankAccountWithSetterInjection; +import org.junit.Before; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -12,11 +13,16 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import static org.junit.Assert.assertTrue; public class SampleBeanInjectionTest { + ApplicationContext context; + + @Before + public void before(){ + context = new ClassPathXmlApplicationContext("dependencyinjectiontypes-context.xml"); + } @Test - public void testSetterInjectionValid() { + public void givenAutowiredAnnotation_WhenSetOnSetter_ThenDependencyValid() { - ApplicationContext context = new ClassPathXmlApplicationContext("samplebeaninjectiontypes-context.xml"); BankAccountWithSetterInjection bankAccountWithSetterInjection = (BankAccountWithSetterInjection) context.getBean("bankAccountWithSetterInjection"); String owner = "John Doe"; @@ -27,9 +33,8 @@ public class SampleBeanInjectionTest { } @Test - public void testConstructorInjectionValid() { + public void givenAutowiredAnnotation_WhenSetOnConstructor_ThenDependencyValid() { - ApplicationContext context = new ClassPathXmlApplicationContext("samplebeaninjectiontypes-context.xml"); BankAccountWithConstructorInjection bankAccountWithConstructorInjection = (BankAccountWithConstructorInjection) context.getBean("bankAccountWithConstructorInjectionBean"); String owner = "John Doe";