Search in sources :

Example 1 with InputValidator

use of org.eclipse.che.ide.api.dialogs.InputValidator in project che by eclipse.

the class SshKeyManagerPresenterTest method shouldReturnNullOnHostNameWithSeveralDotsAndDashesValidation.

@Test
public void shouldReturnNullOnHostNameWithSeveralDotsAndDashesValidation() throws OperationException {
    String validHostname = "ho-st.na-me.com";
    Violation violation = ((InputValidator) presenter.hostNameValidator).validate(validHostname);
    assertNull(violation);
}
Also used : Violation(org.eclipse.che.ide.api.dialogs.InputValidator.Violation) InputValidator(org.eclipse.che.ide.api.dialogs.InputValidator) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 2 with InputValidator

use of org.eclipse.che.ide.api.dialogs.InputValidator in project che by eclipse.

the class InputDialogPresenterTest method shouldShowErrorHintWhenValueIsIncorrect.

@Test
public void shouldShowErrorHintWhenValueIsIncorrect() throws Exception {
    reset(view);
    when(view.getValue()).thenReturn(INCORRECT_INPUT_VALUE);
    InputValidator inputValidator = mock(InputValidator.class);
    InputValidator.Violation violation = mock(InputValidator.Violation.class);
    when(inputValidator.validate(INCORRECT_INPUT_VALUE)).thenReturn(violation);
    when(violation.getMessage()).thenReturn(ERROR_MESSAGE);
    presenter.withValidator(inputValidator);
    presenter.inputValueChanged();
    verify(view).showErrorHint(anyString());
    verify(view, never()).hideErrorHint();
    verify(view, never()).setValue(anyString());
}
Also used : InputValidator(org.eclipse.che.ide.api.dialogs.InputValidator) Test(org.junit.Test) BaseTest(org.eclipse.che.ide.ui.dialogs.BaseTest)

Example 3 with InputValidator

use of org.eclipse.che.ide.api.dialogs.InputValidator in project che by eclipse.

the class InputDialogPresenterTest method onEnterClickedWhenInputValueIsCorrect.

@Test
public void onEnterClickedWhenInputValueIsCorrect() throws Exception {
    reset(view);
    when(view.getValue()).thenReturn(CORRECT_INPUT_VALUE);
    InputValidator inputValidator = mock(InputValidator.class);
    when(inputValidator.validate(CORRECT_INPUT_VALUE)).thenReturn(null);
    presenter.withValidator(inputValidator);
    presenter.onEnterClicked();
    verify(view, never()).showErrorHint(anyString());
    verify(view).hideErrorHint();
    verify(view).closeDialog();
    verify(inputCallback).accepted(eq(CORRECT_INPUT_VALUE));
}
Also used : InputValidator(org.eclipse.che.ide.api.dialogs.InputValidator) Test(org.junit.Test) BaseTest(org.eclipse.che.ide.ui.dialogs.BaseTest)

Example 4 with InputValidator

use of org.eclipse.che.ide.api.dialogs.InputValidator in project che by eclipse.

the class InputDialogPresenterTest method onEnterClickedWhenInputValueIsIncorrect.

@Test
public void onEnterClickedWhenInputValueIsIncorrect() throws Exception {
    reset(view);
    when(view.getValue()).thenReturn(INCORRECT_INPUT_VALUE);
    InputValidator inputValidator = mock(InputValidator.class);
    InputValidator.Violation violation = mock(InputValidator.Violation.class);
    when(inputValidator.validate(INCORRECT_INPUT_VALUE)).thenReturn(violation);
    when(violation.getMessage()).thenReturn(ERROR_MESSAGE);
    presenter.withValidator(inputValidator);
    presenter.onEnterClicked();
    verify(view).showErrorHint(anyString());
    verify(view, never()).hideErrorHint();
    verify(view, never()).setValue(anyString());
    verify(inputCallback, never()).accepted(anyString());
}
Also used : InputValidator(org.eclipse.che.ide.api.dialogs.InputValidator) Test(org.junit.Test) BaseTest(org.eclipse.che.ide.ui.dialogs.BaseTest)

Example 5 with InputValidator

use of org.eclipse.che.ide.api.dialogs.InputValidator in project che by eclipse.

the class InputDialogPresenterTest method shouldNotShowErrorHintWhenViolationHasCorrectValue.

@Test
public void shouldNotShowErrorHintWhenViolationHasCorrectValue() throws Exception {
    reset(view);
    when(view.getValue()).thenReturn(INCORRECT_INPUT_VALUE);
    InputValidator inputValidator = mock(InputValidator.class);
    InputValidator.Violation violation = mock(InputValidator.Violation.class);
    when(inputValidator.validate(INCORRECT_INPUT_VALUE)).thenReturn(violation);
    when(violation.getMessage()).thenReturn(null);
    when(violation.getCorrectedValue()).thenReturn(CORRECT_INPUT_VALUE);
    presenter.withValidator(inputValidator);
    presenter.inputValueChanged();
    verify(view, never()).showErrorHint(anyString());
    verify(view).hideErrorHint();
    verify(view).setValue(eq(CORRECT_INPUT_VALUE));
}
Also used : InputValidator(org.eclipse.che.ide.api.dialogs.InputValidator) Test(org.junit.Test) BaseTest(org.eclipse.che.ide.ui.dialogs.BaseTest)

Aggregations

InputValidator (org.eclipse.che.ide.api.dialogs.InputValidator)8 Test (org.junit.Test)7 BaseTest (org.eclipse.che.ide.ui.dialogs.BaseTest)4 Violation (org.eclipse.che.ide.api.dialogs.InputValidator.Violation)3 Matchers.anyString (org.mockito.Matchers.anyString)3 OperationException (org.eclipse.che.api.promises.client.OperationException)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 InputCallback (org.eclipse.che.ide.api.dialogs.InputCallback)1 InputDialog (org.eclipse.che.ide.api.dialogs.InputDialog)1 Resource (org.eclipse.che.ide.api.resources.Resource)1 Path (org.eclipse.che.ide.resource.Path)1