Bael 1366 dagger2 (#4288)
* BAEL-1366-dagger2: Added Dagger 2 example and test case. Added dependency and Dagger compiler plugin to pom.
This commit is contained in:
committed by
Josh Cummings
parent
98ad136e25
commit
8713e26b6f
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.dagger.intro;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test for building a {@link Car} using Dagger.
|
||||
*
|
||||
* @author Donato Rimenti
|
||||
*
|
||||
*/
|
||||
public class DaggerUnitTest {
|
||||
|
||||
/**
|
||||
* Builds two {@link Car} and checks that the fields are injected correctly.
|
||||
*/
|
||||
@Test
|
||||
public void givenGeneratedComponent_whenBuildingCar_thenDependenciesInjected() {
|
||||
VehiclesComponent component = DaggerVehiclesComponent.create();
|
||||
|
||||
Car carOne = component.buildCar();
|
||||
Car carTwo = component.buildCar();
|
||||
|
||||
Assert.assertNotNull(carOne);
|
||||
Assert.assertNotNull(carTwo);
|
||||
Assert.assertNotNull(carOne.getEngine());
|
||||
Assert.assertNotNull(carTwo.getEngine());
|
||||
Assert.assertNotNull(carOne.getBrand());
|
||||
Assert.assertNotNull(carTwo.getBrand());
|
||||
Assert.assertNotEquals(carOne.getEngine(), carTwo.getEngine());
|
||||
Assert.assertEquals(carOne.getBrand(), carTwo.getBrand());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user