1 package org.junit.tests.experimental.theories.runner; 2 3 import static org.hamcrest.CoreMatchers.not; 4 import static org.junit.Assert.assertThat; 5 import static org.junit.experimental.results.PrintableResult.testResult; 6 import static org.junit.experimental.results.ResultMatchers.isSuccessful; 7 import org.junit.Test; 8 import org.junit.experimental.theories.DataPoint; 9 import org.junit.experimental.theories.DataPoints; 10 import org.junit.experimental.theories.Theories; 11 import org.junit.experimental.theories.Theory; 12 import org.junit.runner.RunWith; 13 14 public class FailingDataPointMethods { 15 16 @RunWith(Theories.class) 17 public static class HasFailingSingleDataPointMethod { 18 @DataPoint 19 public static int num = 10; 20 21 @DataPoint 22 public static int failingDataPoint() { 23 throw new RuntimeException(); 24 } 25 26 @Theory 27 public void theory(int x) { 28 } 29 } 30 31 @Test 32 public void shouldFailFromExceptionsInSingleDataPointMethods() { 33 assertThat(testResult(HasWronglyIgnoredFailingSingleDataPointMethod.class), not(isSuccessful())); 34 } 35 36 @RunWith(Theories.class) 37 public static class HasFailingDataPointArrayMethod { 38 @DataPoints 39 public static int[] num = { 1, 2, 3 }; 40 41 @DataPoints 42 public static int[] failingDataPoints() { 43 throw new RuntimeException(); 44 } 45 46 @Theory 47 public void theory(int x) { 48 } 49 } 50 51 @Test 52 public void shouldFailFromExceptionsInDataPointArrayMethods() { 53 assertThat(testResult(HasFailingDataPointArrayMethod.class), not(isSuccessful())); 54 } 55 56 @RunWith(Theories.class) 57 public static class HasIgnoredFailingSingleDataPointMethod { 58 @DataPoint 59 public static int num = 10; 60 61 @DataPoint(ignoredExceptions=Throwable.class) 62 public static int failingDataPoint() { 63 throw new RuntimeException(); 64 } 65 66 @Theory 67 public void theory(int x) { 68 } 69 } 70 71 @Test 72 public void shouldIgnoreSingleDataPointMethodExceptionsOnRequest() { 73 assertThat(testResult(HasIgnoredFailingSingleDataPointMethod.class), isSuccessful()); 74 } 75 76 @RunWith(Theories.class) 77 public static class HasIgnoredFailingMultipleDataPointMethod { 78 @DataPoint 79 public static int num = 10; 80 81 @DataPoints(ignoredExceptions=Throwable.class) 82 public static int[] failingDataPoint() { 83 throw new RuntimeException(); 84 } 85 86 @Theory 87 public void theory(int x) { 88 } 89 } 90 91 @Test 92 public void shouldIgnoreMultipleDataPointMethodExceptionsOnRequest() { 93 assertThat(testResult(HasIgnoredFailingMultipleDataPointMethod.class), isSuccessful()); 94 } 95 96 @RunWith(Theories.class) 97 public static class HasWronglyIgnoredFailingSingleDataPointMethod { 98 @DataPoint 99 public static int num = 10; 100 101 @DataPoint(ignoredExceptions=NullPointerException.class) 102 public static int failingDataPoint() { 103 throw new RuntimeException(); 104 } 105 106 @Theory 107 public void theory(int x) { 108 } 109 } 110 111 @Test 112 public void shouldNotIgnoreNonMatchingSingleDataPointExceptions() { 113 assertThat(testResult(HasWronglyIgnoredFailingSingleDataPointMethod.class), not(isSuccessful())); 114 } 115 116 @RunWith(Theories.class) 117 public static class HasWronglyIgnoredFailingMultipleDataPointMethod { 118 @DataPoint 119 public static int num = 10; 120 121 @DataPoint(ignoredExceptions=NullPointerException.class) 122 public static int failingDataPoint() { 123 throw new RuntimeException(); 124 } 125 126 @Theory 127 public void theory(int x) { 128 } 129 } 130 131 @Test 132 public void shouldNotIgnoreNonMatchingMultipleDataPointExceptions() { 133 assertThat(testResult(HasWronglyIgnoredFailingMultipleDataPointMethod.class), not(isSuccessful())); 134 } 135 136 }