@Override public String toString() { return toJson().toString(); } }
public void assertValid(T value) { ValidationBean validationBean = this.validate(value); if (!validationBean.isValid()) { throw new RuntimeException(errorMessage); } }
/** * @deprecated This method is obsolete */ public Map<String, Object> toJson() { Map<String, Object> jsonMap = new LinkedHashMap<>(); jsonMap.put("isValid", valueOf(isValid)); jsonMap.put(ERROR_FOR_JSON, getError()); return jsonMap; }
public ValidationBean handleException(Exception e, String gitVersionConsoleOut) { ValidationBean defaultResponse = ValidationBean.notValid(e.getMessage()); try { if (!isVersionOnedotSixOrHigher(gitVersionConsoleOut)) { return ValidationBean.notValid(ERR_GIT_OLD_VERSION + gitVersionConsoleOut); } else { return defaultResponse; } } catch (Exception ex) { return defaultResponse; } }
@Override public ValidationBean checkConnection(GitMaterial material, SubprocessExecutionContext executionContext) { return ValidationBean.valid(); } }
public static ValidationBean valid() { return new ValidationBean(true, ""); }
/** * This is a straight test of what is already there. * We are NOT sure that this is the correct behaviour. * We think it was there for SVNKIT and can now be removed. */ @Test public void shouldStripOutExceptionText() { assertThat( ValidationBean.notValid(new Exception("SVNKITException: The actual message")).getError(), is("The actual message") ); }
@Test public void shouldExplainThatEmailAddressIsInvalid() throws Exception { assertThat(validate("invalid").getError(), containsString(EmailValidator.EMAIL_ERROR_MESSAGE)); }
private ValidationBean execute(Runnable action) { Thread thread = new Thread(action); thread.start(); try { thread.join(timeout); if (thread.isAlive()) { thread.interrupt(); return ValidationBean.notValid(ERROR_MESSAGE); } return validation; } catch (InterruptedException e) { LOGGER.error("Timed out when sending an email. Please check email configuration."); return ValidationBean.notValid(ERROR_MESSAGE); } }
@Test public void shouldCheckConnection() { TestSubprocessExecutionContext execCtx = new TestSubprocessExecutionContext(); TfsCommand tfsCommand = mock(TfsCommand.class); doNothing().when(tfsCommand).checkConnection(); TfsMaterial spy = spy(tfsMaterialFirstCollectionFirstProject); doReturn(tfsCommand).when(spy).tfs(execCtx); assertThat(spy.checkConnection(execCtx), is(valid())); verify(tfsCommand, times(1)).checkConnection(); }
public static ValidationBean notValid(String message) { return new ValidationBean(false, message); }