BrowserLiveReloadImpl implements BrowserLiveReload { @Override public Backend getBackend() { if (backend != null) { return backend; } for (Map.Entry<Backend, List<String>> entry : IDENTIFIER_CLASSES .entrySet()) { Backend backendCandidate = entry.getKey(); boolean found = true; for (String clazz : entry.getValue()) { try { classLoader.loadClass(clazz); } catch (ClassNotFoundException e) { getLogger().debug("Class {} not found, excluding {}", clazz, backendCandidate); found = false; break; } } if (found) { backend = backendCandidate; break; } } return backend; } BrowserLiveReloadImpl();   BrowserLiveReloadImpl(ClassLoader classLoader); @Override Backend getBackend(); @Override void setBackend(Backend backend); @Override void onConnect(AtmosphereResource resource); @Override void onDisconnect(AtmosphereResource resource); @Override boolean isLiveReload(AtmosphereResource resource); @Override void reload();  }
@Test public void getBackend_JRebelInitializerClassLoaded_returnsJREBEL() { class JRebelInitializer { } BrowserLiveReloadImpl reload = new BrowserLiveReloadImpl( new ClassLoader(getClass().getClassLoader()) { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { switch (name) { case "com.vaadin.flow.server.jrebel.JRebelInitializer": return JRebelInitializer.class; default: throw new ClassNotFoundException(); } } }); Assert.assertEquals(BrowserLiveReload.Backend.JREBEL, reload.getBackend()); }
@Test public void getBackend_HotSwapVaadinIntegrationClassLoaded_returnsHOTSWAP_AGENT() { class VaadinIntegration { } BrowserLiveReloadImpl reload = new BrowserLiveReloadImpl( new ClassLoader(getClass().getClassLoader()) { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { switch (name) { case "org.hotswap.agent.plugin.vaadin.VaadinIntegration": return VaadinIntegration.class; default: throw new ClassNotFoundException(); } } }); Assert.assertEquals(BrowserLiveReload.Backend.HOTSWAP_AGENT, reload.getBackend()); }
@Test public void getBackend_SpringBootDevtoolsClassesLoaded_returnsSPRING_BOOT_DEVTOOLS() { class SpringServlet { } class LiveReloadServer { } BrowserLiveReloadImpl reload = new BrowserLiveReloadImpl( new ClassLoader(getClass().getClassLoader()) { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { switch (name) { case "com.vaadin.flow.spring.SpringServlet": return SpringServlet.class; case "org.springframework.boot.devtools.livereload.LiveReloadServer": return LiveReloadServer.class; default: throw new ClassNotFoundException(); } } }); Assert.assertEquals(BrowserLiveReload.Backend.SPRING_BOOT_DEVTOOLS, reload.getBackend()); }