01: package org.junit.experimental.test.theories;
02:
03: import static org.junit.matchers.StringContains.containsString;
04: import static org.hamcrest.CoreMatchers.is;
05: import static org.hamcrest.CoreMatchers.not;
06: import static org.junit.Assert.assertThat;
07: import static org.junit.Assume.assumeThat;
08: import org.junit.experimental.theories.Theories;
09: import org.junit.experimental.theories.Theory;
10: import org.junit.experimental.theories.internal.ParameterizedAssertionError;
11: import org.junit.runner.RunWith;
12:
13: @RunWith(Theories.class)
14: public class ParameterizedAssertionErrorTest {
15: public static final String METHOD_NAME = "methodName";
16:
17: public static final NullPointerException NULL_POINTER_EXCEPTION = new NullPointerException();
18:
19: public static Object[] NO_OBJECTS = new Object[0];
20:
21: public static ParameterizedAssertionError A = new ParameterizedAssertionError(
22: NULL_POINTER_EXCEPTION, METHOD_NAME);
23:
24: public static ParameterizedAssertionError B = new ParameterizedAssertionError(
25: NULL_POINTER_EXCEPTION, METHOD_NAME);
26:
27: public static ParameterizedAssertionError B2 = new ParameterizedAssertionError(
28: NULL_POINTER_EXCEPTION, "methodName2");
29:
30: @Theory
31: public void equalParameterizedAssertionErrorsHaveSameToString(
32: ParameterizedAssertionError a, ParameterizedAssertionError b) {
33: assumeThat(a, is(b));
34: assertThat(a.toString(), is(b.toString()));
35: }
36:
37: @Theory
38: public void differentParameterizedAssertionErrorsHaveDifferentToStrings(
39: ParameterizedAssertionError a, ParameterizedAssertionError b) {
40: assumeThat(a, not(b));
41: assertThat(a.toString(), not(b.toString()));
42: }
43:
44: @Theory
45: public void equalsReturnsTrue(Throwable targetException,
46: String methodName, Object[] params) {
47: assertThat(new ParameterizedAssertionError(targetException,
48: methodName, params),
49: is(new ParameterizedAssertionError(targetException,
50: methodName, params)));
51: }
52:
53: @SuppressWarnings("unchecked")
54: @Theory(nullsAccepted=false)
55: public void buildParameterizedAssertionError(String methodName,
56: String param) {
57: assertThat(new ParameterizedAssertionError(
58: new RuntimeException(), methodName, param).toString(),
59: containsString(methodName));
60: }
61: }
|