public ExecutionFailure assertHasNoCause() { if (failure instanceof LocationAwareException) { LocationAwareException exception = (LocationAwareException) failure; assertThat(exception.getReportableCauses(), isEmpty()); } else { assertThat(failure.getCause(), nullValue()); } outputFailure.assertHasNoCause(); return this; }
public ExecutionFailure assertThatCause(final Matcher<String> matcher) { if (failure instanceof LocationAwareException) { LocationAwareException exception = (LocationAwareException) failure; assertThat(exception.getReportableCauses(), hasItem(hasMessage(matcher))); } else { assertThat(failure.getCause(), notNullValue()); assertThat(failure.getCause().getMessage(), matcher); } return this; }
@Test public void wrapsOnlyIfPredicateFailure() { final Throwable failure = new RuntimeException(); final Collector<Throwable> wrappedFailure = collector(); context.checking( new Expectations() { { allowing(task).getEnabled(); will(returnValue(true)); one(spec).isSatisfiedBy(task); will(throwException(failure)); one(state).executed(with(notNullValue(GradleException.class))); will(collectTo(wrappedFailure)); } }); executer.execute(task, state, executionContext); GradleException exception = (GradleException) wrappedFailure.get(); assertThat(exception.getMessage(), equalTo("Could not evaluate onlyIf predicate for <task>.")); assertThat(exception.getCause(), sameInstance(failure)); }