I'm interested in writing a test that allows me to check whether a function returns one of two values. For example:
@Test
public void testRandomFunction() {
assertEquals(
either(equalTo(2)).or(equalTo(3)),
RandomFunction(5)
);
return;
}
Reading up online I found out about the matchers in hamcrest. The code compiles but when I run the test, it seems the integer 5 is compared to a matcher object instead of integers 2 and 3.
I am open to try something different besides matchers if it makes this easier. Does anyone know how I can do this?
I have also tried the following without success:
@Test
public void testRandomFunction() {
Set<Integer> acceptedValues = new HashSet<Integer>();
acceptedValues.add(2);
acceptedValues.add(3);
assertEquals(
isIn(acceptedValues),
RandomFunction(5)
);
return;
}