|
1 | 1 | package org.junit.experimental.theories.internal;
|
2 | 2 |
|
3 |
| -import static org.hamcrest.CoreMatchers.not; |
4 |
| -import static org.hamcrest.core.IsInstanceOf.instanceOf; |
5 |
| - |
6 | 3 | import java.lang.reflect.Array;
|
7 | 4 | import java.lang.reflect.Field;
|
8 | 5 | import java.util.ArrayList;
|
@@ -40,23 +37,19 @@ public Object getValue() throws CouldNotGenerateValueException {
|
40 | 37 | } catch (IllegalAccessException e) {
|
41 | 38 | throw new RuntimeException(
|
42 | 39 | "unexpected: getMethods returned an inaccessible method");
|
43 |
| - } catch (Throwable t) { |
44 |
| - DataPoint annotation = fMethod.getAnnotation(DataPoint.class); |
45 |
| - if (annotation != null) { |
46 |
| - for (Class<? extends Throwable> ignorable : annotation.ignoredExceptions()) { |
47 |
| - Assume.assumeThat(t, not(instanceOf(ignorable))); |
48 |
| - } |
49 |
| - } |
| 40 | + } catch (Throwable throwable) { |
| 41 | + DataPoint annotation = fMethod.getAnnotation(DataPoint.class); |
| 42 | + Assume.assumeTrue(annotation == null || !isAssignableToAnyOf(annotation.ignoredExceptions(), throwable)); |
50 | 43 |
|
51 |
| - throw new CouldNotGenerateValueException(t); |
| 44 | + throw new CouldNotGenerateValueException(throwable); |
52 | 45 | }
|
53 | 46 | }
|
54 | 47 |
|
55 | 48 | @Override
|
56 | 49 | public String getDescription() throws CouldNotGenerateValueException {
|
57 | 50 | return fMethod.getName();
|
58 | 51 | }
|
59 |
| - } |
| 52 | + } |
60 | 53 |
|
61 | 54 | private final TestClass fClass;
|
62 | 55 |
|
@@ -86,16 +79,13 @@ private void addMultiPointMethods(ParameterSignature sig, List<PotentialAssignme
|
86 | 79 | if (returnType.isArray() && sig.canPotentiallyAcceptType(returnType.getComponentType())) {
|
87 | 80 | try {
|
88 | 81 | addArrayValues(sig, dataPointsMethod.getName(), list, dataPointsMethod.invokeExplosively(null));
|
89 |
| - } catch (Throwable t) { |
| 82 | + } catch (Throwable throwable) { |
90 | 83 | DataPoints annotation = dataPointsMethod.getAnnotation(DataPoints.class);
|
91 |
| - if (annotation != null) { |
92 |
| - for (Class<? extends Throwable> ignored : annotation.ignoredExceptions()) { |
93 |
| - if (ignored.isAssignableFrom(t.getClass())) { |
94 |
| - return; |
95 |
| - } |
96 |
| - } |
| 84 | + if (annotation != null && isAssignableToAnyOf(annotation.ignoredExceptions(), throwable)) { |
| 85 | + return; |
| 86 | + } else { |
| 87 | + throw throwable; |
97 | 88 | }
|
98 |
| - throw t; |
99 | 89 | }
|
100 | 90 | }
|
101 | 91 | }
|
@@ -145,6 +135,15 @@ private Object getStaticFieldValue(final Field field) {
|
145 | 135 | "unexpected: getFields returned an inaccessible field");
|
146 | 136 | }
|
147 | 137 | }
|
| 138 | + |
| 139 | + private static boolean isAssignableToAnyOf(Class<?>[] typeArray, Object target) { |
| 140 | + for (Class<?> type : typeArray) { |
| 141 | + if (type.isAssignableFrom(target.getClass())) { |
| 142 | + return true; |
| 143 | + } |
| 144 | + } |
| 145 | + return false; |
| 146 | + } |
148 | 147 |
|
149 | 148 | protected Collection<FrameworkMethod> getDataPointsMethods(ParameterSignature sig) {
|
150 | 149 | return fClass.getAnnotatedMethods(DataPoints.class);
|
|
0 commit comments