Если вы просто хотите проверить, что Guice впрыскивает ваш AnotherThing
вы можете написать:
Injector injector
@Before {
injector = Guice.createInjector(new AnotherThingModule());
}
@Test
public void testAnotherThingInstantiated() {
//act
AnotherThing another = injector.getInstance(AnotherThing.class);
//assert
assertNotNull(another);
}
Если AnotherThing
является @Singleton
, и вы хотите, чтобы проверить, что Guice не экземпляр дважды вы можете написать :
@Test
public void testSingletonAnotherThingNotInstantiatedTwiceByInjector() {
//act
AnotherThing first = injector.getInstance(AnotherThing.class);
AnotherThing second = injector.getInstance(AnotherThing.class);
//assert
assertSame(first, second);
}