How can I tell if an object is a Mockito mock?
As a follow up, the Mockito public API now has this method:
MockingDetails org.mockito.Mockito.mockingDetails(Object toInspect)
Which is the result of the issue that @David Wallace raised. The returned object supports the methods isMock()
as well as isSpy()
along with a few other methods that provide additional mocking information.
Looks like there is no such API (please raise an issue, it should be!) Fortunately (following your comment below) there is a method in the org.mockito.internal.util
package:
import org.mockito.internal.util.MockUtil;
new MockUtil().isMock(obj)
In the future Mockito.isMock()
method might be added to public API, see: Issue 313: Provide isMock outside of org.mockito.internal).