### Question:
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);  }### Answer:
@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(); }
@Test void callsIntoJavaScriptWhenCallingAnApiMethodWithoutParameters() { Configuration config = mock(Configuration.class); CefClient client = mock(CefClient.class); CefBrowser cefBrowser = mock(CefBrowser.class); when(client.createBrowser(any(), anyBoolean(), anyBoolean())).thenReturn(cefBrowser); Browser browser = new Browser("-dummy name-", config, client); TestUiApi api = browser.assumeUiApi("foo", TestUiApi.class); assumeThat(api).isNotNull(); api.callSimpleJsFunction(); verify(cefBrowser).executeJavaScript("window.uiApi.foo.callSimpleJsFunction();", "", 0); }
@Test void callsIntoJavaScriptWhenCallingAnApiMethodWithParameters() { Configuration config = mock(Configuration.class); CefClient client = mock(CefClient.class); CefBrowser cefBrowser = mock(CefBrowser.class); when(client.createBrowser(any(), anyBoolean(), anyBoolean())).thenReturn(cefBrowser); Browser browser = new Browser("-dummy name-", config, client); TestUiApi api = browser.assumeUiApi("foo", TestUiApi.class); assumeThat(api).isNotNull(); api.callSomeJsFunction("foo", 0, false); verify(cefBrowser).executeJavaScript("window.uiApi.foo.callSomeJsFunction(\"foo\", 0, false);", "", 0); }