I am trying to understand how to use mocking with Mockito, but I don't know how to handle the following situation:
- Where the method in the class which you are trying to mock is private.
- Where the method should remain in the class.
- Where making the method public could result in future programmers making the code behavior unexpectedly, thus should remain private.
public class Foo {
private final int secret;
public Foo(int s) {
secret = s;
}
public void bar() {
int sum = sum(0);
}
private int sum(int i) {
if (i == 1) {
return i * secret;
}
secret -= i;
return i;
}
}
I am trying to mock Foo and test that sum is behaving correctly, but I'm struggling to decide how best to do so with minimal impact. Should I change the sum method to public? How do you go about testing this behavior?
Aucun commentaire:
Enregistrer un commentaire