I want to stub a private method in the class under test. I am using junit 5. I have used before powermock to achieve this. Unfortunately junit 5 does not work with powermock.
I have simplified the example to better explain the problem. I have class that has has private helper method that is called inside public methods. Like below:
public class Service {
private Repository repository;
public Object findById(String id) {
Object object = repository.findById(id);
object = verify(object);
return object;
}
private Object verify(Object object) {
//removed for simplicity
return object;
}
}
Now I want to unit test the method findById of Service. I have used junit 5 with mockito to implement unit test for the Service class.
public class ServiceUTest {
@InjectMocks
private Service service;
@Mock
private Repository repository;
@BeforeEach
public void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test
public void testFindById() {
when(repository.findById(Mockito.any())).thenReturn(new Object());
//how to stub verify method
}
}
I would appreciate any help and guide to solve this problem.
Regards,