I have a project with Morphia ORM - Without transactions. And I have this method:
public void methodForTest() {
try {
methodCanThrowException();
} catch (Exception e) {
methodWhiсhICanNotTest(template);
throw new Exception("message of exception");
}
}
private void methodWhiсhICanNotTest(String template){
serviceWhichCanBeMockOne.clearAll(template);
serviceWhichCanBeMockTwo.clearAll(template);
serviceWhichCanBeMockThree.clearAll(template);
}
Can I check that methodWhiсhICanNotTest();
was called? or how can I rewrite this code for easier testing?
UPDATE ANSWER FOR THE UPDATED QUESTION:D
If your methodWhiсhICanNotTest
is a private method. Then you cannot verify it using Mockito in my previous answer. PowerMock is another solution for you. Read this article and try it:-)
=======================
You can use Mockito to verify whether methodWhiсhICanNotTest
is called.
Mockito.verify(abc.methodWhiсhICanNotTest())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.