33 lines
1.1 KiB
Java
33 lines
1.1 KiB
Java
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 FieldByNameInjectTest {
|
|
|
|
@Inject
|
|
@Named("yetAnotherFieldInjectDependency")
|
|
private ArbitraryDependency yetAnotherFieldInjectDependency;
|
|
|
|
@Test
|
|
public void givenInjectQualifier_WhenSetOnField_ThenDependencyValid() {
|
|
assertNotNull(yetAnotherFieldInjectDependency);
|
|
assertEquals("Yet Another Arbitrary Dependency", yetAnotherFieldInjectDependency.toString());
|
|
}
|
|
}
|