Reformat code style
This commit is contained in:
parent
25cb16d473
commit
da0cd158e7
@ -1,81 +1,83 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>dependency-injection</artifactId>
|
<artifactId>dependency-injection</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<name>Resource vs Inject vs Autowired</name>
|
<name>Resource vs Inject vs Autowired</name>
|
||||||
<description>Accompanying the demonstration of the use of the annotations related to injection mechanisms, namely Resource, Inject, and Autowired</description>
|
<description>Accompanying the demonstration of the use of the annotations related to injection mechanisms, namely
|
||||||
|
Resource, Inject, and Autowired
|
||||||
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.11</version>
|
<version>4.11</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-all</artifactId>
|
<artifactId>mockito-all</artifactId>
|
||||||
<version>1.10.19</version>
|
<version>1.10.19</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-test</artifactId>
|
<artifactId>spring-test</artifactId>
|
||||||
<version>4.2.6.RELEASE</version>
|
<version>4.2.6.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-core</artifactId>
|
<artifactId>spring-core</artifactId>
|
||||||
<version>4.2.6.RELEASE</version>
|
<version>4.2.6.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-beans</artifactId>
|
<artifactId>spring-beans</artifactId>
|
||||||
<version>4.2.6.RELEASE</version>
|
<version>4.2.6.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-context</artifactId>
|
<artifactId>spring-context</artifactId>
|
||||||
<version>4.2.6.RELEASE</version>
|
<version>4.2.6.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.inject</groupId>
|
<groupId>javax.inject</groupId>
|
||||||
<artifactId>javax.inject</artifactId>
|
<artifactId>javax.inject</artifactId>
|
||||||
<version>1</version>
|
<version>1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.8</source>
|
<source>1.8</source>
|
||||||
<target>1.8</target>
|
<target>1.8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<includes>
|
<includes>
|
||||||
<include>**/*Test.java</include>
|
<include>**/*Test.java</include>
|
||||||
</includes>
|
</includes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>java.net</id>
|
<id>java.net</id>
|
||||||
<url>https://maven.java.net/content/repositories/releases/</url>
|
<url>https://maven.java.net/content/repositories/releases/</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package com.baeldung.autowired;
|
package com.baeldung.autowired;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.baeldung.configuration.ApplicationContextTestAutowiredName;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
import com.baeldung.configuration.ApplicationContextTestAutowiredName;
|
import static org.junit.Assert.assertEquals;
|
||||||
import com.baeldung.dependency.ArbitraryDependency;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(
|
@ContextConfiguration(
|
||||||
loader=AnnotationConfigContextLoader.class,
|
loader = AnnotationConfigContextLoader.class,
|
||||||
classes=ApplicationContextTestAutowiredName.class)
|
classes = ApplicationContextTestAutowiredName.class)
|
||||||
public class FieldAutowiredNameTest {
|
public class FieldAutowiredNameTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ArbitraryDependency autowiredFieldDependency;
|
private ArbitraryDependency autowiredFieldDependency;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenAutowiredAnnotation_WhenOnField_ThenDependencyValid(){
|
public void givenAutowiredAnnotation_WhenOnField_ThenDependencyValid() {
|
||||||
assertNotNull(autowiredFieldDependency);
|
assertNotNull(autowiredFieldDependency);
|
||||||
assertEquals("Arbitrary Dependency",
|
assertEquals("Arbitrary Dependency", autowiredFieldDependency.toString());
|
||||||
autowiredFieldDependency.toString());
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package com.baeldung.autowired;
|
package com.baeldung.autowired;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.baeldung.configuration.ApplicationContextTestAutowiredType;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
import com.baeldung.configuration.ApplicationContextTestAutowiredType;
|
import static org.junit.Assert.assertEquals;
|
||||||
import com.baeldung.dependency.ArbitraryDependency;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(
|
@ContextConfiguration(
|
||||||
loader=AnnotationConfigContextLoader.class,
|
loader = AnnotationConfigContextLoader.class,
|
||||||
classes=ApplicationContextTestAutowiredType.class)
|
classes = ApplicationContextTestAutowiredType.class)
|
||||||
public class FieldAutowiredTest {
|
public class FieldAutowiredTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package com.baeldung.autowired;
|
package com.baeldung.autowired;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.baeldung.configuration.ApplicationContextTestAutowiredQualifier;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
import com.baeldung.configuration.ApplicationContextTestAutowiredQualifier;
|
import static org.junit.Assert.assertEquals;
|
||||||
import com.baeldung.dependency.ArbitraryDependency;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(
|
@ContextConfiguration(
|
||||||
loader=AnnotationConfigContextLoader.class,
|
loader = AnnotationConfigContextLoader.class,
|
||||||
classes=ApplicationContextTestAutowiredQualifier.class)
|
classes = ApplicationContextTestAutowiredQualifier.class)
|
||||||
public class FieldQualifierAutowiredTest {
|
public class FieldQualifierAutowiredTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -29,15 +28,14 @@ public class FieldQualifierAutowiredTest {
|
|||||||
private ArbitraryDependency fieldDependency2;
|
private ArbitraryDependency fieldDependency2;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenAutowiredQualifier_WhenOnField_ThenDep1Valid(){
|
public void givenAutowiredQualifier_WhenOnField_ThenDep1Valid() {
|
||||||
assertNotNull(fieldDependency1);
|
assertNotNull(fieldDependency1);
|
||||||
assertEquals("Arbitrary Dependency", fieldDependency1.toString());
|
assertEquals("Arbitrary Dependency", fieldDependency1.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenAutowiredQualifier_WhenOnField_ThenDep2Valid(){
|
public void givenAutowiredQualifier_WhenOnField_ThenDep2Valid() {
|
||||||
assertNotNull(fieldDependency2);
|
assertNotNull(fieldDependency2);
|
||||||
assertEquals("Another Arbitrary Dependency",
|
assertEquals("Another Arbitrary Dependency", fieldDependency2.toString());
|
||||||
fieldDependency2.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,6 @@ import org.springframework.context.annotation.ComponentScan;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(basePackages={"com.baeldung.dependency"})
|
@ComponentScan(basePackages = {"com.baeldung.dependency"})
|
||||||
public class ApplicationContextTestAutowiredName {
|
public class ApplicationContextTestAutowiredName {
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,24 @@
|
|||||||
package com.baeldung.configuration;
|
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.AnotherArbitraryDependency;
|
||||||
import com.baeldung.dependency.ArbitraryDependency;
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class ApplicationContextTestAutowiredQualifier {
|
public class ApplicationContextTestAutowiredQualifier {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ArbitraryDependency autowiredFieldDependency() {
|
public ArbitraryDependency autowiredFieldDependency() {
|
||||||
ArbitraryDependency autowiredFieldDependency = new ArbitraryDependency();
|
ArbitraryDependency autowiredFieldDependency = new ArbitraryDependency();
|
||||||
|
|
||||||
return autowiredFieldDependency;
|
return autowiredFieldDependency;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ArbitraryDependency anotherAutowiredFieldDependency() {
|
public ArbitraryDependency anotherAutowiredFieldDependency() {
|
||||||
ArbitraryDependency anotherAutowiredFieldDependency = new AnotherArbitraryDependency();
|
ArbitraryDependency anotherAutowiredFieldDependency = new AnotherArbitraryDependency();
|
||||||
|
|
||||||
return anotherAutowiredFieldDependency;
|
return anotherAutowiredFieldDependency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package com.baeldung.configuration;
|
package com.baeldung.configuration;
|
||||||
|
|
||||||
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import com.baeldung.dependency.ArbitraryDependency;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class ApplicationContextTestAutowiredType {
|
public class ApplicationContextTestAutowiredType {
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package com.baeldung.configuration;
|
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.ArbitraryDependency;
|
||||||
import com.baeldung.dependency.YetAnotherArbitraryDependency;
|
import com.baeldung.dependency.YetAnotherArbitraryDependency;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class ApplicationContextTestInjectName {
|
public class ApplicationContextTestInjectName {
|
||||||
|
@ -1,23 +1,22 @@
|
|||||||
package com.baeldung.configuration;
|
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.AnotherArbitraryDependency;
|
||||||
import com.baeldung.dependency.ArbitraryDependency;
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class ApplicationContextTestInjectQualifier {
|
public class ApplicationContextTestInjectQualifier {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ArbitraryDependency defaultFile() {
|
public ArbitraryDependency defaultFile() {
|
||||||
ArbitraryDependency defaultFile = new ArbitraryDependency();
|
ArbitraryDependency defaultFile = new ArbitraryDependency();
|
||||||
return defaultFile;
|
return defaultFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ArbitraryDependency namedFile() {
|
public ArbitraryDependency namedFile() {
|
||||||
ArbitraryDependency namedFile = new AnotherArbitraryDependency();
|
ArbitraryDependency namedFile = new AnotherArbitraryDependency();
|
||||||
return namedFile;
|
return namedFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
package com.baeldung.configuration;
|
package com.baeldung.configuration;
|
||||||
|
|
||||||
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import com.baeldung.dependency.ArbitraryDependency;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class ApplicationContextTestInjectType {
|
public class ApplicationContextTestInjectType {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ArbitraryDependency injectDependency() {
|
public ArbitraryDependency injectDependency() {
|
||||||
ArbitraryDependency injectDependency = new ArbitraryDependency();
|
ArbitraryDependency injectDependency = new ArbitraryDependency();
|
||||||
return injectDependency;
|
return injectDependency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package com.baeldung.configuration;
|
package com.baeldung.configuration;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class ApplicationContextTestResourceNameType {
|
public class ApplicationContextTestResourceNameType {
|
||||||
|
|
||||||
@Bean(name="namedFile")
|
@Bean(name = "namedFile")
|
||||||
public File namedFile() {
|
public File namedFile() {
|
||||||
File namedFile = new File("namedFile.txt");
|
File namedFile = new File("namedFile.txt");
|
||||||
return namedFile;
|
return namedFile;
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
package com.baeldung.configuration;
|
package com.baeldung.configuration;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class ApplicationContextTestResourceQualifier {
|
public class ApplicationContextTestResourceQualifier {
|
||||||
|
|
||||||
@Bean(name="defaultFile")
|
@Bean(name = "defaultFile")
|
||||||
public File defaultFile() {
|
public File defaultFile() {
|
||||||
File defaultFile = new File("defaultFile.txt");
|
File defaultFile = new File("defaultFile.txt");
|
||||||
return defaultFile;
|
return defaultFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean(name="namedFile")
|
@Bean(name = "namedFile")
|
||||||
public File namedFile() {
|
public File namedFile() {
|
||||||
File namedFile = new File("namedFile.txt");
|
File namedFile = new File("namedFile.txt");
|
||||||
return namedFile;
|
return namedFile;
|
||||||
|
@ -2,7 +2,7 @@ package com.baeldung.dependency;
|
|||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component(value="autowiredFieldDependency")
|
@Component(value = "autowiredFieldDependency")
|
||||||
public class ArbitraryDependency {
|
public class ArbitraryDependency {
|
||||||
|
|
||||||
private final String label = "Arbitrary Dependency";
|
private final String label = "Arbitrary Dependency";
|
||||||
|
@ -1,24 +1,23 @@
|
|||||||
package com.baeldung.inject;
|
package com.baeldung.inject;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.baeldung.configuration.ApplicationContextTestInjectName;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
import com.baeldung.configuration.ApplicationContextTestInjectName;
|
import javax.inject.Inject;
|
||||||
import com.baeldung.dependency.ArbitraryDependency;
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(
|
@ContextConfiguration(
|
||||||
loader=AnnotationConfigContextLoader.class,
|
loader = AnnotationConfigContextLoader.class,
|
||||||
classes=ApplicationContextTestInjectName.class)
|
classes = ApplicationContextTestInjectName.class)
|
||||||
public class FieldByNameInjectTest {
|
public class FieldByNameInjectTest {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -28,7 +27,6 @@ public class FieldByNameInjectTest {
|
|||||||
@Test
|
@Test
|
||||||
public void givenInjectQualifier_WhenSetOnField_ThenDependencyValid() {
|
public void givenInjectQualifier_WhenSetOnField_ThenDependencyValid() {
|
||||||
assertNotNull(yetAnotherFieldInjectDependency);
|
assertNotNull(yetAnotherFieldInjectDependency);
|
||||||
assertEquals("Yet Another Arbitrary Dependency",
|
assertEquals("Yet Another Arbitrary Dependency", yetAnotherFieldInjectDependency.toString());
|
||||||
yetAnotherFieldInjectDependency.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,30 @@
|
|||||||
package com.baeldung.inject;
|
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.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
import com.baeldung.configuration.ApplicationContextTestInjectType;
|
import javax.inject.Inject;
|
||||||
import com.baeldung.dependency.ArbitraryDependency;
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(
|
@ContextConfiguration(
|
||||||
loader=AnnotationConfigContextLoader.class,
|
loader = AnnotationConfigContextLoader.class,
|
||||||
classes=ApplicationContextTestInjectType.class)
|
classes = ApplicationContextTestInjectType.class)
|
||||||
public class FieldInjectTest {
|
public class FieldInjectTest {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ArbitraryDependency fieldInjectDependency;
|
private ArbitraryDependency fieldInjectDependency;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenInjectAnnotation_WhenOnField_ThenValidDependency(){
|
public void givenInjectAnnotation_WhenOnField_ThenValidDependency() {
|
||||||
assertNotNull(fieldInjectDependency);
|
assertNotNull(fieldInjectDependency);
|
||||||
assertEquals("Arbitrary Dependency",
|
assertEquals("Arbitrary Dependency", fieldInjectDependency.toString());
|
||||||
fieldInjectDependency.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package com.baeldung.inject;
|
package com.baeldung.inject;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.baeldung.configuration.ApplicationContextTestInjectQualifier;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
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.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
import com.baeldung.configuration.ApplicationContextTestInjectQualifier;
|
import javax.inject.Inject;
|
||||||
import com.baeldung.dependency.ArbitraryDependency;
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(loader=AnnotationConfigContextLoader.class,
|
@ContextConfiguration(loader = AnnotationConfigContextLoader.class,
|
||||||
classes=ApplicationContextTestInjectQualifier.class)
|
classes = ApplicationContextTestInjectQualifier.class)
|
||||||
public class FieldQualifierInjectTest {
|
public class FieldQualifierInjectTest {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -29,16 +28,14 @@ public class FieldQualifierInjectTest {
|
|||||||
private ArbitraryDependency namedDependency;
|
private ArbitraryDependency namedDependency;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenInjectQualifier_WhenOnField_ThenDefaultFileValid(){
|
public void givenInjectQualifier_WhenOnField_ThenDefaultFileValid() {
|
||||||
assertNotNull(defaultDependency);
|
assertNotNull(defaultDependency);
|
||||||
assertEquals("Arbitrary Dependency",
|
assertEquals("Arbitrary Dependency", defaultDependency.toString());
|
||||||
defaultDependency.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenInjectQualifier_WhenOnField_ThenNamedFileValid(){
|
public void givenInjectQualifier_WhenOnField_ThenNamedFileValid() {
|
||||||
assertNotNull(defaultDependency);
|
assertNotNull(defaultDependency);
|
||||||
assertEquals("Another Arbitrary Dependency",
|
assertEquals("Another Arbitrary Dependency", namedDependency.toString());
|
||||||
namedDependency.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,29 @@
|
|||||||
package com.baeldung.resource;
|
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.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
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)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(
|
@ContextConfiguration(
|
||||||
loader=AnnotationConfigContextLoader.class,
|
loader = AnnotationConfigContextLoader.class,
|
||||||
classes=ApplicationContextTestResourceNameType.class)
|
classes = ApplicationContextTestResourceNameType.class)
|
||||||
public class FieldResourceInjectionTest {
|
public class FieldResourceInjectionTest {
|
||||||
|
|
||||||
@Resource(name="namedFile")
|
@Resource(name = "namedFile")
|
||||||
private File defaultFile;
|
private File defaultFile;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenResourceAnnotation_WhenOnField_ThenDependencyValid(){
|
public void givenResourceAnnotation_WhenOnField_ThenDependencyValid() {
|
||||||
assertNotNull(defaultFile);
|
assertNotNull(defaultFile);
|
||||||
assertEquals("namedFile.txt", defaultFile.getName());
|
assertEquals("namedFile.txt", defaultFile.getName());
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
package com.baeldung.resource;
|
package com.baeldung.resource;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.baeldung.configuration.ApplicationContextTestResourceQualifier;
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
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.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
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)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(
|
@ContextConfiguration(
|
||||||
loader=AnnotationConfigContextLoader.class,
|
loader = AnnotationConfigContextLoader.class,
|
||||||
classes=ApplicationContextTestResourceQualifier.class)
|
classes = ApplicationContextTestResourceQualifier.class)
|
||||||
public class MethodByQualifierResourceTest {
|
public class MethodByQualifierResourceTest {
|
||||||
|
|
||||||
private File arbDependency;
|
private File arbDependency;
|
||||||
private File anotherArbDependency;
|
private File anotherArbDependency;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenResourceQualifier_WhenSetter_ThenValidDependencies(){
|
public void givenResourceQualifier_WhenSetter_ThenValidDependencies() {
|
||||||
assertNotNull(arbDependency);
|
assertNotNull(arbDependency);
|
||||||
assertEquals("namedFile.txt", arbDependency.getName());
|
assertEquals("namedFile.txt", arbDependency.getName());
|
||||||
assertNotNull(anotherArbDependency);
|
assertNotNull(anotherArbDependency);
|
||||||
assertEquals("defaultFile.txt", anotherArbDependency.getName());
|
assertEquals("defaultFile.txt", anotherArbDependency.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Qualifier("namedFile")
|
@Qualifier("namedFile")
|
||||||
public void setArbDependency(File arbDependency) {
|
public void setArbDependency(File arbDependency) {
|
||||||
this.arbDependency = arbDependency;
|
this.arbDependency = arbDependency;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Qualifier("defaultFile")
|
@Qualifier("defaultFile")
|
||||||
public void setAnotherArbDependency(File anotherArbDependency) {
|
public void setAnotherArbDependency(File anotherArbDependency) {
|
||||||
this.anotherArbDependency = anotherArbDependency;
|
this.anotherArbDependency = anotherArbDependency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,22 @@
|
|||||||
package com.baeldung.resource;
|
package com.baeldung.resource;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.baeldung.configuration.ApplicationContextTestResourceNameType;
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
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)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(
|
@ContextConfiguration(
|
||||||
loader=AnnotationConfigContextLoader.class,
|
loader = AnnotationConfigContextLoader.class,
|
||||||
classes=ApplicationContextTestResourceNameType.class)
|
classes = ApplicationContextTestResourceNameType.class)
|
||||||
public class MethodByTypeResourceTest {
|
public class MethodByTypeResourceTest {
|
||||||
|
|
||||||
private File defaultFile;
|
private File defaultFile;
|
||||||
@ -29,7 +27,7 @@ public class MethodByTypeResourceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenResourceAnnotation_WhenSetter_ThenValidDependency(){
|
public void givenResourceAnnotation_WhenSetter_ThenValidDependency() {
|
||||||
assertNotNull(defaultFile);
|
assertNotNull(defaultFile);
|
||||||
assertEquals("namedFile.txt", defaultFile.getName());
|
assertEquals("namedFile.txt", defaultFile.getName());
|
||||||
}
|
}
|
||||||
|
@ -1,35 +1,33 @@
|
|||||||
package com.baeldung.resource;
|
package com.baeldung.resource;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.baeldung.configuration.ApplicationContextTestResourceNameType;
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
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)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(
|
@ContextConfiguration(
|
||||||
loader=AnnotationConfigContextLoader.class,
|
loader = AnnotationConfigContextLoader.class,
|
||||||
classes=ApplicationContextTestResourceNameType.class)
|
classes = ApplicationContextTestResourceNameType.class)
|
||||||
public class MethodResourceInjectionTest {
|
public class MethodResourceInjectionTest {
|
||||||
|
|
||||||
private File defaultFile;
|
private File defaultFile;
|
||||||
|
|
||||||
@Resource(name="namedFile")
|
@Resource(name = "namedFile")
|
||||||
protected void setDefaultFile(File defaultFile) {
|
protected void setDefaultFile(File defaultFile) {
|
||||||
this.defaultFile = defaultFile;
|
this.defaultFile = defaultFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenResourceAnnotation_WhenSetter_ThenDependencyValid(){
|
public void givenResourceAnnotation_WhenSetter_ThenDependencyValid() {
|
||||||
assertNotNull(defaultFile);
|
assertNotNull(defaultFile);
|
||||||
assertEquals("namedFile.txt", defaultFile.getName());
|
assertEquals("namedFile.txt", defaultFile.getName());
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,24 @@
|
|||||||
package com.baeldung.resource;
|
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.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
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)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(loader=AnnotationConfigContextLoader.class,
|
@ContextConfiguration(loader = AnnotationConfigContextLoader.class,
|
||||||
classes=ApplicationContextTestResourceNameType.class)
|
classes = ApplicationContextTestResourceNameType.class)
|
||||||
public class NamedResourceTest {
|
public class NamedResourceTest {
|
||||||
|
|
||||||
@Resource(name="namedFile")
|
@Resource(name = "namedFile")
|
||||||
private File testFile;
|
private File testFile;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
package com.baeldung.resource;
|
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.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
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.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
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)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(
|
@ContextConfiguration(
|
||||||
loader=AnnotationConfigContextLoader.class,
|
loader = AnnotationConfigContextLoader.class,
|
||||||
classes=ApplicationContextTestResourceQualifier.class)
|
classes = ApplicationContextTestResourceQualifier.class)
|
||||||
public class QualifierResourceInjectionTest {
|
public class QualifierResourceInjectionTest {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Qualifier("defaultFile")
|
@Qualifier("defaultFile")
|
||||||
private File dependency1;
|
private File dependency1;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Qualifier("namedFile")
|
@Qualifier("namedFile")
|
||||||
private File dependency2;
|
private File dependency2;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenResourceAnnotation_WhenField_ThenDependency1Valid(){
|
public void givenResourceAnnotation_WhenField_ThenDependency1Valid() {
|
||||||
assertNotNull(dependency1);
|
assertNotNull(dependency1);
|
||||||
assertEquals("defaultFile.txt", dependency1.getName());
|
assertEquals("defaultFile.txt", dependency1.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenResourceQualifier_WhenField_ThenDependency2Valid(){
|
public void givenResourceQualifier_WhenField_ThenDependency2Valid() {
|
||||||
assertNotNull(dependency2);
|
assertNotNull(dependency2);
|
||||||
assertEquals("namedFile.txt", dependency2.getName());
|
assertEquals("namedFile.txt", dependency2.getName());
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,21 @@
|
|||||||
package com.baeldung.resource;
|
package com.baeldung.resource;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.baeldung.configuration.ApplicationContextTestResourceNameType;
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
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)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(loader=AnnotationConfigContextLoader.class,
|
@ContextConfiguration(loader = AnnotationConfigContextLoader.class,
|
||||||
classes=ApplicationContextTestResourceNameType.class)
|
classes = ApplicationContextTestResourceNameType.class)
|
||||||
public class SetterResourceInjectionTest {
|
public class SetterResourceInjectionTest {
|
||||||
|
|
||||||
private File defaultFile;
|
private File defaultFile;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user