/** * Adds a failure to the table if {@code matcher} does not match {@code value}. * Execution continues, but the test will fail at the end if the match fails. */ public <T> void checkThat(final T value, final Matcher<T> matcher) { checkThat("", value, matcher); }
/** * Adds to the table the exception, if any, thrown from {@code callable}. * Execution continues, but the test will fail at the end if * {@code callable} threw an exception. */ public Object checkSucceeds(Callable<Object> callable) { try { return callable.call(); } catch (Throwable e) { addError(e); return null; } } }
/** * Adds a failure with the given {@code reason} * to the table if {@code matcher} does not match {@code value}. * Execution continues, but the test will fail at the end if the match fails. */ public <T> void checkThat(final String reason, final T value, final Matcher<T> matcher) { checkSucceeds(new Callable<Object>() { public Object call() throws Exception { assertThat(reason, value, matcher); return value; } }); }
@Test public void default_instance() { Set<Class<? extends Templates>> templates = querydsl.getSubTypesOf(Templates.class); Set<Class<? extends Templates>> moduleSpecific = getAll(templates, MODULE_SPECIFIC); for (Class<? extends Templates> template : moduleSpecific) { try { Templates defaultInstance = (Templates) template.getField("DEFAULT").get(null); errorCollector.checkThat(defaultInstance, instanceOf(template)); } catch (Exception ex) { errorCollector.addError(ex); } } }
@Override public void verify() throws Throwable { super.verify(); } }
final Matcher<Iterable<? super TypeReference>> matcher1 = anyOf(isJLNPE, isJLAIOOBE); collector.checkThat("Edge deleted but cause instruction can't throw NullPointerException" + "nor ArrayIndexOutOfBoundsException: " + identifyer + ":" + method.getLineNumber(lastInstruction.iindex), lastInstruction.getExceptionTypes(), matcher1); equalTo(TypeReference.JavaLangArrayIndexOutOfBoundsException))); collector.checkThat("Edge deleted but cause instruction throws other exceptions as NullPointerException" + "and ArrayIndexOutOfBoundsException: " + identifyer + ":" + method.getLineNumber(lastInstruction.iindex), lastInstruction.getExceptionTypes(), matcher2); collector.addError(new Throwable("Exceptional edge deleted, but no instruction as cause. - No last instruction."));
@Override protected void verify() { try { super.verify(); } catch (Error | RuntimeException e) { throw e; } catch (Throwable t) { throw new RuntimeException(t); } }
/** * Adds a failure to the table if {@code matcher} does not match {@code value}. * Execution continues, but the test will fail at the end if the match fails. * * @deprecated use {@code org.hamcrest.junit.ErrorCollector.checkThat()} */ @Deprecated public <T> void checkThat(final T value, final Matcher<T> matcher) { checkThat("", value, matcher); }
/** * Adds to the table the exception, if any, thrown from {@code callable}. * Execution continues, but the test will fail at the end if * {@code callable} threw an exception. */ public <T> T checkSucceeds(Callable<T> callable) { try { return callable.call(); } catch (AssumptionViolatedException e) { AssertionError error = new AssertionError("Callable threw AssumptionViolatedException"); error.initCause(e); addError(error); return null; } catch (Throwable e) { addError(e); return null; } }
/** * Adds a failure with the given {@code reason} * to the table if {@code matcher} does not match {@code value}. * Execution continues, but the test will fail at the end if the match fails. * * @deprecated use {@code org.hamcrest.junit.ErrorCollector.checkThat()} */ @Deprecated public <T> void checkThat(final String reason, final T value, final Matcher<T> matcher) { checkSucceeds(new Callable<Object>() { public Object call() throws Exception { assertThat(reason, value, matcher); return value; } }); }
@Override // CHECKSTYLE:OFF public void verify() throws Throwable { // CHECKSTYLE:ON super.verify(); }
@Test public void isThreadAlertingIsTrueWhileExecuting() { execute(() -> errorCollector.checkThat(isThreadAlerting(), is(true))); }
/** * Adds a failure to the table if {@code runnable} does not throw an * exception of type {@code expectedThrowable} when executed. * Execution continues, but the test will fail at the end if the runnable * does not throw an exception, or if it throws a different exception. * * @param expectedThrowable the expected type of the exception * @param runnable a function that is expected to throw an exception when executed * @since 4.13 */ public void checkThrows(Class<? extends Throwable> expectedThrowable, ThrowingRunnable runnable) { try { assertThrows(expectedThrowable, runnable); } catch (AssertionError e) { addError(e); } }
/** * Adds a failure with the given {@code reason} * to the table if {@code matcher} does not match {@code value}. * Execution continues, but the test will fail at the end if the match fails. */ public <T> void checkThat(final String reason, final T value, final Matcher<T> matcher) { checkSucceeds(new Callable<Object>() { public Object call() throws Exception { assertThat(reason, value, matcher); return value; } }); }
@Override public void verify() throws Throwable { super.verify(); }
/** * Adds a failure to the table if {@code matcher} does not match {@code value}. * Execution continues, but the test will fail at the end if the match fails. */ public <T> void checkThat(final T value, final Matcher<T> matcher) { checkThat("", value, matcher); }
/** * Adds to the table the exception, if any, thrown from {@code callable}. * Execution continues, but the test will fail at the end if * {@code callable} threw an exception. */ public Object checkSucceeds(Callable<Object> callable) { try { return callable.call(); } catch (Throwable e) { addError(e); return null; } } }
/** * Adds a failure with the given {@code reason} * to the table if {@code matcher} does not match {@code value}. * Execution continues, but the test will fail at the end if the match fails. */ public <T> void checkThat(final String reason, final T value, final Matcher<T> matcher) { checkSucceeds(new Callable<Object>() { public Object call() throws Exception { assertThat(reason, value, matcher); return value; } }); }
@Override public void verify() throws Throwable { MultipleFailureException.assertEmpty(errors); super.verify(); }
/** * Adds a failure to the table if {@code matcher} does not match {@code value}. * Execution continues, but the test will fail at the end if the match fails. */ public <T> void checkThat(final T value, final Matcher<T> matcher) { checkThat("", value, matcher); }