Skip to content
Browse files

address issue 154 (reported on google code project) : Prevent either(…

…).and() and both().or(). This should also attend to issue 236 on the junit project https://github.com/KentBeck/junit/issues/236 and pull request 272 on the junit project https://github.com/KentBeck/junit/pull/272
  • Loading branch information...
1 parent 8cfb3a0 commit 1c33be116091a885b21797aae761d5652bcdf3af @scarytom scarytom committed
Showing with 25 additions and 5 deletions.
  1. +25 −5 hamcrest-core/src/main/java/org/hamcrest/core/CombinableMatcher.java
View
30 hamcrest-core/src/main/java/org/hamcrest/core/CombinableMatcher.java
@@ -47,8 +47,18 @@ public void describeTo(Description description) {
* </pre>
*/
@Factory
- public static <LHS> CombinableMatcher<LHS> both(Matcher<? super LHS> matcher) {
- return new CombinableMatcher<LHS>(matcher);
+ public static <LHS> CombinableBothMatcher<LHS> both(Matcher<? super LHS> matcher) {
+ return new CombinableBothMatcher<LHS>(matcher);
+ }
+
+ public static final class CombinableBothMatcher<X> {
+ private final Matcher<? super X> first;
+ public CombinableBothMatcher(Matcher<? super X> matcher) {
+ this.first = matcher;
+ }
+ public CombinableMatcher<X> and(Matcher<? super X> other) {
+ return new CombinableMatcher<X>(first).and(other);
+ }
}
/**
@@ -58,7 +68,17 @@ public void describeTo(Description description) {
* </pre>
*/
@Factory
- public static <LHS> CombinableMatcher<LHS> either(Matcher<? super LHS> matcher) {
- return new CombinableMatcher<LHS>(matcher);
+ public static <LHS> CombinableEitherMatcher<LHS> either(Matcher<? super LHS> matcher) {
+ return new CombinableEitherMatcher<LHS>(matcher);
+ }
+
+ public static final class CombinableEitherMatcher<X> {
+ private final Matcher<? super X> first;
+ public CombinableEitherMatcher(Matcher<? super X> matcher) {
+ this.first = matcher;
+ }
+ public CombinableMatcher<X> or(Matcher<? super X> other) {
+ return new CombinableMatcher<X>(first).or(other);
+ }
}
-}
+}

0 comments on commit 1c33be1

Please sign in to comment.
Something went wrong with that request. Please try again.