Thoppan / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

java.lang.IllegalAccessError when using PowerMock 1.6.0 and Mockito 1.10.16 #533

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. The following test class can reproduce the issue:

@RunWith(PowerMockRunner.class)
@PrepareForTest({StringBuilder.class})
public class BugTest {

    @Before
    public void setUp() throws Exception {
        mockStatic(StringBuilder.class);
    }

    @Test
    public void testSomething() throws Exception {

    }
}

What is the expected output? What do you see instead?

The test fails to run. Instead it breaks with the following stack trace:

java.lang.IllegalAccessError: tried to access class 
org.mockito.internal.creation.cglib.CGLIBHacker from class 
org.mockito.internal.creation.MethodInterceptorFilter
    at org.mockito.internal.creation.MethodInterceptorFilter.<init>(MethodInterceptorFilter.java:34)
    at org.powermock.api.mockito.internal.mockcreation.PowerMockMethodInterceptorFilter.<init>(PowerMockMethodInterceptorFilter.java:18)
    at org.powermock.api.mockito.internal.mockcreation.MockCreator.createMethodInvocationControl(MockCreator.java:108)
    at org.powermock.api.mockito.internal.mockcreation.MockCreator.mock(MockCreator.java:57)
    at org.powermock.api.mockito.PowerMockito.mockStatic(PowerMockito.java:70)
    at au.com.sensis.sitesmart.api.v1.AbstractSiteServletTest.setUp(AbstractSiteServletTest.java:31)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:129)
    at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:93)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:127)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:207)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:146)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:106)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
    at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

What version of the product are you using? On what operating system?

PowerMock 1.6.0 with Mockito 1.10.16 using Java 1.7.0_72 on Ubuntu 14.04 64-bit

Original issue reported on code.google.com by behran...@gmail.com on 15 Dec 2014 at 3:39

GoogleCodeExporter commented 9 years ago
Same problem with PowerMock 1.6.1, Mockito 1.10.17, Java 1.8.0_40, OS X 10.10.2 
while trying to mock a class with the mock() method of PowerMock:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import static org.mockito.Matchers.anyVararg;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.whenNew;

@RunWith(PowerMockRunner.class)
@PrepareForTest(App.class)
public class AppShould {

    @Test
    public void startWithArguments() throws Exception {
        final App appMock = mock(App.class);
        whenNew(App.class).withNoArguments().thenReturn(appMock);
        App.main(new String[]{"server", "config.yaml"});
        verify(appMock, times(1)).run(anyVararg());
    }
}

The exception thrown is:

java.lang.IllegalAccessError: tried to access class 
org.mockito.internal.creation.cglib.CGLIBHacker from class 
org.mockito.internal.creation.MethodInterceptorFilter
    at org.mockito.internal.creation.MethodInterceptorFilter.<init>(MethodInterceptorFilter.java:34)
    at org.powermock.api.mockito.internal.mockcreation.PowerMockMethodInterceptorFilter.<init>(PowerMockMethodInterceptorFilter.java:18)
    at org.powermock.api.mockito.internal.mockcreation.MockCreator.createMethodInvocationControl(MockCreator.java:108)
    at org.powermock.api.mockito.internal.mockcreation.MockCreator.mock(MockCreator.java:57)
    at org.powermock.api.mockito.PowerMockito.mock(PowerMockito.java:143)
    at xxxxx.xxxxx.xxxxx.AppShould.startWithArguments(AppShould.java:20)

Original comment by marcus.f...@gmail.com on 14 Mar 2015 at 9:32

GoogleCodeExporter commented 9 years ago
It seems to be fixed with PowerMock 1.6.2!

Original comment by marcus.f...@gmail.com on 24 Mar 2015 at 6:53