01: package org.junit.experimental.test.results;
02:
03: import static java.util.Arrays.asList;
04: import static org.hamcrest.CoreMatchers.allOf;
05: import static org.junit.Assert.assertThat;
06: import static org.junit.matchers.StringContains.containsString;
07:
08: import java.util.Arrays;
09:
10: import org.junit.experimental.results.PrintableResult;
11: import org.junit.experimental.theories.Theories;
12: import org.junit.experimental.theories.Theory;
13: import org.junit.runner.Description;
14: import org.junit.runner.RunWith;
15: import org.junit.runner.notification.Failure;
16:
17: @RunWith(Theories.class)
18: public class PrintableResultTest {
19: @SuppressWarnings("unchecked")
20: @Theory(nullsAccepted=false)
21: public void backTraceHasGoodToString(String descriptionName,
22: final String stackTraceClassName) {
23: Failure failure = new Failure(Description
24: .createSuiteDescription(descriptionName),
25: new Throwable() {
26: private static final long serialVersionUID = 1L;
27:
28: @Override
29: public StackTraceElement[] getStackTrace() {
30: return new StackTraceElement[] { new StackTraceElement(
31: stackTraceClassName, "methodName",
32: "fileName", 1) };
33: }
34: });
35:
36: assertThat(new PrintableResult(asList(failure)).toString(),
37: allOf(containsString(descriptionName),
38: containsString(stackTraceClassName)));
39: }
40:
41: public static String SHELL_POINT = "Shell Point";
42:
43: @Theory
44: public void includeMultipleFailures(String secondExceptionName) {
45: PrintableResult backtrace = new PrintableResult(Arrays.asList(
46: new Failure(Description
47: .createSuiteDescription("firstName"),
48: new RuntimeException("firstException")),
49: new Failure(Description
50: .createSuiteDescription("secondName"),
51: new RuntimeException(secondExceptionName))));
52: assertThat(backtrace.toString(),
53: containsString(secondExceptionName));
54: }
55: }
|