I am new to the concept of writing unit tests so I'm not sure how to go on about this. I have the following method in my class which is a class full of helper functions which gets used around my app:
public static float getCurrentTime() {
Calendar calandar = Calendar.getInstance();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
String[] time = simpleDateFormat.format(calandar.getTime()).split(":");
float returnResult = /*perform some calculations*/
return returnResult ;
}
Now in this method, the result depends on what time it is. In my unit test, I want to control that aspect to ensure to gives me the right time but I'm not sure how to do that. I looked up powermockito and using the when(..).then(..)
method, also looked into mocking the calender object but because its instantiated in the method, it doesn't look like that'll work. Any ideas? I have no constructors in this class as all the methods in this class is static so I simply call the methods by class name rather than instantiating an object of this class.