|
| 1 | +package com.baeldung.injectiontypes; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | + |
| 5 | +import org.junit.Test; |
| 6 | +import org.junit.runner.RunWith; |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; |
| 8 | +import org.springframework.test.context.ContextConfiguration; |
| 9 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 10 | +import org.springframework.test.context.support.AnnotationConfigContextLoader; |
| 11 | + |
| 12 | +import com.baelding.injectiontypes.BeanDefinition; |
| 13 | +import com.baelding.injectiontypes.ConstructorInjection; |
| 14 | +import com.baelding.injectiontypes.FieldInjection; |
| 15 | +import com.baelding.injectiontypes.SetterInjection; |
| 16 | + |
| 17 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 18 | +@ContextConfiguration( |
| 19 | + loader = AnnotationConfigContextLoader.class, |
| 20 | + classes = {BeanDefinition.class, ConstructorInjection.class, SetterInjection.class, FieldInjection.class}) |
| 21 | +public class TypesOfInjectionTest { |
| 22 | + |
| 23 | + @Autowired |
| 24 | + private ConstructorInjection constructorInjection; |
| 25 | + |
| 26 | + @Autowired |
| 27 | + private FieldInjection fieldInjection; |
| 28 | + |
| 29 | + @Autowired |
| 30 | + private SetterInjection setterInjection; |
| 31 | + |
| 32 | + @Test |
| 33 | + public void givenWiredDependencies_WhenExecutingGetBean_ThenDependenciesShouldBeAlreadyInjected() { |
| 34 | + assertEquals("Using constructor injection, we got these parameters Hello-Injection",constructorInjection.getParameters()); |
| 35 | + assertEquals("Using field injection, we got these parameters Hello-Injection",fieldInjection.getParameters()); |
| 36 | + assertEquals("Using setter injection, we got these parameters Hello-Injection",setterInjection.getParameters()); |
| 37 | + } |
| 38 | + |
| 39 | +} |
0 commit comments