This question already has an answer here:
I have code like this:
switch(someEnumValue) {
case MyEnum.SomeEnum:
blah();
break;
case MyEnum.MoreEnum:
moreBlah();
break;
default:
throw new IllegalStateException("Unknown enum value.");
}
How do I test the default case which has been put there for defensive coding purposes?
Do I use a 'null' value for someEnumValue? Or is there some way in Java to sneakily created an instance of an enum which is actually invalid?
I like the defensive coding practice, but when combined with static analysis that checks code coverage and forces things like default cases in switches - it can make testing a little tricky.
Aucun commentaire:
Enregistrer un commentaire