I have the following piece of java method code:
@Override
public void applyStates(int timestamp, State[] states) {
// Calculate the time diff between current time and the time stamp of the given states.
int diff = getNetworkTime() - timestamp;
if (diff <= 0) {
Log.e("Ignoring states that seem to come from the future!");
return;
}
if (diff >= DIFF_THRESHOLD) {
Log.w("Ignoring states that are too old. Diff is: " + diff);
return;
}
// Do the real processing here.
}
I'd like this code to be testable (by unit tests), however since it has a flow that's comprised of multiple return statements, it's not so easy for me to do so.
I'd like to verify for example, that depending on the input, i go into the 2 different validation clauses in the beginning of the method.
Is there a better design than this? how can this method be better structured for testabilty?