I am quite confused about writing the unit test to test myMethod, because it cannot cover the logics defined factory, because the default value of boolean is false, it means if I don't changed flag to true, it won't be executed at all. How can I define flag is true in my test in order factory method can be executed?
@Service
public class MyService{
private boolean flag;
private String result;
public void myMethod(String input1, String input2) {
factory(input1, input2);
}
private void factory(String input1, String input2) {
if (flag) {
result = input1 + input2;
}
}
Here is my test:
@Test
public void myMethod() {
assertEquals(myMethod("Hello", "World"), "HelloWorld");
}
Aucun commentaire:
Enregistrer un commentaire