I know that it is possible to mock a single enum(using How to mock an enum singleton class using Mockito/Powermock?), but I have like 1000 of enum values and they can call 5 different constructors. The enum values are often changing in development.
I want to really mock only one or two for my JUnit test. I don't care about the rest, but they are still instantiated, which calls some nasty stuff, which loads the values for the enum from the file system.
Yes I know It's very bad design. But for now I don't get the time to change it.
At the moment we have Mockito/powermock in use. But any framework, which can solve this sh** I mean bad design is welcome.
Let's say I have an enum similar to this:
public static enum MyEnum {
A(OtherEnum.CONSTANT),
B("1"),
C("1", OtherEnum.CONSTANT),
//...and so on for again 1000 enum values :(
private double value;
private String defaultValue;
private OtherEnum value;
/* Getter/Setter */
/* constructors */
}
enum
implement aninterface
that can then be mocked. It's a hack but would allow you to write your test now, then you should refactor – Unfasten