diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-01-02 22:26:45 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-01-02 22:26:45 +0000 |
| commit | 871df6bd1a1f7c45e750a49589c7a195c3506205 (patch) | |
| tree | 11b552f4c2e12ec1242852c047446d1f27df20f3 /src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java | |
| parent | d5005305b90afe47e639fc0fa1430242556f0385 (diff) | |
Add reading of style IDs
Diffstat (limited to 'src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java')
| -rw-r--r-- | src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java b/src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java index 8ee0d8f..54b74ee 100644 --- a/src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java +++ b/src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java @@ -11,6 +11,7 @@ import org.hamcrest.TypeSafeDiagnosingMatcher; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.List; +import java.util.Optional; import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.transform; @@ -37,6 +38,9 @@ public class DeepReflectionMatcher<T> extends TypeSafeDiagnosingMatcher<T> { mismatchDescription.appendText("was " + actual.getClass().getName()); return false; } + if (expected instanceof Optional && actual instanceof Optional) { + return matchesOptional(path, (Optional)expected, (Optional)actual, mismatchDescription); + } if (expected instanceof String) { return matchesString(path, expected, actual, mismatchDescription); @@ -75,6 +79,26 @@ public class DeepReflectionMatcher<T> extends TypeSafeDiagnosingMatcher<T> { return true; } + private static boolean matchesOptional(String path, Optional expected, Optional actual, Description mismatchDescription) { + if (actual.isPresent() && !expected.isPresent()) { + appendPath(mismatchDescription, path); + mismatchDescription.appendText("had value " + generateDescriptionOfValue(actual.get())); + return false; + } + + if (expected.isPresent() && !actual.isPresent()) { + appendPath(mismatchDescription, path); + mismatchDescription.appendText("was empty"); + return false; + } + + if (actual.isPresent() && expected.isPresent()) { + return matchesSafely(path, expected.get(), actual.get(), mismatchDescription); + } + + return true; + } + private static <T> boolean matchesString(String path, T expected, T actual, Description mismatchDescription) { Matcher<Object> matcher = Matchers.equalTo(expected); if (!matcher.matches(actual)) { |
