diff --git a/src/main/java/org/hamcrest/junit/ExpectedException.java b/src/main/java/org/hamcrest/junit/ExpectedException.java index 77be281..7d59f55 100644 --- a/src/main/java/org/hamcrest/junit/ExpectedException.java +++ b/src/main/java/org/hamcrest/junit/ExpectedException.java @@ -170,7 +170,7 @@ public Statement apply(Statement base, * throw e; * } */ - public void expect(Matcher matcher) { + public void expect(Matcher matcher) { matcherBuilder.add(matcher); } diff --git a/src/main/java/org/hamcrest/junit/ExpectedExceptionMatcherBuilder.java b/src/main/java/org/hamcrest/junit/ExpectedExceptionMatcherBuilder.java index e67ef10..e1d82f9 100644 --- a/src/main/java/org/hamcrest/junit/ExpectedExceptionMatcherBuilder.java +++ b/src/main/java/org/hamcrest/junit/ExpectedExceptionMatcherBuilder.java @@ -1,7 +1,6 @@ package org.hamcrest.junit; import static org.hamcrest.CoreMatchers.allOf; -import static org.hamcrest.junit.JUnitMatchers.isThrowable; import java.util.ArrayList; import java.util.List; @@ -13,9 +12,9 @@ */ class ExpectedExceptionMatcherBuilder { - private final List> matchers = new ArrayList>(); + private final List> matchers = new ArrayList<>(); - void add(Matcher matcher) { + void add(Matcher matcher) { matchers.add(matcher); } @@ -23,24 +22,8 @@ boolean expectsThrowable() { return !matchers.isEmpty(); } - Matcher build() { - return isThrowable(allOfTheMatchers()); + Matcher build() { + return allOf(matchers); } - private Matcher allOfTheMatchers() { - if (matchers.size() == 1) { - return cast(matchers.get(0)); - } - return allOf(castedMatchers()); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private List> castedMatchers() { - return new ArrayList>((List) matchers); - } - - @SuppressWarnings("unchecked") - private Matcher cast(Matcher singleMatcher) { - return (Matcher) singleMatcher; - } } diff --git a/src/test/java/org/hamcrest/junit/ExpectedExceptionTest.java b/src/test/java/org/hamcrest/junit/ExpectedExceptionTest.java index dfe4151..054fe4c 100644 --- a/src/test/java/org/hamcrest/junit/ExpectedExceptionTest.java +++ b/src/test/java/org/hamcrest/junit/ExpectedExceptionTest.java @@ -227,7 +227,7 @@ public static class ExpectsMatcher { @Test public void throwsMore() { - thrown.expect(any(Exception.class)); + thrown.expect(instanceOf(Exception.class)); throw new NullPointerException("Ack!"); } }