PowerMock, Mockito and mocking final class from the reflection api
===


I'm trying to mock the java.lang.reflect.Method, here my code:

    @RunWith(PowerMockRunner.class)
    @PrepareForTest(Method.class)
    public class AuditDataTest {
      @Test
      public void testStartAudit() {
    		Object[] args = new Object[1];
    		args[0] = "bla";
    		Method method = PowerMockito.mock(Method.class);
    		when(method.getAnnotation(Audit.class).value()).thenReturn("audit");
    		auditData.startAudit(method, args);
    	}
    }

When i run the test, i get following error message:

    java.lang.IllegalAccessError: java.lang.Class
    	at sun.reflect.GeneratedSerializationConstructorAccessor10.newInstance(Unknown Source)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    	at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:40)
    	at org.powermock.reflect.internal.WhiteboxImpl.newInstance(WhiteboxImpl.java:257)
    	at org.powermock.reflect.Whitebox.newInstance(Whitebox.java:139)
    	at org.powermock.core.DefaultFieldValueGenerator.instantiateFieldType(DefaultFieldValueGenerator.java:74)
    	at org.powermock.core.DefaultFieldValueGenerator.fillWithDefaultValues(DefaultFieldValueGenerator.java:51)
    	at org.powermock.api.mockito.internal.mockcreation.MockCreator.mock(MockCreator.java:60)
    	at org.powermock.api.mockito.PowerMockito.mock(PowerMockito.java:138)
    	at my.package.audit.AuditDataTest.testStartAudit(AuditDataTest.java:52)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
    	at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:322)
    	at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
    	at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
    	at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:309)
    	at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:297)
    	at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
    	at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
    	at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:222)
    	at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:161)
    	at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:135)
    	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
    	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
    	at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:133)
    	at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:112) 
    	at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:57)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Can someone explain me, what i'm doing wrong?