In JMockit, there are types that are outright un-mockable (like java.lang.Class) or are really bad ideas to mock (like java.lang.Math, as stated in this question).
How do you use Verifications on these types? Using the linked question as an example, how would I verify that Math.pow()
got called with the right arguments?
By way of example, this test passes even though I call Math.pow()
but I check for Math.min()
in the Verifications - how could I make this fail?
public class TestTest {
public static class MyClass {
public double foo() {
return Math.pow(2, 3);
}
}
@Tested MyClass mc;
// @Mocked java.lang.Math math;
@Test
public void testCalendar() throws Throwable {
double d = mc.foo();
assertThat(d, is(8.0));
new FullVerificationsInOrder() {{
Math.min(42.0, 17.0);
}};
}
}
Adding the commented-out line, to mock Math
, only leads to disastrous results due to fouling up classloaders etc that rely on java.lang.Math
. Making it @Injectable
instead of @Mocked
has no effect since all methods are static.
So how could I verify it?