I have the following enum in java:
public enum MyEnum {
INSTANCE;
//do some other stuff
public List<Long> getBlah(String input) {
return something;
}
}
The following is the test code in scala (Why in scala? because the actual code that uses MyEnum
is in scala)
import org.powermock.api.mockito.PowerMockito.mock
import org.powermock.modules.junit4.PowerMockRunner
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.reflect.Whitebox
@RunWith(classOf[PowerMockRunner])
@PrepareForTest(Array(classOf[MyEnum]))
class MyTest extends FunSuite {
test("my test") {
var myMock = mock(classOf[MyEnum])
Whitebox.setInternalState(classOf[MyEnum], "INSTANCE", myMock)
var result = MyEnum.INSTANCE.getBlah("input")
}
}
But I get the error:
java.lang.IllegalArgumentException: Cannot subclass final class class MyEnum
The same test code works in junit
but not in scala
. I suspect that its scala specific. Can anyone point the mistake? I think its the RunWith
and PrepareForTest
annotations that are not working.