@Test void assumeUiApiReturnsImplementationOfInterface() { Configuration config = mock(Configuration.class); CefClient client = mock(CefClient.class); when(client.createBrowser(any(), anyBoolean(), anyBoolean())).thenReturn(mock(CefBrowser.class)); Browser browser = new Browser("-dummy name-", config, client); TestUiApi api = browser.assumeUiApi("foo", TestUiApi.class); assertThat(api).isNotNull(); }
public <T> T assumeUiApi(String apiId, Class<T> api) { InvocationHandler handler = (self, method, args) -> { nativeBrowser.executeJavaScript("window.uiApi."+apiId+"."+method.getName()+"("+collectArgs(args)+");", "", 0); return null; }; return (T) Proxy.newProxyInstance(api.getClassLoader(), new Class[] {api}, handler); }
Browser { public <T> T assumeUiApi(String apiId, Class<T> api) { InvocationHandler handler = (self, method, args) -> { nativeBrowser.executeJavaScript("window.uiApi."+apiId+"."+method.getName()+"("+collectArgs(args)+");", "", 0); return null; }; return (T) Proxy.newProxyInstance(api.getClassLoader(), new Class[] {api}, handler); } }
Browser { public <T> T assumeUiApi(String apiId, Class<T> api) { InvocationHandler handler = (self, method, args) -> { nativeBrowser.executeJavaScript("window.uiApi."+apiId+"."+method.getName()+"("+collectArgs(args)+");", "", 0); return null; }; return (T) Proxy.newProxyInstance(api.getClassLoader(), new Class[] {api}, handler); } Browser(String name, Configuration config, CefClient client); }
Browser { public <T> T assumeUiApi(String apiId, Class<T> api) { InvocationHandler handler = (self, method, args) -> { nativeBrowser.executeJavaScript("window.uiApi."+apiId+"."+method.getName()+"("+collectArgs(args)+");", "", 0); return null; }; return (T) Proxy.newProxyInstance(api.getClassLoader(), new Class[] {api}, handler); } Browser(String name, Configuration config, CefClient client); Component getBrowserUi(); T assumeUiApi(String apiId, Class<T> api); void close(Runnable onAfterClose); CefBrowser getNativeBrowser(); @Override String toString(); void addCreatedHandler(Consumer<Browser> createdHandler); String getName(); void addClosedHandler(Consumer<Browser> browserClosed); }
Browser { public <T> T assumeUiApi(String apiId, Class<T> api) { InvocationHandler handler = (self, method, args) -> { nativeBrowser.executeJavaScript("window.uiApi."+apiId+"."+method.getName()+"("+collectArgs(args)+");", "", 0); return null; }; return (T) Proxy.newProxyInstance(api.getClassLoader(), new Class[] {api}, handler); } Browser(String name, Configuration config, CefClient client); Component getBrowserUi(); T assumeUiApi(String apiId, Class<T> api); void close(Runnable onAfterClose); CefBrowser getNativeBrowser(); @Override String toString(); void addCreatedHandler(Consumer<Browser> createdHandler); String getName(); void addClosedHandler(Consumer<Browser> browserClosed);  }