I am running into a problem mocking out java.lang.Math
using JMockit (1.21). See below for a simplified use of my actual class. Basically somewhere in my code I use
Because 1) methods from java.lang.Math
(in particular, Math.min(a, b)
) get called all the time by other classes from the JRE (for example, look inside java.lang.String
), and 2) when JMockit mocks a class (with @Mocked
, anyway), it gets mocked for the duration of the test, regardless of where the calls are coming from.
Bottom line, don't mock low-level JRE classes unless you really know what you are doing. In this particular case, JMockit should probably deny the full mocking of java.lang.Math
, as really there is no good reason (that I can see) for doing it.