/** * Class constructor specifying the evaluator to use and the id of the passwordField we want to test. * The constructor checks if the given id does correspond to a passwordField. * * @param evaluator a technology specific evaluator * @param id the id (unique) of the passwordField */ public PasswordField(Evaluator evaluator, String id) { super(evaluator, id); checkIsExpectedComponent(PasswordField); } }
@Test public void test_toString() { when(evaluator.value(any(PasswordField.class))).thenReturn("myPassword"); when(evaluator.label(any(PasswordField.class))).thenReturn("label"); when(evaluator.maxLength(any(PasswordField.class))).thenReturn(10); PasswordField passwordField = new PasswordField(evaluator, id); assertThat(passwordField.toString(), is("class org.testatoo.core.component.PasswordField with state : enabled:true, visible:true, value:myPassword, label:label, maxLength:10")); } }
@Test public void can_check_max_length_accepted_by_passwordfield() { when(evaluator.value(any(Field.class))).thenReturn(""); when(evaluator.label(any(PasswordField.class))).thenReturn(""); when(evaluator.maxLength(any(PasswordField.class))).thenReturn(10); PasswordField passwordField = new PasswordField(evaluator, id); assertThat(passwordField.maxLength(), is(10)); }
@Test public void test_component_type() { evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.componentType(id)).thenReturn(Radio); try { new PasswordField(evaluator, id); fail(); } catch (ComponentException e) { assertThat(e.getMessage(), is("The component with id=" + id + " is not a PasswordField but a Radio")); } }