Thoppan / powermock

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

mockSelfPrivateMethod with class has self instance, StackOverFlowError #425

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Class:
package demo;

public class MockSelfPrivateFieldServiceClass {

    MockSelfPrivateFieldServiceClass instance = new MockSelfPrivateFieldServiceClass();

    private Boolean privateMethodSub()
    {
        //System.out.println("privateMethodSub...");
        return true;
    }

}

Test Class:
package application;

import static org.junit.Assert.assertEquals;

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.legacy.PowerMockRunner;

import org.powermock.reflect.Whitebox;

import demo.MockSelfPrivateFieldServiceClass;

@RunWith(PowerMockRunner.class)
@PrepareForTest(MockSelfPrivateFieldServiceClass.class)
public class MockSelfPrivateFieldServiceClassTest {

    @Test
    public void testInvokePrivateMethod() throws Exception {

        MockSelfPrivateFieldServiceClass tested = new MockSelfPrivateFieldServiceClass();
        Boolean expected = true;

        Boolean actual = (Boolean) Whitebox.invokeMethod(tested, "privateMethodSub");

        assertEquals("Expected and actual did not match", expected, actual);
    }
}

Trace:

java.lang.StackOverflowError
    at java.lang.Class.getParameterTypesSignature(Class.java:2046)
    at java.lang.Class.getDeclaredMethod(Class.java:590)
    at net.sf.cglib.proxy.Enhancer.getCallbacksSetter(Enhancer.java:630)
    at net.sf.cglib.proxy.Enhancer.isEnhanced(Enhancer.java:604)
    at org.powermock.api.extension.proxyframework.ProxyFrameworkImpl.isProxy(ProxyFrameworkImpl.java:29)
    at org.powermock.reflect.internal.WhiteboxImpl.getUnmockedType(WhiteboxImpl.java:1783)
    at org.powermock.reflect.internal.WhiteboxImpl.getConstructor(WhiteboxImpl.java:248)
    at org.powermock.core.MockGateway.newInstanceCall(MockGateway.java:192)
    at demo.MockSelfPrivateFieldServiceClass.<init>(MockSelfPrivateFieldServiceClass.java:5)

...
...
...
...

    at demo.MockSelfPrivateFieldServiceClass.<init>(MockSelfPrivateFieldServiceClass.java:5)
    at demo.MockSelfPrivateFieldServiceClass.<init>(MockSelfPrivateFieldServiceClass.java:5)
    at application.MockSelfPrivateFieldServiceClassTest.testInvokePrivateMethod(MockSelfPrivateFieldServiceClassTest.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:599)
    at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
    at org.powermock.modules.junit4.legacy.internal.impl.testcaseworkaround.PowerMockJUnit4LegacyTestMethodRunner.runUnprotected(PowerMockJUnit4LegacyTestMethodRunner.java:103)
    at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
    at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:599)
    at org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation(WhiteboxImpl.java:2014)
    at org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:885)
    at org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:801)
    at org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:442)
    at org.powermock.modules.junit4.legacy.internal.impl.testcaseworkaround.PowerMockJUnit4LegacyTestMethodRunner.run(PowerMockJUnit4LegacyTestMethodRunner.java:66)
    at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
    at org.powermock.modules.junit4.legacy.internal.impl.testcaseworkaround.PowerMockJUnit4LegacyTestClassMethodsRunner.run(PowerMockJUnit4LegacyTestClassMethodsRunner.java:96)
    at org.powermock.modules.junit4.legacy.internal.impl.PowerMockJUnit4LegacyRunnerDelegateImpl$1.runUnprotected(PowerMockJUnit4LegacyRunnerDelegateImpl.java:69)
    at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
    at org.powermock.modules.junit4.legacy.internal.impl.PowerMockJUnit4LegacyRunnerDelegateImpl.run(PowerMockJUnit4LegacyRunnerDelegateImpl.java:85)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:101)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Original issue reported on code.google.com by omerbatmaz@gmail.com on 27 Jan 2013 at 8:34