Skip to content

Commit 1c33be1

Browse files
committed
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
1 parent 8cfb3a0 commit 1c33be1

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

‎hamcrest-core/src/main/java/org/hamcrest/core/CombinableMatcher.java‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,18 @@ private ArrayList<Matcher<? super T>> templatedListWith(Matcher<? super T> other
4747
* </pre>
4848
*/
4949
@Factory
50-
public static <LHS> CombinableMatcher<LHS> both(Matcher<? super LHS> matcher) {
51-
return new CombinableMatcher<LHS>(matcher);
50+
public static <LHS> CombinableBothMatcher<LHS> both(Matcher<? super LHS> matcher) {
51+
return new CombinableBothMatcher<LHS>(matcher);
52+
}
53+
54+
public static final class CombinableBothMatcher<X> {
55+
private final Matcher<? super X> first;
56+
public CombinableBothMatcher(Matcher<? super X> matcher) {
57+
this.first = matcher;
58+
}
59+
public CombinableMatcher<X> and(Matcher<? super X> other) {
60+
return new CombinableMatcher<X>(first).and(other);
61+
}
5262
}
5363

5464
/**
@@ -58,7 +68,17 @@ public static <LHS> CombinableMatcher<LHS> both(Matcher<? super LHS> matcher) {
5868
* </pre>
5969
*/
6070
@Factory
61-
public static <LHS> CombinableMatcher<LHS> either(Matcher<? super LHS> matcher) {
62-
return new CombinableMatcher<LHS>(matcher);
71+
public static <LHS> CombinableEitherMatcher<LHS> either(Matcher<? super LHS> matcher) {
72+
return new CombinableEitherMatcher<LHS>(matcher);
73+
}
74+
75+
public static final class CombinableEitherMatcher<X> {
76+
private final Matcher<? super X> first;
77+
public CombinableEitherMatcher(Matcher<? super X> matcher) {
78+
this.first = matcher;
79+
}
80+
public CombinableMatcher<X> or(Matcher<? super X> other) {
81+
return new CombinableMatcher<X>(first).or(other);
82+
}
6383
}
64-
}
84+
}

0 commit comments

Comments
 (0)