title: How can I mock an instance of an enum class with PowerMock & Mockito?
body: <p>I tried to follow the example offered in the answer to this very similar question, but it does not work for me. I get the following error message:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Cannot subclass final class class com.myproject.test.support.ExampleEnumerable
      at org.mockito.cglib.proxy.Enhancer.generateClass(Enhancer.java:447)
      at org.mockito.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
      at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:217)
      at org.mockito.cglib.proxy.Enhancer.createHelper(Enhancer.java:378)
      at org.mockito.cglib.proxy.Enhancer.createClass(Enhancer.java:318)
      at org.powermock.api.mockito.repackaged.ClassImposterizer.createProxyClass(ClassImposterizer.java:123)
      at org.powermock.api.mockito.repackaged.ClassImposterizer.imposterise(ClassImposterizer.java:57)
      at org.powermock.api.mockito.internal.mockcreation.MockCreator.createMethodInvocationControl(MockCreator.java:110)
      at org.powermock.api.mockito.internal.mockcreation.MockCreator.mock(MockCreator.java:58)
      at org.powermock.api.mockito.PowerMockito.mock(PowerMockito.java:143)
  </code></pre>
  
  <p>I need a simple mock instance of an <code>enum class</code>. I don't need to mock any of its methods.</p>
  
  <p>Here is the class I want to mock:</p>
  
  <pre><code>public enum ExampleEnumerable implements IEnumerable&lt;ExampleEnumerable&gt; {
      EXAMPLE_ENUM_1("Test Enum 1"),
      EXAMPLE_ENUM_2("Test Enum 2");
  
      final String alias;
  
      ExampleEnumerable(final String alias) {
          this.alias = alias;
      }
  
      @SuppressWarnings({"VariableArgumentMethod", "unchecked"})
      @Override
      public @Nullable
      String getAlias(final @Nonnull IEnumerable&lt;? extends Enum&lt;?&gt;&gt;... context) {
          return alias;
      }
  }
  </code></pre>
  
  <p>I have the following TestNG setup:</p>
  
  <pre><code>import static org.powermock.api.mockito.PowerMockito.mock;
  
  @PrepareForTest({ ExampleEnumerable.class})
  @Test(groups = {"LoadableBuilderTestGroup"})
  public class LoadableBuilderTest {
  
      private ExampleEnumerable mockEnumerable;
  
      @BeforeMethod
      public void setUp() {
          mockEnumerable = mock(ExampleEnumerable.class);
      }
  }
  </code></pre>