Reformat code style
This commit is contained in:
parent
25cb16d473
commit
da0cd158e7
|
@ -1,6 +1,6 @@
|
||||||
<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>
|
||||||
|
|
||||||
|
@ -10,7 +10,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
|
||||||
<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>
|
||||||
|
|
|
@ -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,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.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 {
|
||||||
|
|
|
@ -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,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.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 {
|
||||||
|
|
|
@ -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 ApplicationContextTestInjectType {
|
public class ApplicationContextTestInjectType {
|
||||||
|
|
||||||
|
|
|
@ -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,19 +8,23 @@ 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);
|
||||||
|
|
|
@ -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,12 +8,16 @@ 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
|
||||||
|
@ -30,13 +29,13 @@ public class QualifierResourceInjectionTest {
|
||||||
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…
Reference in New Issue