GovernatorServletContextListener extends GuiceServletContextListener { protected final Injector getInjector() { if (injector != null) { throw new IllegalStateException("Injector already created."); } try { injector = createInjector(); } catch (Exception e) { LOG.error("Failed to created injector", e); throw new ProvisionException("Failed to create injector", e); } return injector; }  void contextInitialized(ServletContextEvent servletContextEvent); void contextDestroyed(ServletContextEvent servletContextEvent);  }
@Test(expected = IllegalStateException.class) public void testGetInjectorIsCreatedOnlyOnce() { Injector injector = listener.getInjector(); Assert.assertNotNull(injector); listener.getInjector(); }