jeudi 4 juillet 2019

How can I test if a method was called on an object created inside the method to be tested

Is it possible to test that the "innerMethod" was called without modify the Class class?

I need to make a unit test in a separate class both scenario of the "someCondition".

The problem is that the method is void so I cannot make use of the return type. The only way would be to check if the "innerMethod" was called.

I was thinking to use Mokito verify but this method is called inside a method on an object created at runtime.

Any suggestion are most welcome.

public class Class {

 public void outerMethod(outerObj) {

      if(someCondition) {

           Object innerObj = new Object();
           innerObj.innerMethod(outerObj); 

      } else {

           //other code
      }    

}

Aucun commentaire:

Enregistrer un commentaire