Skip to content

Commit 86743e0

Browse files
inkblotjnape
authored andcommitted
Loosen EitherMatcher types, add static constructors
Add isRight() and isLeft() matcher constructors to EitherMatcher. To implement these using the anything() core matcher as the inner matcher, the type signature in isRightThat(..) and isLeftThat(..) has to be loosened since this and some other core matchers are not strictly typed with parameterized types.
1 parent a472c9f commit 86743e0

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/test/java/testsupport/matchers/EitherMatcher.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
import static com.jnape.palatable.lambda.adt.Either.right;
1010
import static com.jnape.palatable.lambda.functions.builtin.fn1.Constantly.constantly;
1111
import static com.jnape.palatable.lambda.io.IO.io;
12+
import static org.hamcrest.CoreMatchers.anything;
1213

1314
public final class EitherMatcher<L, R> extends TypeSafeMatcher<Either<L, R>> {
14-
private final Either<Matcher<L>, Matcher<R>> matcher;
15+
private final Either<Matcher<? super L>, Matcher<? super R>> matcher;
1516

16-
private EitherMatcher(Either<Matcher<L>, Matcher<R>> matcher) {
17+
private EitherMatcher(Either<Matcher<? super L>, Matcher<? super R>> matcher) {
1718
this.matcher = matcher;
1819
}
1920

@@ -44,11 +45,19 @@ public void describeTo(Description description) {
4445
.unsafePerformIO();
4546
}
4647

47-
public static <L, R> EitherMatcher<L, R> isLeftThat(Matcher<L> lMatcher) {
48+
public static <L, R> EitherMatcher<L, R> isLeftThat(Matcher<? super L> lMatcher) {
4849
return new EitherMatcher<>(left(lMatcher));
4950
}
5051

51-
public static <L, R> EitherMatcher<L, R> isRightThat(Matcher<R> rMatcher) {
52+
public static <L, R> EitherMatcher<L, R> isLeft() {
53+
return isLeftThat(anything());
54+
}
55+
56+
public static <L, R> EitherMatcher<L, R> isRightThat(Matcher<? super R> rMatcher) {
5257
return new EitherMatcher<>(right(rMatcher));
5358
}
59+
60+
public static <L, R> EitherMatcher<L, R> isRight() {
61+
return isRightThat(anything());
62+
}
5463
}

0 commit comments

Comments
 (0)