Rename dependency-injection -> spring-core
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.autowired;
|
||||
|
||||
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;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(
|
||||
loader = AnnotationConfigContextLoader.class,
|
||||
classes = ApplicationContextTestAutowiredType.class)
|
||||
public class FieldAutowiredIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ArbitraryDependency fieldDependency;
|
||||
|
||||
@Test
|
||||
public void givenAutowired_WhenSetOnField_ThenDependencyResolved() {
|
||||
assertNotNull(fieldDependency);
|
||||
assertEquals("Arbitrary Dependency", fieldDependency.toString());
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.autowired;
|
||||
|
||||
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;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(
|
||||
loader = AnnotationConfigContextLoader.class,
|
||||
classes = ApplicationContextTestAutowiredName.class)
|
||||
public class FieldAutowiredNameIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ArbitraryDependency autowiredFieldDependency;
|
||||
|
||||
@Test
|
||||
public void givenAutowiredAnnotation_WhenOnField_ThenDependencyValid() {
|
||||
assertNotNull(autowiredFieldDependency);
|
||||
assertEquals("Arbitrary Dependency", autowiredFieldDependency.toString());
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.baeldung.autowired;
|
||||
|
||||
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;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(
|
||||
loader = AnnotationConfigContextLoader.class,
|
||||
classes = ApplicationContextTestAutowiredQualifier.class)
|
||||
public class FieldQualifierAutowiredIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("autowiredFieldDependency")
|
||||
private ArbitraryDependency fieldDependency1;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("anotherAutowiredFieldDependency")
|
||||
private ArbitraryDependency fieldDependency2;
|
||||
|
||||
@Test
|
||||
public void givenAutowiredQualifier_WhenOnField_ThenDep1Valid() {
|
||||
assertNotNull(fieldDependency1);
|
||||
assertEquals("Arbitrary Dependency", fieldDependency1.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAutowiredQualifier_WhenOnField_ThenDep2Valid() {
|
||||
assertNotNull(fieldDependency2);
|
||||
assertEquals("Another Arbitrary Dependency", fieldDependency2.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.inject;
|
||||
|
||||
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 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)
|
||||
public class FieldByNameInjectIntegrationTest {
|
||||
|
||||
@Inject
|
||||
@Named("yetAnotherFieldInjectDependency")
|
||||
private ArbitraryDependency yetAnotherFieldInjectDependency;
|
||||
|
||||
@Test
|
||||
public void givenInjectQualifier_WhenSetOnField_ThenDependencyValid() {
|
||||
assertNotNull(yetAnotherFieldInjectDependency);
|
||||
assertEquals("Yet Another Arbitrary Dependency", yetAnotherFieldInjectDependency.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.baeldung.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 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)
|
||||
public class FieldInjectIntegrationTest {
|
||||
|
||||
@Inject
|
||||
private ArbitraryDependency fieldInjectDependency;
|
||||
|
||||
@Test
|
||||
public void givenInjectAnnotation_WhenOnField_ThenValidDependency() {
|
||||
assertNotNull(fieldInjectDependency);
|
||||
assertEquals("Arbitrary Dependency", fieldInjectDependency.toString());
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.baeldung.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;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
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)
|
||||
public class FieldQualifierInjectIntegrationTest {
|
||||
|
||||
@Inject
|
||||
@Qualifier("defaultFile")
|
||||
private ArbitraryDependency defaultDependency;
|
||||
|
||||
@Inject
|
||||
@Qualifier("namedFile")
|
||||
private ArbitraryDependency namedDependency;
|
||||
|
||||
@Test
|
||||
public void givenInjectQualifier_WhenOnField_ThenDefaultFileValid() {
|
||||
assertNotNull(defaultDependency);
|
||||
assertEquals("Arbitrary Dependency", defaultDependency.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenInjectQualifier_WhenOnField_ThenNamedFileValid() {
|
||||
assertNotNull(defaultDependency);
|
||||
assertEquals("Another Arbitrary Dependency", namedDependency.toString());
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.baeldung.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 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)
|
||||
public class FieldResourceInjectionIntegrationTest {
|
||||
|
||||
@Resource(name = "namedFile")
|
||||
private File defaultFile;
|
||||
|
||||
@Test
|
||||
public void givenResourceAnnotation_WhenOnField_ThenDependencyValid() {
|
||||
assertNotNull(defaultFile);
|
||||
assertEquals("namedFile.txt", defaultFile.getName());
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.baeldung.resource;
|
||||
|
||||
import com.baeldung.configuration.ApplicationContextTestResourceQualifier;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
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)
|
||||
public class MethodByQualifierResourceIntegrationTest {
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
@Resource
|
||||
@Qualifier("namedFile")
|
||||
public void setArbDependency(File arbDependency) {
|
||||
this.arbDependency = arbDependency;
|
||||
}
|
||||
|
||||
@Resource
|
||||
@Qualifier("defaultFile")
|
||||
public void setAnotherArbDependency(File anotherArbDependency) {
|
||||
this.anotherArbDependency = anotherArbDependency;
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.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 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)
|
||||
public class MethodByTypeResourceIntegrationTest {
|
||||
|
||||
private File defaultFile;
|
||||
|
||||
@Resource
|
||||
protected void setDefaultFile(File defaultFile) {
|
||||
this.defaultFile = defaultFile;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenResourceAnnotation_WhenSetter_ThenValidDependency() {
|
||||
assertNotNull(defaultFile);
|
||||
assertEquals("namedFile.txt", defaultFile.getName());
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.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 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)
|
||||
public class MethodResourceInjectionIntegrationTest {
|
||||
|
||||
private File defaultFile;
|
||||
|
||||
@Resource(name = "namedFile")
|
||||
protected void setDefaultFile(File defaultFile) {
|
||||
this.defaultFile = defaultFile;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenResourceAnnotation_WhenSetter_ThenDependencyValid() {
|
||||
assertNotNull(defaultFile);
|
||||
assertEquals("namedFile.txt", defaultFile.getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.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 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)
|
||||
public class NamedResourceIntegrationTest {
|
||||
|
||||
@Resource(name = "namedFile")
|
||||
private File testFile;
|
||||
|
||||
@Test
|
||||
public void givenResourceAnnotation_WhenOnField_THEN_DEPENDENCY_Found() {
|
||||
assertNotNull(testFile);
|
||||
assertEquals("namedFile.txt", testFile.getName());
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.baeldung.resource;
|
||||
|
||||
import com.baeldung.configuration.ApplicationContextTestResourceQualifier;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
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)
|
||||
public class QualifierResourceInjectionIntegrationTest {
|
||||
|
||||
@Resource
|
||||
@Qualifier("defaultFile")
|
||||
private File dependency1;
|
||||
|
||||
@Resource
|
||||
@Qualifier("namedFile")
|
||||
private File dependency2;
|
||||
|
||||
@Test
|
||||
public void givenResourceAnnotation_WhenField_ThenDependency1Valid() {
|
||||
assertNotNull(dependency1);
|
||||
assertEquals("defaultFile.txt", dependency1.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenResourceQualifier_WhenField_ThenDependency2Valid() {
|
||||
assertNotNull(dependency2);
|
||||
assertEquals("namedFile.txt", dependency2.getName());
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.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 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)
|
||||
public class SetterResourceInjectionIntegrationTest {
|
||||
|
||||
private File defaultFile;
|
||||
|
||||
@Resource
|
||||
protected void setDefaultFile(File defaultFile) {
|
||||
this.defaultFile = defaultFile;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenResourceAnnotation_WhenOnSetter_THEN_MUST_INJECT_Dependency() {
|
||||
assertNotNull(defaultFile);
|
||||
assertEquals("namedFile.txt", defaultFile.getName());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user