aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-03-31 11:42:01 +0100
committerMichael Williamson <mike@zwobble.org>2016-03-31 11:42:01 +0100
commit66b9c8813b3a4d60420134ccff700b64d4668da3 (patch)
tree4d12eefc3169c64bb5a4d3a94255a285ceaa67d2 /src/test/java/org
parentf89273cc65a2abfeae7ea58b37424e066b9f81b3 (diff)
Tidy up isA matcher
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/zwobble/couscous/tests/backends/python/PythonCodeGeneratorTests.java33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCodeGeneratorTests.java b/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCodeGeneratorTests.java
index 98d2e20..bdbf47e 100644
--- a/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCodeGeneratorTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCodeGeneratorTests.java
@@ -1,7 +1,6 @@
package org.zwobble.couscous.tests.backends.python;
-import org.hamcrest.FeatureMatcher;
-import org.hamcrest.Matcher;
+import org.hamcrest.*;
import org.junit.Test;
import org.zwobble.couscous.backends.python.PythonCodeGenerator;
import org.zwobble.couscous.backends.python.ast.PythonListNode;
@@ -36,7 +35,35 @@ public class PythonCodeGeneratorTests {
}
private static <T, U> Matcher<T> isA(Class<U> type, Matcher<? super U> downcastMatcher) {
- return allOf(instanceOf(type), (Matcher<? super T>) downcastMatcher);
+ return new DiagnosingMatcher<T>() {
+ @Override
+ protected boolean matches(Object item, Description mismatch) {
+ if (null == item) {
+ mismatch.appendText("null");
+ return false;
+ }
+
+ if (!type.isInstance(item)) {
+ mismatch.appendValue(item).appendText(" is a " + item.getClass().getName());
+ return false;
+ }
+
+ if (!downcastMatcher.matches(item)) {
+ downcastMatcher.describeMismatch(item, mismatch);
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description
+ .appendText(type.getSimpleName())
+ .appendText(" with ");
+ downcastMatcher.describeTo(description);
+ }
+ };
}
private static Matcher<PythonExpressionNode> isPythonList(