How can I mock an instance of an enum class with PowerMock & Mockito?
You need to run this with PowerMockRunner
eg.
@RunWith(PowerMockRunner.class)
@PrepareForTest({ ExampleEnumerable.class})
@Test(groups = {"LoadableBuilderTestGroup"})
public class LoadableBuilderTest {
private ExampleEnumerable mockEnumerable;
@BeforeMethod
public void setUp() {
mockEnumerable = mock(ExampleEnumerable.class);
}
}
I got this working by extending the PowerMockTestCase class that handles this kind of thing for TestNG:
@PrepareForTest(TestEnumerable.class)
@Test(groups = {"LoadableBuilderTestGroup"})
public class LoadableBuilderTest extends PowerMockTestCase {
private TestEnumerable mockEnumerable;
@SuppressWarnings("unchecked")
@BeforeMethod
public void setUp() {
mockEnumerable = PowerMockito.mock(TestEnumerable.class);
}
}