mercredi 6 juillet 2016

Mock an enum using Mockito in Java

How can I mock an enum for testing purposes using Mockito? Given this sample for the enum:

public enum TestEnum {
 YES,
 NO
}

and this one for the method using the enum:

public static boolean WorkTheEnum(TestEnum theEnum) {
switch (theEnum) {
  case YES:
     return true;
  case NO:
     return false;
  default:
     // throws an exception here
 }
}

how can I mock the enum to reach the default branch of the switch loop? This answer says Mockito can't mock enums but the answer has also been provided more than a year ago. Do I can mock an enum meanwhile or have I to let the branch stay untested? Other Mocking frameworks can't be used.

Aucun commentaire:

Enregistrer un commentaire