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"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project 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">
|
||||
|
||||
<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>
|
||||
|
||||
<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>
|
||||
<dependency>
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
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 {
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
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 {
|
||||
|
|
|
@ -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 ApplicationContextTestInjectType {
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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,19 +8,23 @@ 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;
|
||||
|
||||
@Test
|
||||
public void givenResourceQualifier_WhenSetter_ThenValidDependencies(){
|
||||
public void givenResourceQualifier_WhenSetter_ThenValidDependencies() {
|
||||
assertNotNull(arbDependency);
|
||||
assertEquals("namedFile.txt", arbDependency.getName());
|
||||
assertNotNull(anotherArbDependency);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,12 +8,16 @@ 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
|
||||
|
@ -30,13 +29,13 @@ public class QualifierResourceInjectionTest {
|
|||
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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue