This is the test class has 2 methods.
@Service
class TestClass {
public void testingMethod() {
if (isTimeToExecute("task1")) {
// ..
// ..
// ..
// logic
}
}
private boolean isTimeToExecute(String taskName) {
Calendar calender = Calendar.getInstance();
boolean shouldBeExecuted = false;
switch (taskName) {
case "task1":
shouldBeExecuted = calender.get(Calendar.HOUR_OF_DAY) == 23;
break;
case "task2":
shouldBeExecuted = calender.get(Calendar.DAY_OF_WEEK) == 6 && calender.get(Calendar.HOUR_OF_DAY) == 23;
break;
}
return shouldBeExecuted;
}
}
I want to test testingMethod()
and need to spyOn(isTimeToExecute())
to always return true.
@Inject
private TestClass testClass;
@Test
public void testTestingMethod() {
testClass.testingMethod();
}