This project aims to simplify integrating Netflix Governator in JUnit Tests.
This is how a Governator Junit test would look using this module:
@RunWith(GovernatorJunit4Runner.class)
@LifecycleInjectorParams(modules = SampleModule.class, scannedPackages = "governator.junit.demo")
public class SampleGovernatorRunnerTest {
@Inject
private BlogService blogService;
@Test
public void testExampleBeanInjection() throws Exception {
assertNotNull(blogService.get(1l));
}
}
This is in contrast to the more verbose code that results from using the JUnit @Rule provided by governator’s test support:
public class SampleGovernatorJunitSupportTest {
@Rule
public LifecycleTester tester = new LifecycleTester();
@Test
public void testExampleBeanInjection() throws Exception {
tester.start();
Injector injector = tester
.builder()
.usingBasePackages("sample.gov")
.build()
.createInjector();
BlogService blogService = injector.getInstance(BlogService.class);
assertThat(blogService.get(1l), is(notNullValue()));
}
}
More Samples are in the test folder