I want to test that my method calls another method in the same class that I cannot mock.
Example:
public void methodToTest(){
//other stuff to test that can be mocked
someClassICanMock.doSomething();
//method within same class that cannot be mocked
methodFromSameClassIWantToVerify();
}
How can I use a verify
to check that this my method under test calls methodFromSameClassIWantToVerify();?
Edit: not a duplicate as I am specifically refers to how to test this using mockito.
like this,
MyClass c = new MyClass();
someClassICanMock m = mock(someClassICanMock.class);
doNothing().when(m).doSomething();
MyClass s = spy(c);
s.methodToTest();
verify(s , times(1)).methodFromSameClassIWantToVerify();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With