/** * Class constructor specifying the evaluator to use and the id of the button we want to test. * The constructor checks if the given id does correspond to a button. * * @param evaluator a technology specific evaluator * @param id the id (unique) of the button */ public Button(Evaluator evaluator, String id) { super(evaluator, id); checkIsExpectedComponent(Button); }
private Button getResetButton(Form form) { return new Button(this, $("#" + form.id() + " :reset").id(this)); }
@Test public void test_toString() { Button button = new Button(evaluator, id); when(evaluator.isVisible(button)).thenReturn(true); when(evaluator.isEnabled(button)).thenReturn(true); when(evaluator.icon(button)).thenReturn("http://localhost/enter.gif"); when(evaluator.text(button)).thenReturn("ButtonText"); assertThat(button.toString(), is("class org.testatoo.core.component.Button with state : enabled:true, visible:true, text:ButtonText, icon:http://localhost/enter.gif")); } }
/** * Uses the matcher SelectedValue to compare the text on a button to the expected text of the matcher, * using the syntax "text("xxx")" * * @param button the button * @return True if the text on the button is equal to the text of the matcher Text */ @Override public boolean matchesSafely(Button button) { return button.text().equals(text); }
public static Button button() { Evaluator evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.componentType(id)).thenReturn(Button); when(evaluator.isVisible(any(Component.class))).thenReturn(true); when(evaluator.isEnabled(any(Component.class))).thenReturn(true); when(evaluator.icon(any(Button.class))).thenReturn(""); when(evaluator.text(any(Button.class))).thenReturn("buttonText"); return new Button(evaluator, id); }
@Test public void test_component_type() { evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.componentType(id)).thenReturn(Radio); try { new Button(evaluator, id); fail(); } catch (ComponentException e) { assertThat(e.getMessage(), is("The component with id=" + id + " is not a Button but a Radio")); } }