Reformat code style
This commit is contained in:
+9
-11
@@ -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
|
||||
|
||||
+9
-11
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
}
|
||||
|
||||
+12
-13
@@ -1,25 +1,24 @@
|
||||
package com.baeldung.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.baeldung.dependency.AnotherArbitraryDependency;
|
||||
import com.baeldung.dependency.ArbitraryDependency;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class ApplicationContextTestAutowiredQualifier {
|
||||
|
||||
@Bean
|
||||
public ArbitraryDependency autowiredFieldDependency() {
|
||||
ArbitraryDependency autowiredFieldDependency = new ArbitraryDependency();
|
||||
@Bean
|
||||
public ArbitraryDependency autowiredFieldDependency() {
|
||||
ArbitraryDependency autowiredFieldDependency = new ArbitraryDependency();
|
||||
|
||||
return autowiredFieldDependency;
|
||||
}
|
||||
return autowiredFieldDependency;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ArbitraryDependency anotherAutowiredFieldDependency() {
|
||||
ArbitraryDependency anotherAutowiredFieldDependency = new AnotherArbitraryDependency();
|
||||
@Bean
|
||||
public ArbitraryDependency anotherAutowiredFieldDependency() {
|
||||
ArbitraryDependency anotherAutowiredFieldDependency = new AnotherArbitraryDependency();
|
||||
|
||||
return anotherAutowiredFieldDependency;
|
||||
}
|
||||
return anotherAutowiredFieldDependency;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -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 {
|
||||
|
||||
|
||||
+2
-3
@@ -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 {
|
||||
|
||||
+12
-13
@@ -1,23 +1,22 @@
|
||||
package com.baeldung.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.baeldung.dependency.AnotherArbitraryDependency;
|
||||
import com.baeldung.dependency.ArbitraryDependency;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class ApplicationContextTestInjectQualifier {
|
||||
|
||||
@Bean
|
||||
public ArbitraryDependency defaultFile() {
|
||||
ArbitraryDependency defaultFile = new ArbitraryDependency();
|
||||
return defaultFile;
|
||||
}
|
||||
@Bean
|
||||
public ArbitraryDependency defaultFile() {
|
||||
ArbitraryDependency defaultFile = new ArbitraryDependency();
|
||||
return defaultFile;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ArbitraryDependency namedFile() {
|
||||
ArbitraryDependency namedFile = new AnotherArbitraryDependency();
|
||||
return namedFile;
|
||||
}
|
||||
@Bean
|
||||
public ArbitraryDependency namedFile() {
|
||||
ArbitraryDependency namedFile = new AnotherArbitraryDependency();
|
||||
return namedFile;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-7
@@ -1,16 +1,15 @@
|
||||
package com.baeldung.configuration;
|
||||
|
||||
import com.baeldung.dependency.ArbitraryDependency;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.baeldung.dependency.ArbitraryDependency;
|
||||
|
||||
@Configuration
|
||||
public class ApplicationContextTestInjectType {
|
||||
|
||||
@Bean
|
||||
public ArbitraryDependency injectDependency() {
|
||||
ArbitraryDependency injectDependency = new ArbitraryDependency();
|
||||
return injectDependency;
|
||||
}
|
||||
@Bean
|
||||
public ArbitraryDependency injectDependency() {
|
||||
ArbitraryDependency injectDependency = new ArbitraryDependency();
|
||||
return injectDependency;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -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;
|
||||
|
||||
+4
-4
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
+12
-15
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
+10
-11
@@ -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());
|
||||
}
|
||||
|
||||
+27
-29
@@ -1,12 +1,6 @@
|
||||
package com.baeldung.resource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.baeldung.configuration.ApplicationContextTestResourceQualifier;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -14,34 +8,38 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import com.baeldung.configuration.ApplicationContextTestResourceQualifier;
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(
|
||||
loader=AnnotationConfigContextLoader.class,
|
||||
classes=ApplicationContextTestResourceQualifier.class)
|
||||
loader = AnnotationConfigContextLoader.class,
|
||||
classes = ApplicationContextTestResourceQualifier.class)
|
||||
public class MethodByQualifierResourceTest {
|
||||
|
||||
private File arbDependency;
|
||||
private File anotherArbDependency;
|
||||
private File arbDependency;
|
||||
private File anotherArbDependency;
|
||||
|
||||
@Test
|
||||
public void givenResourceQualifier_WhenSetter_ThenValidDependencies(){
|
||||
assertNotNull(arbDependency);
|
||||
assertEquals("namedFile.txt", arbDependency.getName());
|
||||
assertNotNull(anotherArbDependency);
|
||||
assertEquals("defaultFile.txt", anotherArbDependency.getName());
|
||||
}
|
||||
@Test
|
||||
public void givenResourceQualifier_WhenSetter_ThenValidDependencies() {
|
||||
assertNotNull(arbDependency);
|
||||
assertEquals("namedFile.txt", arbDependency.getName());
|
||||
assertNotNull(anotherArbDependency);
|
||||
assertEquals("defaultFile.txt", anotherArbDependency.getName());
|
||||
}
|
||||
|
||||
@Resource
|
||||
@Qualifier("namedFile")
|
||||
public void setArbDependency(File arbDependency) {
|
||||
this.arbDependency = arbDependency;
|
||||
}
|
||||
@Resource
|
||||
@Qualifier("namedFile")
|
||||
public void setArbDependency(File arbDependency) {
|
||||
this.arbDependency = arbDependency;
|
||||
}
|
||||
|
||||
@Resource
|
||||
@Qualifier("defaultFile")
|
||||
public void setAnotherArbDependency(File anotherArbDependency) {
|
||||
this.anotherArbDependency = anotherArbDependency;
|
||||
}
|
||||
@Resource
|
||||
@Qualifier("defaultFile")
|
||||
public void setAnotherArbDependency(File anotherArbDependency) {
|
||||
this.anotherArbDependency = anotherArbDependency;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-11
@@ -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());
|
||||
}
|
||||
|
||||
+10
-12
@@ -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
|
||||
|
||||
+11
-12
@@ -1,11 +1,6 @@
|
||||
package com.baeldung.resource;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.baeldung.configuration.ApplicationContextTestResourceQualifier;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -13,30 +8,34 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import com.baeldung.configuration.ApplicationContextTestResourceQualifier;
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(
|
||||
loader=AnnotationConfigContextLoader.class,
|
||||
classes=ApplicationContextTestResourceQualifier.class)
|
||||
loader = AnnotationConfigContextLoader.class,
|
||||
classes = ApplicationContextTestResourceQualifier.class)
|
||||
public class QualifierResourceInjectionTest {
|
||||
|
||||
@Resource
|
||||
@Qualifier("defaultFile")
|
||||
private File dependency1;
|
||||
|
||||
|
||||
@Resource
|
||||
@Qualifier("namedFile")
|
||||
private File dependency2;
|
||||
|
||||
@Test
|
||||
public void givenResourceAnnotation_WhenField_ThenDependency1Valid(){
|
||||
public void givenResourceAnnotation_WhenField_ThenDependency1Valid() {
|
||||
assertNotNull(dependency1);
|
||||
assertEquals("defaultFile.txt", dependency1.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenResourceQualifier_WhenField_ThenDependency2Valid(){
|
||||
public void givenResourceQualifier_WhenField_ThenDependency2Valid() {
|
||||
assertNotNull(dependency2);
|
||||
assertEquals("namedFile.txt", dependency2.getName());
|
||||
}
|
||||
|
||||
+8
-10
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user