wujun / powermock

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

PowerMock cannot mockStatic ADFContext class #403

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
PowerMock cannot mockStatic oracle.adf.share.ADFContext class.

What steps will reproduce the problem?

import oracle.adf.share.ADFContext;
import static org.easymock.EasyMock.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest( { ADFContext.class })
public class ADFContextTest {
    public ADFContextTest() {
    }

    @Test
    public void testADFContext() {
        PowerMock.mockStatic(ADFContext.class);
        expect(ADFContext.getCurrent()).andReturn(null);
        PowerMock.replay(ADFContext.class);
        ADFContext.getCurrent();
        PowerMock.verifyAll();
    }
}

The above test case fails with exception:

Exception in thread "main" java.lang.IllegalStateException: Failed to transform 
class with name oracle.adf.share.ADFContext. Reason: PowerMock internal error 
when modifying method.
    at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:207)
    at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:145)
    at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:67)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

What version of the product are you using?

powermock-easymock-1.4.12
easymock-3.1

Original issue reported on code.google.com by discordi...@gmail.com on 18 Sep 2012 at 6:00