mercredi 15 janvier 2020

How to mock function inside function based on specific arguments?

I have a function like this that I would like to write a JUnit unit test:

public static Answer function A(String a, String b) {
    if(a == null)
       a = 'not_null';
    if(b == null)
       b = 'not_null';
    MyObject o = new MyObject(a, b);
    Answer a = function_b(o);
    return a.getList(); // Some list 
}

I would like to ensure whether function A is calling function_b with a MyObject parameters with no null String values. What is the best way to unit test this case using Mockito? I am assuming I need to somehow mock function_b's result based on Object o being passed with null string or not but not sure how to. Thanks!

Aucun commentaire:

Enregistrer un commentaire