use of org.junit.runner.notification.Failure in project lucene-solr by apache.
the class WithNestedTests method assertFailureCount.
protected void assertFailureCount(int expected, Result result) {
if (result.getFailureCount() != expected) {
StringBuilder b = new StringBuilder();
for (Failure f : result.getFailures()) {
b.append("\n\n");
b.append(f.getMessage());
b.append("\n");
b.append(f.getTrace());
}
Assert.assertFalse("Expected failures: " + expected + " but was " + result.getFailureCount() + ", failures below: " + b.toString(), true);
}
}
use of org.junit.runner.notification.Failure in project lucene-solr by apache.
the class TestExceptionInBeforeClassHooks method testExceptionWithinTestFailsTheTest.
@Test
public void testExceptionWithinTestFailsTheTest() {
Result runClasses = JUnitCore.runClasses(Nested2.class);
assertFailureCount(3, runClasses);
Assert.assertEquals(3, runClasses.getRunCount());
ArrayList<String> foobars = new ArrayList<>();
for (Failure f : runClasses.getFailures()) {
Matcher m = Pattern.compile("foobar[0-9]+").matcher(f.getTrace());
while (m.find()) {
foobars.add(m.group());
}
}
Collections.sort(foobars);
Assert.assertEquals("[foobar1, foobar2, foobar3]", Arrays.toString(foobars.toArray()));
}
use of org.junit.runner.notification.Failure in project geode by apache.
the class ExpectedTimeoutRuleTest method failsWithExpectedTimeoutButWrongError.
@Test
public void failsWithExpectedTimeoutButWrongError() {
Result result = TestRunner.runTest(FailsWithExpectedTimeoutButWrongError.class);
assertThat(result.wasSuccessful()).isFalse();
List<Failure> failures = result.getFailures();
assertThat(failures.size()).as("Failures: " + failures).isEqualTo(1);
Failure failure = failures.get(0);
String expectedMessage = "\n" + "Expected: (an instance of java.util.concurrent.TimeoutException and exception with message a string containing \"this is a message for FailsWithExpectedTimeoutButWrongError\")" + "\n" + " " + "but: an instance of java.util.concurrent.TimeoutException <java.lang.NullPointerException> is a java.lang.NullPointerException";
assertThat(failure.getException()).isExactlyInstanceOf(AssertionError.class).hasMessageContaining(expectedMessage);
}
use of org.junit.runner.notification.Failure in project geode by apache.
the class RetryRuleLocalWithErrorTest method failsOnThirdAttempt.
@Test
public void failsOnThirdAttempt() {
Result result = TestRunner.runTest(FailsOnThirdAttempt.class);
assertThat(result.wasSuccessful()).isFalse();
List<Failure> failures = result.getFailures();
assertThat(failures.size()).as("Failures: " + failures).isEqualTo(1);
Failure failure = failures.get(0);
assertThat(failure.getException()).isExactlyInstanceOf(AssertionError.class).hasMessage(FailsOnThirdAttempt.message);
assertThat(FailsOnThirdAttempt.count).isEqualTo(3);
}
use of org.junit.runner.notification.Failure in project geode by apache.
the class RetryRuleLocalWithExceptionTest method failsUnused.
@Test
public void failsUnused() {
Result result = TestRunner.runTest(FailsUnused.class);
assertThat(result.wasSuccessful()).isFalse();
List<Failure> failures = result.getFailures();
assertThat(failures.size()).as("Failures: " + failures).isEqualTo(1);
Failure failure = failures.get(0);
assertThat(failure.getException()).isExactlyInstanceOf(CustomException.class).hasMessage(FailsUnused.message);
assertThat(FailsUnused.count).isEqualTo(1);
}
Aggregations