Skip to content

Tag: mockito

Mockito returning same argument of ArrayList which is passed

I have a method which is used as : The method mocking followed is as : Option 1 : This is not even working because i think only doReturn needs to be worked, thenAnswer will not work here. Option 2: Getting Runtime exception as : ERROR! java.lang.RuntimeException: org.mockito.exceptions.misusing.WrongTypeOfRet…

Mockito Spy : Wanted but not invoked, but it is

I have a basic unit test for a Service with a mocked repository as follow : When running the test, I get the following error : Second sentence saying the exact opposite of the first sentence… I tried using verify(repoSpy, atLeastOnce()).deleteById(anyLong()); just in case, but same error message. Answer…

How to mock a method call in a constructor?

I have class class1, which has 2 member variables: I want to test the method fun, so I will have to write a test-class and a test method for that. But, how do I mock the method call config.getEnablingStatus(), while creating an object of type classA in the test class? I am thinking of doing something like thi…

How to mock LocalDateTime.now() in java 8

Please, I am testing a functionality ABC that uses LocalDateTime.now(). In the methode ABC i’am comparing an entry date with the LocalDateTime.now() I want my test to be passed at any day so i have to mock the LocalDateTime.now() This is my test: I am using JAVA 8 the date shown in the console is always…