I am using PowerMock with Mockito to test a static function, as shown below. It worked well until today it throws this exception, mentioned below.
// this test case need to mock static methods so it uses PowerMock @RunWith(PowerMockRunner.class) // this static methods to be mocked are on Environment so that must be 'prepared' @PrepareForTest({Environment.class, Build.class, Build.VERSION.class}) public class FileUtilityUnitTest { //This uses the JUnit TemporaryFolder Rule to create // (and discard on completion) a directory for the assertions. @Rule TemporaryFolder storageDirectory = new TemporaryFolder(); File nonExistentDirectory; File existentDirectory; @Before public void setup(){ PowerMockito.mockStatic(Environment.class); PowerMockito.mockStatic(Build.VERSION.class); nonExistentDirectory = Mockito.mock(File.class); //so the exists method tends to be false when(nonExistentDirectory.exists()).thenReturn(false); existentDirectory = storageDirectory.getRoot(); } @Test public void test_is_external_storage_writable(){ when(Environment.getExternalStorageState()).thenReturn(Environment.MEDIA_MOUNTED); assertTrue("External storage mounted ", Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED); } }
And stacktrace is as follows.
Internal Error occured. java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724) at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531) at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355) at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286) at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120) at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72) at java.lang.Class.createAnnotationData(Class.java:3521) at java.lang.Class.annotationData(Class.java:3510) at java.lang.Class.getAnnotation(Class.java:3415) at com.intellij.junit4.JUnit4TestRunnerUtil.buildRequest(JUnit4TestRunnerUtil.java:150) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:93) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Can anyone tell about this. I was googling but can't find a good link. Thanks in advance.
Vansi source share