Skip to content
Advertisement

Tag: mocking

MockitoException when trying to mock java.lang.System

I have a test case that mock a static method of java.lang.System class: But when I run the test, I got this error: org.mockito.exceptions.base.MockitoException: It is not possible to mock static methods of java.lang.System to avoid interfering with class loading what leads to infinite loops Why does this happen? How can I mock methods of java.lang.System class? Answer While Mockito

Mocking a singleton with mockito

I need to test some legacy code, which uses a singleton in a a method call. The purpose of the test is to ensure that the clas sunder test makes a call to singletons method. I have seen similar questions on SO, but all the answers require other dependencies (different test frameworks) – I’m unfortunately limited to using Mockito and

Set value to mocked object but get null

I have a simple class Foo to be mocked: In my unit test code, I mock it by using Mockito. I set name in mocked object, but when I call getter to get the name it returns null. Is it a Mockito specific issue or is it an convention that mocked object can’t set value? Why is that? What is

Mockito Error Is Not Applicable for the Arguments (void)

Mockito throws error “The method when(T) in the type Stubber is not applicable for the arguments (void)” for a class I’m mocking, can’t figure out why. the code in question is: I’m aware similar questions have been asked but if somebody could explain a solution for this or point me in the right direction I would greatly appreciate it Answer

Advertisement