1 package org.junit.tests.experimental.theories.runner;
2
3 import static org.hamcrest.CoreMatchers.containsString;
4 import static org.hamcrest.CoreMatchers.is;
5 import static org.hamcrest.CoreMatchers.not;
6 import static org.junit.Assert.assertThat;
7 import static org.junit.Assume.assumeThat;
8 import static org.junit.experimental.results.PrintableResult.testResult;
9
10 import org.hamcrest.Matcher;
11 import org.junit.experimental.theories.DataPoint;
12 import org.junit.experimental.theories.DataPoints;
13 import org.junit.experimental.theories.Theories;
14 import org.junit.experimental.theories.Theory;
15 import org.junit.runner.RunWith;
16
17 @RunWith(Theories.class)
18 public class WhenNoParametersMatch {
19 @DataPoints
20 public static int[] ints = {0, 1, 3, 5, 1776};
21
22 @DataPoints
23 public static Matcher<?>[] matchers = {not(0), is(1)};
24
25 @RunWith(Theories.class)
26 public static class AssumptionsFail {
27 @DataPoint
28 public static int DATA = 0;
29
30 @DataPoint
31 public static Matcher<Integer> MATCHER = null;
32
33 @Theory
34 public void nonZeroIntsAreFun(int x) {
35 assumeThat(x, MATCHER);
36 }
37 }
38
39 @Theory
40 public void showFailedAssumptionsWhenNoParametersFound(int data,
41 Matcher<Integer> matcher) throws Exception {
42 assumeThat(data, not(matcher));
43 AssumptionsFail.DATA = data;
44 AssumptionsFail.MATCHER = matcher;
45
46 String result = testResult(AssumptionsFail.class).toString();
47
48 assertThat(result, containsString(matcher.toString()));
49 assertThat(result, containsString("" + data));
50 }
51 }