Skip to content
Advertisement

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.WrongTypeOfReturnValue: ReturnsArgumentAt cannot be returned by getPermittedUserIDs() getPermittedUserIDs() should return List If you’re

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 spy doesn’t alter the argument in-place, it decorates it and returns

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 this [see the

Testing a Spring ControllerMethod using Mockito which alters an entry in the db with Optional.map NullPOinterException

Im currently Testing my Controller methods. In one Method I add a Reisepunkt(travelpoint) to a Reise(travel), which is already saved inside a database. Using the generated-request.http API I can use the method to make entrys into the db. Now i wanted to write a test method just so I can get the hang of it. I always get a NullPointerException

Spring Mockito @BeforeAll mocking logic works on 1 test only

I have a problem with understanding why the logic mocked inside @BeforeAll works, but only for the first test. They work fine separately, copying the identical logic to both tests will produce the same result – 1 passed, 1 failed. What happens: in AboutUsService.update() on the first line appears the mistake at pageRepository.getByName(ABOUT_US_PAGE).orElseThrow(null); For the first test, the calling of

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 the real LacalDateTime not

Advertisement