java - How to mock/fake a new enum value with JMockit -


how can add fake enum value using jmockit?

i could't find in documentation. possible?

related: this question mockito only, not jmockit.

edit: removed examples gave in first place because examples seem distracting. please have @ upvoted answer on linked question see i'm expecting. want know if it's possible same jmockit.

i think trying solve wrong problem. instead, fix foo(myenum) method follows:

    public int foo(myenum value) {         switch (value) {             case a: return 1;             case b: return 2;         }         return 0; // satisfy compiler     } 

having throw @ end capture imaginary enum element doesn't exist not useful, never reached. if concerned new element getting added enum , foo method not being updated accordingly, there better solutions. 1 of them rely on code inspection java ide (intellij @ least has 1 case: "switch statement on enumerated type misses case") or rule static analysis tool.

the best solution, though, put constant values associated enum elements belong (the enum itself), therefore eliminating need switch:

public enum betterenum {     a(1), b(2);      public final int value;     betterenum(int value) { this.value = value; } } 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -