1

There is a mock for a service below:

@TestConfiguration
    public static class TestConfig {

        @Bean
        @Primary
        public UserService userServiceBean() {
            UserService mock = mock(UserService.class);
            doReturn(12l).when(mock).getCompanyId();
            return mock;
        }
    }

This affects other UT where I want to return some other companyId such as:

when(userService.getCompanyId()).thenReturn(155l); <-- this mock is not working

Thanks

1 Answers1

0

There are cases where you can't use when/thenReturn. Stubbing void methods is one such. Others include use with Mockito spies, and stubbing the same method more than once.

Reference: Mockito - difference between doReturn() and when()