2016-06-01 06:47:26 -06:00
|
|
|
package com.baeldung.inject;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
|
|
|
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;
|
2016-06-01 06:47:26 -06:00
|
|
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
2016-06-01 06:47:26 -06:00
|
|
|
|
2016-06-01 06:47:26 -06:00
|
|
|
import com.baeldung.configuration.ApplicationContextTestInjectQualifier;
|
2016-06-01 06:47:26 -06:00
|
|
|
import com.baeldung.dependency.ArbitraryDependency;
|
|
|
|
|
|
|
|
@RunWith(SpringJUnit4ClassRunner.class)
|
2016-06-01 06:47:26 -06:00
|
|
|
@ContextConfiguration(loader=AnnotationConfigContextLoader.class,
|
|
|
|
classes=ApplicationContextTestInjectQualifier.class)
|
|
|
|
public class FieldQualifierInjectTest {
|
2016-06-01 06:47:26 -06:00
|
|
|
|
|
|
|
@Inject
|
|
|
|
@Qualifier("defaultFile")
|
|
|
|
private ArbitraryDependency defaultDependency;
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
@Qualifier("namedFile")
|
|
|
|
private ArbitraryDependency namedDependency;
|
|
|
|
|
|
|
|
@Test
|
2016-06-01 06:47:26 -06:00
|
|
|
public void givenInjectQualifier_WhenOnField_ThenDefaultFileValid(){
|
2016-06-01 06:47:26 -06:00
|
|
|
assertNotNull(defaultDependency);
|
2016-06-01 06:47:26 -06:00
|
|
|
assertEquals("Arbitrary Dependency",
|
|
|
|
defaultDependency.toString());
|
2016-06-01 06:47:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2016-06-01 06:47:26 -06:00
|
|
|
public void givenInjectQualifier_WhenOnField_ThenNamedFileValid(){
|
2016-06-01 06:47:26 -06:00
|
|
|
assertNotNull(defaultDependency);
|
2016-06-01 06:47:26 -06:00
|
|
|
assertEquals("Another Arbitrary Dependency",
|
|
|
|
namedDependency.toString());
|
2016-06-01 06:47:26 -06:00
|
|
|
}
|
|
|
|
}
|