Code and related files for the dependency injection demos.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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 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;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(
|
||||
loader=AnnotationConfigContextLoader.class,
|
||||
classes=ApplicationContextTestInjectName.class)
|
||||
public class FieldByNameInjectTest {
|
||||
|
||||
@Inject
|
||||
@Named("yetAnotherFieldInjectDependency")
|
||||
private ArbitraryDependency yetAnotherFieldInjectDependency;
|
||||
|
||||
@Test
|
||||
public void givenInjectQualifier_WhenSetOnField_ThenDependencyValid() {
|
||||
assertNotNull(yetAnotherFieldInjectDependency);
|
||||
assertEquals("Yet Another Arbitrary Dependency",
|
||||
yetAnotherFieldInjectDependency.toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user