BrowserLiveReloadAccess { public BrowserLiveReload getLiveReload(VaadinService service) { if (service.getDeploymentConfiguration().isProductionMode()) { LoggerFactory.getLogger(BrowserLiveReloadAccess.class) .debug("BrowserLiveReloadAccess::getLiveReload is called in production mode."); return null; } if (!service.getDeploymentConfiguration().isDevModeLiveReloadEnabled()) { LoggerFactory.getLogger(BrowserLiveReloadAccess.class) .debug("BrowserLiveReloadAccess::getLiveReload is called when live reload is disabled."); return null; } VaadinContext context = service.getContext(); BrowserLiveReloadImpl liveReload; synchronized (this) { liveReload = context.getAttribute(BrowserLiveReloadImpl.class); if (liveReload == null) { liveReload = new BrowserLiveReloadImpl(); context.setAttribute(BrowserLiveReloadImpl.class, liveReload); } } return liveReload; }  BrowserLiveReload getLiveReload(VaadinService service);  }
@Test public void getLiveReload_productionMode_nullIsReturned() { VaadinService service = Mockito.mock(VaadinService.class); DeploymentConfiguration config = Mockito .mock(DeploymentConfiguration.class); Mockito.when(service.getDeploymentConfiguration()).thenReturn(config); Mockito.when(config.isProductionMode()).thenReturn(true); Assert.assertNull(access.getLiveReload(service)); }
@Test public void getLiveReload_liveReloadDisabled_nullIsReturned() { VaadinService service = Mockito.mock(VaadinService.class); DeploymentConfiguration config = Mockito .mock(DeploymentConfiguration.class); Mockito.when(service.getDeploymentConfiguration()).thenReturn(config); Mockito.when(config.isProductionMode()).thenReturn(false); Mockito.when(config.isDevModeLiveReloadEnabled()).thenReturn(false); Assert.assertNull(access.getLiveReload(service)); }
@Test public void getLiveReload_devMode_contextHasNoReloadInstance_instanceIsCreated() { VaadinService service = Mockito.mock(VaadinService.class); DeploymentConfiguration config = Mockito .mock(DeploymentConfiguration.class); Mockito.when(service.getDeploymentConfiguration()).thenReturn(config); Mockito.when(config.isProductionMode()).thenReturn(false); Mockito.when(config.isDevModeLiveReloadEnabled()).thenReturn(true); VaadinContext context = Mockito.mock(VaadinContext.class); Mockito.when(service.getContext()).thenReturn(context); Assert.assertNotNull(access.getLiveReload(service)); }
@Test public void getLiveReload_devMode_contextHasReloadInstance_instanceIsReturned() { VaadinService service = Mockito.mock(VaadinService.class); DeploymentConfiguration config = Mockito .mock(DeploymentConfiguration.class); Mockito.when(service.getDeploymentConfiguration()).thenReturn(config); Mockito.when(config.isProductionMode()).thenReturn(false); Mockito.when(config.isDevModeLiveReloadEnabled()).thenReturn(true); VaadinContext context = Mockito.mock(VaadinContext.class); Mockito.when(service.getContext()).thenReturn(context); BrowserLiveReloadImpl reload = Mockito .mock(BrowserLiveReloadImpl.class); Mockito.when(context.getAttribute(BrowserLiveReloadImpl.class)) .thenReturn(reload); Assert.assertSame(reload, access.getLiveReload(service)); }