diff --git a/dependency-injection/pom.xml b/dependency-injection/pom.xml index 8fdc22999f..667ea87402 100644 --- a/dependency-injection/pom.xml +++ b/dependency-injection/pom.xml @@ -1,81 +1,83 @@ - + - 4.0.0 + 4.0.0 - com.baeldung - dependency-injection - 0.0.1-SNAPSHOT - war + com.baeldung + dependency-injection + 0.0.1-SNAPSHOT + war - Resource vs Inject vs Autowired - Accompanying the demonstration of the use of the annotations related to injection mechanisms, namely Resource, Inject, and Autowired + Resource vs Inject vs Autowired + Accompanying the demonstration of the use of the annotations related to injection mechanisms, namely + Resource, Inject, and Autowired + - - - junit - junit - 4.11 - test - - - org.mockito - mockito-all - 1.10.19 - - - org.springframework - spring-test - 4.2.6.RELEASE - - - org.springframework - spring-core - 4.2.6.RELEASE - - - org.springframework - spring-beans - 4.2.6.RELEASE - - - org.springframework - spring-context - 4.2.6.RELEASE - - - javax.inject - javax.inject - 1 - - + + + junit + junit + 4.11 + test + + + org.mockito + mockito-all + 1.10.19 + + + org.springframework + spring-test + 4.2.6.RELEASE + + + org.springframework + spring-core + 4.2.6.RELEASE + + + org.springframework + spring-beans + 4.2.6.RELEASE + + + org.springframework + spring-context + 4.2.6.RELEASE + + + javax.inject + javax.inject + 1 + + - - - - maven-compiler-plugin - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*Test.java - - - - - + + + + maven-compiler-plugin + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*Test.java + + + + + - - - java.net - https://maven.java.net/content/repositories/releases/ - - + + + java.net + https://maven.java.net/content/repositories/releases/ + + diff --git a/dependency-injection/src/test/java/com/baeldung/autowired/FieldAutowiredNameTest.java b/dependency-injection/src/test/java/com/baeldung/autowired/FieldAutowiredNameTest.java index 0455ca500c..cbdac68543 100644 --- a/dependency-injection/src/test/java/com/baeldung/autowired/FieldAutowiredNameTest.java +++ b/dependency-injection/src/test/java/com/baeldung/autowired/FieldAutowiredNameTest.java @@ -1,8 +1,7 @@ package com.baeldung.autowired; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - +import com.baeldung.configuration.ApplicationContextTestAutowiredName; +import com.baeldung.dependency.ArbitraryDependency; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -10,22 +9,21 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.baeldung.configuration.ApplicationContextTestAutowiredName; -import com.baeldung.dependency.ArbitraryDependency; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( - loader=AnnotationConfigContextLoader.class, - classes=ApplicationContextTestAutowiredName.class) + loader = AnnotationConfigContextLoader.class, + classes = ApplicationContextTestAutowiredName.class) public class FieldAutowiredNameTest { @Autowired private ArbitraryDependency autowiredFieldDependency; @Test - public void givenAutowiredAnnotation_WhenOnField_ThenDependencyValid(){ + public void givenAutowiredAnnotation_WhenOnField_ThenDependencyValid() { assertNotNull(autowiredFieldDependency); - assertEquals("Arbitrary Dependency", - autowiredFieldDependency.toString()); - } + assertEquals("Arbitrary Dependency", autowiredFieldDependency.toString()); + } } diff --git a/dependency-injection/src/test/java/com/baeldung/autowired/FieldAutowiredTest.java b/dependency-injection/src/test/java/com/baeldung/autowired/FieldAutowiredTest.java index 811daebaf6..b736871f85 100644 --- a/dependency-injection/src/test/java/com/baeldung/autowired/FieldAutowiredTest.java +++ b/dependency-injection/src/test/java/com/baeldung/autowired/FieldAutowiredTest.java @@ -1,8 +1,7 @@ package com.baeldung.autowired; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - +import com.baeldung.configuration.ApplicationContextTestAutowiredType; +import com.baeldung.dependency.ArbitraryDependency; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -10,13 +9,13 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.baeldung.configuration.ApplicationContextTestAutowiredType; -import com.baeldung.dependency.ArbitraryDependency; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( - loader=AnnotationConfigContextLoader.class, - classes=ApplicationContextTestAutowiredType.class) + loader = AnnotationConfigContextLoader.class, + classes = ApplicationContextTestAutowiredType.class) public class FieldAutowiredTest { @Autowired diff --git a/dependency-injection/src/test/java/com/baeldung/autowired/FieldQualifierAutowiredTest.java b/dependency-injection/src/test/java/com/baeldung/autowired/FieldQualifierAutowiredTest.java index d72d38e9a8..cbc3d56f67 100644 --- a/dependency-injection/src/test/java/com/baeldung/autowired/FieldQualifierAutowiredTest.java +++ b/dependency-injection/src/test/java/com/baeldung/autowired/FieldQualifierAutowiredTest.java @@ -1,8 +1,7 @@ package com.baeldung.autowired; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - +import com.baeldung.configuration.ApplicationContextTestAutowiredQualifier; +import com.baeldung.dependency.ArbitraryDependency; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -11,13 +10,13 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.baeldung.configuration.ApplicationContextTestAutowiredQualifier; -import com.baeldung.dependency.ArbitraryDependency; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( - loader=AnnotationConfigContextLoader.class, - classes=ApplicationContextTestAutowiredQualifier.class) + loader = AnnotationConfigContextLoader.class, + classes = ApplicationContextTestAutowiredQualifier.class) public class FieldQualifierAutowiredTest { @Autowired @@ -29,15 +28,14 @@ public class FieldQualifierAutowiredTest { private ArbitraryDependency fieldDependency2; @Test - public void givenAutowiredQualifier_WhenOnField_ThenDep1Valid(){ + public void givenAutowiredQualifier_WhenOnField_ThenDep1Valid() { assertNotNull(fieldDependency1); assertEquals("Arbitrary Dependency", fieldDependency1.toString()); } @Test - public void givenAutowiredQualifier_WhenOnField_ThenDep2Valid(){ + public void givenAutowiredQualifier_WhenOnField_ThenDep2Valid() { assertNotNull(fieldDependency2); - assertEquals("Another Arbitrary Dependency", - fieldDependency2.toString()); + assertEquals("Another Arbitrary Dependency", fieldDependency2.toString()); } } diff --git a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestAutowiredName.java b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestAutowiredName.java index 41dfdb09e2..48c4495465 100644 --- a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestAutowiredName.java +++ b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestAutowiredName.java @@ -4,6 +4,6 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @Configuration -@ComponentScan(basePackages={"com.baeldung.dependency"}) +@ComponentScan(basePackages = {"com.baeldung.dependency"}) public class ApplicationContextTestAutowiredName { } diff --git a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestAutowiredQualifier.java b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestAutowiredQualifier.java index 138fbc46c5..ef6690ab4b 100644 --- a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestAutowiredQualifier.java +++ b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestAutowiredQualifier.java @@ -1,25 +1,24 @@ package com.baeldung.configuration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - import com.baeldung.dependency.AnotherArbitraryDependency; import com.baeldung.dependency.ArbitraryDependency; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; @Configuration public class ApplicationContextTestAutowiredQualifier { - @Bean - public ArbitraryDependency autowiredFieldDependency() { - ArbitraryDependency autowiredFieldDependency = new ArbitraryDependency(); + @Bean + public ArbitraryDependency autowiredFieldDependency() { + ArbitraryDependency autowiredFieldDependency = new ArbitraryDependency(); - return autowiredFieldDependency; - } + return autowiredFieldDependency; + } - @Bean - public ArbitraryDependency anotherAutowiredFieldDependency() { - ArbitraryDependency anotherAutowiredFieldDependency = new AnotherArbitraryDependency(); + @Bean + public ArbitraryDependency anotherAutowiredFieldDependency() { + ArbitraryDependency anotherAutowiredFieldDependency = new AnotherArbitraryDependency(); - return anotherAutowiredFieldDependency; - } + return anotherAutowiredFieldDependency; + } } diff --git a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestAutowiredType.java b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestAutowiredType.java index 703a8214b9..240bc466b7 100644 --- a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestAutowiredType.java +++ b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestAutowiredType.java @@ -1,10 +1,9 @@ package com.baeldung.configuration; +import com.baeldung.dependency.ArbitraryDependency; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.baeldung.dependency.ArbitraryDependency; - @Configuration public class ApplicationContextTestAutowiredType { diff --git a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestInjectName.java b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestInjectName.java index 7fe8306a39..851aa0b8ee 100644 --- a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestInjectName.java +++ b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestInjectName.java @@ -1,10 +1,9 @@ package com.baeldung.configuration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - import com.baeldung.dependency.ArbitraryDependency; import com.baeldung.dependency.YetAnotherArbitraryDependency; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; @Configuration public class ApplicationContextTestInjectName { diff --git a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestInjectQualifier.java b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestInjectQualifier.java index 557ba78aca..59af5a91bb 100644 --- a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestInjectQualifier.java +++ b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestInjectQualifier.java @@ -1,23 +1,22 @@ package com.baeldung.configuration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - import com.baeldung.dependency.AnotherArbitraryDependency; import com.baeldung.dependency.ArbitraryDependency; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; @Configuration public class ApplicationContextTestInjectQualifier { - @Bean - public ArbitraryDependency defaultFile() { - ArbitraryDependency defaultFile = new ArbitraryDependency(); - return defaultFile; - } + @Bean + public ArbitraryDependency defaultFile() { + ArbitraryDependency defaultFile = new ArbitraryDependency(); + return defaultFile; + } - @Bean - public ArbitraryDependency namedFile() { - ArbitraryDependency namedFile = new AnotherArbitraryDependency(); - return namedFile; - } + @Bean + public ArbitraryDependency namedFile() { + ArbitraryDependency namedFile = new AnotherArbitraryDependency(); + return namedFile; + } } diff --git a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestInjectType.java b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestInjectType.java index f84fa8f3a2..1e1f01f269 100644 --- a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestInjectType.java +++ b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestInjectType.java @@ -1,16 +1,15 @@ package com.baeldung.configuration; +import com.baeldung.dependency.ArbitraryDependency; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.baeldung.dependency.ArbitraryDependency; - @Configuration public class ApplicationContextTestInjectType { - @Bean - public ArbitraryDependency injectDependency() { - ArbitraryDependency injectDependency = new ArbitraryDependency(); - return injectDependency; - } + @Bean + public ArbitraryDependency injectDependency() { + ArbitraryDependency injectDependency = new ArbitraryDependency(); + return injectDependency; + } } diff --git a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestResourceNameType.java b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestResourceNameType.java index f53002feca..cb1b5981e8 100644 --- a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestResourceNameType.java +++ b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestResourceNameType.java @@ -1,14 +1,14 @@ package com.baeldung.configuration; -import java.io.File; - import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.io.File; + @Configuration public class ApplicationContextTestResourceNameType { - @Bean(name="namedFile") + @Bean(name = "namedFile") public File namedFile() { File namedFile = new File("namedFile.txt"); return namedFile; diff --git a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestResourceQualifier.java b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestResourceQualifier.java index 18f5af4282..c9aa2f4a7d 100644 --- a/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestResourceQualifier.java +++ b/dependency-injection/src/test/java/com/baeldung/configuration/ApplicationContextTestResourceQualifier.java @@ -1,20 +1,20 @@ package com.baeldung.configuration; -import java.io.File; - import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.io.File; + @Configuration public class ApplicationContextTestResourceQualifier { - @Bean(name="defaultFile") + @Bean(name = "defaultFile") public File defaultFile() { File defaultFile = new File("defaultFile.txt"); return defaultFile; } - @Bean(name="namedFile") + @Bean(name = "namedFile") public File namedFile() { File namedFile = new File("namedFile.txt"); return namedFile; diff --git a/dependency-injection/src/test/java/com/baeldung/dependency/ArbitraryDependency.java b/dependency-injection/src/test/java/com/baeldung/dependency/ArbitraryDependency.java index d120e8daf7..3c90492d2c 100644 --- a/dependency-injection/src/test/java/com/baeldung/dependency/ArbitraryDependency.java +++ b/dependency-injection/src/test/java/com/baeldung/dependency/ArbitraryDependency.java @@ -2,7 +2,7 @@ package com.baeldung.dependency; import org.springframework.stereotype.Component; -@Component(value="autowiredFieldDependency") +@Component(value = "autowiredFieldDependency") public class ArbitraryDependency { private final String label = "Arbitrary Dependency"; diff --git a/dependency-injection/src/test/java/com/baeldung/inject/FieldByNameInjectTest.java b/dependency-injection/src/test/java/com/baeldung/inject/FieldByNameInjectTest.java index 0f0429ea94..665c9f1ddc 100644 --- a/dependency-injection/src/test/java/com/baeldung/inject/FieldByNameInjectTest.java +++ b/dependency-injection/src/test/java/com/baeldung/inject/FieldByNameInjectTest.java @@ -1,24 +1,23 @@ package com.baeldung.inject; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import javax.inject.Inject; -import javax.inject.Named; - +import com.baeldung.configuration.ApplicationContextTestInjectName; +import com.baeldung.dependency.ArbitraryDependency; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.baeldung.configuration.ApplicationContextTestInjectName; -import com.baeldung.dependency.ArbitraryDependency; +import javax.inject.Inject; +import javax.inject.Named; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( - loader=AnnotationConfigContextLoader.class, - classes=ApplicationContextTestInjectName.class) + loader = AnnotationConfigContextLoader.class, + classes = ApplicationContextTestInjectName.class) public class FieldByNameInjectTest { @Inject @@ -28,7 +27,6 @@ public class FieldByNameInjectTest { @Test public void givenInjectQualifier_WhenSetOnField_ThenDependencyValid() { assertNotNull(yetAnotherFieldInjectDependency); - assertEquals("Yet Another Arbitrary Dependency", - yetAnotherFieldInjectDependency.toString()); + assertEquals("Yet Another Arbitrary Dependency", yetAnotherFieldInjectDependency.toString()); } } diff --git a/dependency-injection/src/test/java/com/baeldung/inject/FieldInjectTest.java b/dependency-injection/src/test/java/com/baeldung/inject/FieldInjectTest.java index 7cbba63113..7561c39e76 100644 --- a/dependency-injection/src/test/java/com/baeldung/inject/FieldInjectTest.java +++ b/dependency-injection/src/test/java/com/baeldung/inject/FieldInjectTest.java @@ -1,31 +1,30 @@ package com.baeldung.inject; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import javax.inject.Inject; +import com.baeldung.configuration.ApplicationContextTestInjectType; +import com.baeldung.dependency.ArbitraryDependency; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.baeldung.configuration.ApplicationContextTestInjectType; -import com.baeldung.dependency.ArbitraryDependency; +import javax.inject.Inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( - loader=AnnotationConfigContextLoader.class, - classes=ApplicationContextTestInjectType.class) + loader = AnnotationConfigContextLoader.class, + classes = ApplicationContextTestInjectType.class) public class FieldInjectTest { @Inject private ArbitraryDependency fieldInjectDependency; @Test - public void givenInjectAnnotation_WhenOnField_ThenValidDependency(){ + public void givenInjectAnnotation_WhenOnField_ThenValidDependency() { assertNotNull(fieldInjectDependency); - assertEquals("Arbitrary Dependency", - fieldInjectDependency.toString()); + assertEquals("Arbitrary Dependency", fieldInjectDependency.toString()); } } diff --git a/dependency-injection/src/test/java/com/baeldung/inject/FieldQualifierInjectTest.java b/dependency-injection/src/test/java/com/baeldung/inject/FieldQualifierInjectTest.java index f0fc5866a3..7e5f7e7453 100644 --- a/dependency-injection/src/test/java/com/baeldung/inject/FieldQualifierInjectTest.java +++ b/dependency-injection/src/test/java/com/baeldung/inject/FieldQualifierInjectTest.java @@ -1,10 +1,7 @@ package com.baeldung.inject; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import javax.inject.Inject; - +import com.baeldung.configuration.ApplicationContextTestInjectQualifier; +import com.baeldung.dependency.ArbitraryDependency; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Qualifier; @@ -12,12 +9,14 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.baeldung.configuration.ApplicationContextTestInjectQualifier; -import com.baeldung.dependency.ArbitraryDependency; +import javax.inject.Inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(loader=AnnotationConfigContextLoader.class, - classes=ApplicationContextTestInjectQualifier.class) +@ContextConfiguration(loader = AnnotationConfigContextLoader.class, + classes = ApplicationContextTestInjectQualifier.class) public class FieldQualifierInjectTest { @Inject @@ -29,16 +28,14 @@ public class FieldQualifierInjectTest { private ArbitraryDependency namedDependency; @Test - public void givenInjectQualifier_WhenOnField_ThenDefaultFileValid(){ + public void givenInjectQualifier_WhenOnField_ThenDefaultFileValid() { assertNotNull(defaultDependency); - assertEquals("Arbitrary Dependency", - defaultDependency.toString()); + assertEquals("Arbitrary Dependency", defaultDependency.toString()); } @Test - public void givenInjectQualifier_WhenOnField_ThenNamedFileValid(){ + public void givenInjectQualifier_WhenOnField_ThenNamedFileValid() { assertNotNull(defaultDependency); - assertEquals("Another Arbitrary Dependency", - namedDependency.toString()); + assertEquals("Another Arbitrary Dependency", namedDependency.toString()); } } diff --git a/dependency-injection/src/test/java/com/baeldung/resource/FieldResourceInjectionTest.java b/dependency-injection/src/test/java/com/baeldung/resource/FieldResourceInjectionTest.java index ed73ae8d59..ef7e7b0aeb 100644 --- a/dependency-injection/src/test/java/com/baeldung/resource/FieldResourceInjectionTest.java +++ b/dependency-injection/src/test/java/com/baeldung/resource/FieldResourceInjectionTest.java @@ -1,30 +1,29 @@ package com.baeldung.resource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.File; - -import javax.annotation.Resource; +import com.baeldung.configuration.ApplicationContextTestResourceNameType; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.baeldung.configuration.ApplicationContextTestResourceNameType; +import javax.annotation.Resource; +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( - loader=AnnotationConfigContextLoader.class, - classes=ApplicationContextTestResourceNameType.class) + loader = AnnotationConfigContextLoader.class, + classes = ApplicationContextTestResourceNameType.class) public class FieldResourceInjectionTest { - @Resource(name="namedFile") + @Resource(name = "namedFile") private File defaultFile; @Test - public void givenResourceAnnotation_WhenOnField_ThenDependencyValid(){ + public void givenResourceAnnotation_WhenOnField_ThenDependencyValid() { assertNotNull(defaultFile); assertEquals("namedFile.txt", defaultFile.getName()); } diff --git a/dependency-injection/src/test/java/com/baeldung/resource/MethodByQualifierResourceTest.java b/dependency-injection/src/test/java/com/baeldung/resource/MethodByQualifierResourceTest.java index e512b6fe0a..95e9fc0bd5 100644 --- a/dependency-injection/src/test/java/com/baeldung/resource/MethodByQualifierResourceTest.java +++ b/dependency-injection/src/test/java/com/baeldung/resource/MethodByQualifierResourceTest.java @@ -1,12 +1,6 @@ package com.baeldung.resource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.File; - -import javax.annotation.Resource; - +import com.baeldung.configuration.ApplicationContextTestResourceQualifier; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Qualifier; @@ -14,34 +8,38 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.baeldung.configuration.ApplicationContextTestResourceQualifier; +import javax.annotation.Resource; +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( - loader=AnnotationConfigContextLoader.class, - classes=ApplicationContextTestResourceQualifier.class) + loader = AnnotationConfigContextLoader.class, + classes = ApplicationContextTestResourceQualifier.class) public class MethodByQualifierResourceTest { - private File arbDependency; - private File anotherArbDependency; + private File arbDependency; + private File anotherArbDependency; - @Test - public void givenResourceQualifier_WhenSetter_ThenValidDependencies(){ - assertNotNull(arbDependency); - assertEquals("namedFile.txt", arbDependency.getName()); - assertNotNull(anotherArbDependency); - assertEquals("defaultFile.txt", anotherArbDependency.getName()); - } + @Test + public void givenResourceQualifier_WhenSetter_ThenValidDependencies() { + assertNotNull(arbDependency); + assertEquals("namedFile.txt", arbDependency.getName()); + assertNotNull(anotherArbDependency); + assertEquals("defaultFile.txt", anotherArbDependency.getName()); + } - @Resource - @Qualifier("namedFile") - public void setArbDependency(File arbDependency) { - this.arbDependency = arbDependency; - } + @Resource + @Qualifier("namedFile") + public void setArbDependency(File arbDependency) { + this.arbDependency = arbDependency; + } - @Resource - @Qualifier("defaultFile") - public void setAnotherArbDependency(File anotherArbDependency) { - this.anotherArbDependency = anotherArbDependency; - } + @Resource + @Qualifier("defaultFile") + public void setAnotherArbDependency(File anotherArbDependency) { + this.anotherArbDependency = anotherArbDependency; + } } diff --git a/dependency-injection/src/test/java/com/baeldung/resource/MethodByTypeResourceTest.java b/dependency-injection/src/test/java/com/baeldung/resource/MethodByTypeResourceTest.java index edcf9b12ea..ad9a9a4fb6 100644 --- a/dependency-injection/src/test/java/com/baeldung/resource/MethodByTypeResourceTest.java +++ b/dependency-injection/src/test/java/com/baeldung/resource/MethodByTypeResourceTest.java @@ -1,24 +1,22 @@ package com.baeldung.resource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.File; - -import javax.annotation.Resource; - +import com.baeldung.configuration.ApplicationContextTestResourceNameType; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.baeldung.configuration.ApplicationContextTestResourceNameType; +import javax.annotation.Resource; +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( - loader=AnnotationConfigContextLoader.class, - classes=ApplicationContextTestResourceNameType.class) + loader = AnnotationConfigContextLoader.class, + classes = ApplicationContextTestResourceNameType.class) public class MethodByTypeResourceTest { private File defaultFile; @@ -29,7 +27,7 @@ public class MethodByTypeResourceTest { } @Test - public void givenResourceAnnotation_WhenSetter_ThenValidDependency(){ + public void givenResourceAnnotation_WhenSetter_ThenValidDependency() { assertNotNull(defaultFile); assertEquals("namedFile.txt", defaultFile.getName()); } diff --git a/dependency-injection/src/test/java/com/baeldung/resource/MethodResourceInjectionTest.java b/dependency-injection/src/test/java/com/baeldung/resource/MethodResourceInjectionTest.java index 38e9db8737..1622d8896c 100644 --- a/dependency-injection/src/test/java/com/baeldung/resource/MethodResourceInjectionTest.java +++ b/dependency-injection/src/test/java/com/baeldung/resource/MethodResourceInjectionTest.java @@ -1,35 +1,33 @@ package com.baeldung.resource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.File; - -import javax.annotation.Resource; - +import com.baeldung.configuration.ApplicationContextTestResourceNameType; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.baeldung.configuration.ApplicationContextTestResourceNameType; +import javax.annotation.Resource; +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( - loader=AnnotationConfigContextLoader.class, - classes=ApplicationContextTestResourceNameType.class) + loader = AnnotationConfigContextLoader.class, + classes = ApplicationContextTestResourceNameType.class) public class MethodResourceInjectionTest { private File defaultFile; - @Resource(name="namedFile") + @Resource(name = "namedFile") protected void setDefaultFile(File defaultFile) { this.defaultFile = defaultFile; } @Test - public void givenResourceAnnotation_WhenSetter_ThenDependencyValid(){ + public void givenResourceAnnotation_WhenSetter_ThenDependencyValid() { assertNotNull(defaultFile); assertEquals("namedFile.txt", defaultFile.getName()); } diff --git a/dependency-injection/src/test/java/com/baeldung/resource/NamedResourceTest.java b/dependency-injection/src/test/java/com/baeldung/resource/NamedResourceTest.java index 6dbe77da39..da104ecaae 100644 --- a/dependency-injection/src/test/java/com/baeldung/resource/NamedResourceTest.java +++ b/dependency-injection/src/test/java/com/baeldung/resource/NamedResourceTest.java @@ -1,25 +1,24 @@ package com.baeldung.resource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.File; - -import javax.annotation.Resource; +import com.baeldung.configuration.ApplicationContextTestResourceNameType; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.baeldung.configuration.ApplicationContextTestResourceNameType; +import javax.annotation.Resource; +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(loader=AnnotationConfigContextLoader.class, - classes=ApplicationContextTestResourceNameType.class) +@ContextConfiguration(loader = AnnotationConfigContextLoader.class, + classes = ApplicationContextTestResourceNameType.class) public class NamedResourceTest { - @Resource(name="namedFile") + @Resource(name = "namedFile") private File testFile; @Test diff --git a/dependency-injection/src/test/java/com/baeldung/resource/QualifierResourceInjectionTest.java b/dependency-injection/src/test/java/com/baeldung/resource/QualifierResourceInjectionTest.java index 9afa0cf4f9..024c8e2bbe 100644 --- a/dependency-injection/src/test/java/com/baeldung/resource/QualifierResourceInjectionTest.java +++ b/dependency-injection/src/test/java/com/baeldung/resource/QualifierResourceInjectionTest.java @@ -1,11 +1,6 @@ package com.baeldung.resource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.File; - -import javax.annotation.Resource; +import com.baeldung.configuration.ApplicationContextTestResourceQualifier; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Qualifier; @@ -13,30 +8,34 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.baeldung.configuration.ApplicationContextTestResourceQualifier; +import javax.annotation.Resource; +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( - loader=AnnotationConfigContextLoader.class, - classes=ApplicationContextTestResourceQualifier.class) + loader = AnnotationConfigContextLoader.class, + classes = ApplicationContextTestResourceQualifier.class) public class QualifierResourceInjectionTest { @Resource @Qualifier("defaultFile") private File dependency1; - + @Resource @Qualifier("namedFile") private File dependency2; @Test - public void givenResourceAnnotation_WhenField_ThenDependency1Valid(){ + public void givenResourceAnnotation_WhenField_ThenDependency1Valid() { assertNotNull(dependency1); assertEquals("defaultFile.txt", dependency1.getName()); } @Test - public void givenResourceQualifier_WhenField_ThenDependency2Valid(){ + public void givenResourceQualifier_WhenField_ThenDependency2Valid() { assertNotNull(dependency2); assertEquals("namedFile.txt", dependency2.getName()); } diff --git a/dependency-injection/src/test/java/com/baeldung/resource/SetterResourceInjectionTest.java b/dependency-injection/src/test/java/com/baeldung/resource/SetterResourceInjectionTest.java index 8a249fea4e..aa7cfda975 100644 --- a/dependency-injection/src/test/java/com/baeldung/resource/SetterResourceInjectionTest.java +++ b/dependency-injection/src/test/java/com/baeldung/resource/SetterResourceInjectionTest.java @@ -1,23 +1,21 @@ package com.baeldung.resource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.File; - -import javax.annotation.Resource; - +import com.baeldung.configuration.ApplicationContextTestResourceNameType; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.baeldung.configuration.ApplicationContextTestResourceNameType; +import javax.annotation.Resource; +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(loader=AnnotationConfigContextLoader.class, - classes=ApplicationContextTestResourceNameType.class) +@ContextConfiguration(loader = AnnotationConfigContextLoader.class, + classes = ApplicationContextTestResourceNameType.class) public class SetterResourceInjectionTest { private File defaultFile;