PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/src/test/java/declean/guice/inject/SeagullTest.java

https://gitlab.com/Teclan/declan-guice
Java | 68 lines | 52 code | 16 blank | 0 comment | 0 complexity | 64e0c9477f55578dc94eeda4a3bd8fdc MD5 | raw file
  1. package declean.guice.inject;
  2. import static org.junit.Assert.assertTrue;
  3. import org.junit.Test;
  4. import com.google.inject.Guice;
  5. import com.google.inject.Injector;
  6. import declean.guice.Module.DefaultFlyModule;
  7. import declean.guice.Module.DefaultFlyServiceModuleWithProvider;
  8. import declean.guice.Module.TestFlyModule;
  9. import declean.guice.Module.TestFlyServiceModuleWithProvider;
  10. import declean.guice.model.Seagull;
  11. import declean.guice.service.spi.DefaultFlyService;
  12. import declean.guice.service.spi.TestFlyService;
  13. public class SeagullTest {
  14. @Test
  15. public void defaultFlyTest() {
  16. Injector injector = Guice.createInjector(new DefaultFlyModule());
  17. Seagull seagull = injector.getInstance(Seagull.class);
  18. System.out.print("defaultFlyTest:");
  19. seagull.fly();
  20. assertTrue(DefaultFlyService.class
  21. .equals(seagull.getFlyService().getClass()));
  22. }
  23. @Test
  24. public void testFlyTest() {
  25. Injector injector = Guice.createInjector(new TestFlyModule());
  26. Seagull seagull = injector.getInstance(Seagull.class);
  27. System.out.print("testFlyTest:");
  28. seagull.fly();
  29. assertTrue(TestFlyService.class
  30. .equals(seagull.getFlyService().getClass()));
  31. }
  32. @Test
  33. public void bindDefaultFlyServiceWithProviderTest() {
  34. Injector injector = Guice
  35. .createInjector(new DefaultFlyServiceModuleWithProvider());
  36. Seagull seagull = injector.getInstance(Seagull.class);
  37. System.out.print("bindDefaultFlyServiceWithProviderTest:");
  38. seagull.fly();
  39. assertTrue(DefaultFlyService.class
  40. .equals(seagull.getFlyService().getClass()));
  41. }
  42. @Test
  43. public void bindTestFlyServiceWithProviderTest() {
  44. Injector injector = Guice
  45. .createInjector(new TestFlyServiceModuleWithProvider());
  46. Seagull seagull = injector.getInstance(Seagull.class);
  47. System.out.print("bindTestFlyServiceWithProviderTest:");
  48. seagull.fly();
  49. assertTrue(TestFlyService.class
  50. .equals(seagull.getFlyService().getClass()));
  51. }
  52. }