@Test public void checkRadioButtonClickTwice() { tested = false; RadioButton r1 = new RadioButton("myRadioGroup", "r1"); RadioButton r2 = new RadioButton("myRadioGroup", "r2"); r1.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { tested = !tested; } }); r2.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { tested = !tested; } }); Assert.assertEquals(false, tested); // simule the event Browser.click(r1); Browser.click(r1); Assert.assertEquals(false, tested); Assert.assertEquals(true, r1.getValue()); }
@Test public void runAsync() { // Arrange Button b = new Button(); b.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { GWT.runAsync( new RunAsyncCallback() { public void onFailure(Throwable reason) { fail("GWT.runAsync() has called \"onFailure\" callback"); } public void onSuccess() { success = true; } }); } }); // Act Browser.click(b); // Assert assertTrue(success); }
@SuppressWarnings("unchecked") @Test public void checkRPCCallSuccess() { // Setup Button button = GwtReflectionUtils.getPrivateFieldValue(composite, "button"); Label label = GwtReflectionUtils.getPrivateFieldValue(composite, "label"); service.createBean(EasyMock.eq("OCTO"), EasyMock.isA(AsyncCallback.class)); FooBean expected = new FooBean(); expected.setName("mocked"); expectServiceAndCallbackOnSuccess(expected); // replay all @Mock objects replay(); Assert.assertEquals("", label.getText()); // Test Browser.click(button); // Assert // verify all @Mock objects verify(); Assert.assertEquals("Bean \"mocked\" has been created", label.getText()); }
@Test public void click() { // Arrange CheckBox cb = new CheckBox(); // Pre-Assert assertFalse(cb.getValue()); // Act 1 Browser.click(cb); // Assert 1 assertTrue(cb.getValue()); assertEquals("", errorStringBuilder.toString()); // Act 2 Browser.click(cb); // Assert 2 assertFalse(cb.getValue()); assertEquals("", errorStringBuilder.toString()); }
@Test public void click_disabled() { // Arrange CheckBox cb = new CheckBox(); cb.setEnabled(false); // Act Browser.click(cb); // Assert assertFalse(cb.getValue()); assertTrue( errorStringBuilder .toString() .startsWith( "Cannot dispatch 'mouseover' event : the targeted element has to be enabled : <span class=\"gwt-CheckBox gwt-CheckBox-disabled\"><input type=\"checkbox\"")); }
@Test public void checkRadioButtonClick() { tested = false; RadioButton r = new RadioButton("myRadioGroup", "foo"); r.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { tested = !tested; } }); Assert.assertEquals(false, tested); // simule the event Browser.click(r); Assert.assertEquals(true, tested); Assert.assertEquals(true, r.getValue()); }
@SuppressWarnings("unchecked") @Test public void checkRPCCallFailure() { // Setup Button button = GwtReflectionUtils.getPrivateFieldValue(composite, "button"); Label label = GwtReflectionUtils.getPrivateFieldValue(composite, "label"); service.createBean(EasyMock.eq("OCTO"), EasyMock.isA(AsyncCallback.class)); expectServiceAndCallbackOnFailure(new Exception("Mocked exception")); // replay all @Mock objects replay(); Assert.assertEquals("", label.getText()); // Test Browser.click(button); // Assert // verify all @Mock objects verify(); Assert.assertEquals("Failure : Mocked exception", label.getText()); }
/** * @param target * @deprecated use {@link Browser#mouseUp(Widget)} instead */ public static void mouseUp(Widget target) { Browser.mouseUp(target); }
/** * @param target * @param keyCode * @deprecated use {@link Browser#keyPress(Widget, int)} instead */ public static void keyPress(Widget target, int keyCode) { Browser.keyPress(target, keyCode); }
/** * @param target * @param keyCode * @deprecated use {@link Browser#keyDown(Widget, int)} instead */ public static void keyDown(Widget target, int keyCode) { Browser.keyDown(target, keyCode); }
/** * @param target * @deprecated use {@link Browser#focus(Widget)} instead */ public static void focus(Widget target) { Browser.focus(target); }
/** * @param target * @deprecated use {@link Browser#mouseOver(Widget)} instead */ public static void mouseOver(Widget target) { Browser.mouseOver(target); }
/** * @param target * @deprecated use {@link Browser#mouseDown(Widget)} instead */ public static void mouseDown(Widget target) { Browser.mouseDown(target); }
/** * @param parent * @param clickedItem * @deprecated use {@link Browser#click(MenuBar, MenuItem)} instead */ public static void click(MenuBar parent, MenuItem clickedItem) { Browser.click(parent, clickedItem); }
/** * @param target * @deprecated use {@link Browser#click(Widget)} instead */ public static void click(Widget target) { Browser.click(target); }
/** * @param target * @deprecated use {@link Browser#change(Widget)} instead */ public static void change(Widget target) { Browser.change(target); }
/** * @param target * @deprecated use {@link Browser#blur(Widget)} instead */ public static void blur(Widget target) { Browser.blur(target); }
/** * @param target * @deprecated use {@link Browser#mouseOut(Widget)} instead */ @Deprecated public static void mouseOut(Widget target) { Browser.mouseOut(target); }
/** * @param panel * @param index * @deprecated use {@link Browser#click(ComplexPanel, int)} instead */ public static void click(ComplexPanel panel, int index) { Browser.click(panel, index); }
/** * @param parent * @param clickedItemIndex * @deprecated use {@link Browser#click(MenuBar, int)} instead */ public static void click(MenuBar parent, int clickedItemIndex) { Browser.click(parent, clickedItemIndex); }
/** * @param target * @deprecated use {@link Browser#mouseWheel(Widget)} instead */ public static void mouseWheel(Widget target) { Browser.mouseWheel(target); }
/** * @param grid * @param row * @param column * @deprecated use {@link Browser#click(Grid, int, int)} instead */ public static void click(Grid grid, int row, int column) { Browser.click(grid, row, column); }
/** * @param target * @deprecated use {@link Browser#mouseMove(Widget)} instead */ public static void mouseMove(Widget target) { Browser.mouseMove(target); }