How would you go about getting 100% code coverage with the code below?
- (void)methodA {
mState = Active;
// do something ...
methodB();
}
- (void)methodB {
if (mState != Active) return;
// do something else ...
}
I can test the do something and do something else parts easily, the problem lies in the if (mState != Active) return; line of methodB. Since methodA is always setting the state to Active, the early return will never be executed.
I have the early return code in place just in case methodB is called elsewhere in the future. The code does not make sense to execute if mState is not Active, so it's defensive coding more or less.
I can add comments to the method stating "this method assumes the state is Active" or something, but that doesn't enforce the contract that the state must be active. Throwing an exception and/or asserting could be possibilities here too, but again I'm not sure how I could test that to get 100% code coverage.
I totally understand that for cases like this it is probably irrelevant to get 100% code coverage - but unfortuantely the decision to get is not mine (right now at least). The 'bosses' want this done, and are being unreasonable about this if you ask me!