ahmaddarawshi / powermock

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

When PrepareForTest on method is placed in method,powermock throws exception:Internal error: Failed to find the delgator index. #121

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
My test case:
@PowerMockIgnore("com.alcatel.omc.fwk.server.status")
public class DbPlugAccessMockTest extends TestBase {
    @SuppressWarnings("unchecked")
    public static TestSuite suite() throws Exception {
        return new PowerMockSuite(DbPlugAccessMockTest.class);
    }

    public DbPlugAccessMockTest(String name) {
        super(name);
    }

    @PrepareForTest( { LTEPlugIn.class })
    public void testInitTableOfflineMode() {
        Whitebox
                .setInternalState(LTEPlugIn.class, "MUSE_DB_OFFLINE_MODE", 
true);
        // In this case, we don't care its arguments.
        FwkStatusList actualStatus = DbPlugAccess.initTable(null);
        assertTrue(actualStatus.check());
    }
    @PrepareForTest( { DbAccess.class})
    public void testInitTableConnNull() throws Exception {
        mockStatic(DbAccess.class);
        // expect to return null so that null branch can be executed.
        expect(DbAccess.getConnection()).andReturn(null);
        DbAccess.releaseConnection(null);

        replay(DbAccess.class);

        // In this case, we don't care its arguments.
        FwkStatusList actual = DbPlugAccess.initTable(null);
        //assertNull(DbAccess.getConnection());

        verify(DbAccess.class);

        assertTrue(actual.contains(FwkStatus.database_problem()));
    }
    @PrepareForTest( { DbAccess.class})
    public void testInitTable() throws Exception {
        mockStaticNice(DbAccess.class);
        final String sqlscript = "sqlstatement1;sqlstatment2";
        final Connection conn = createNiceMock(Connection.class);
        final Statement stat = createNiceMock(Statement.class);
        expect(DbAccess.getConnection()).andReturn(conn);
        expect(conn.createStatement()).andReturn(stat);

        replayAll();

        // In this case, we don't care its arguments.
        FwkStatusList actual = DbPlugAccess.initTable(sqlscript);
        //assertNull(DbAccess.getConnection());

        verifyAll();

        assertTrue(actual.check());
    }

    public static void main(String[] args) throws Exception {
        TestRunner.run(suite());
    }
}

It works with junit.textui.TestRunner,but don't work with eclipse test 
runner. Exception as below:

java.lang.RuntimeException: Internal error: Failed to find the delgator 
index.
    at 
org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.getDelegatorInd
ex(AbstractTestSuiteChunkerImpl.java:392)
    at 
org.powermock.modules.junit3.internal.impl.JUnit3TestSuiteChunkerImpl.testA
t(JUnit3TestSuiteChunkerImpl.java:199)
    at org.powermock.modules.junit3.PowerMockSuite.testAt
(PowerMockSuite.java:97)
    at 
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.sendTree
(JUnit3TestReference.java:142)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.sendTrees
(RemoteTestRunner.java:469)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
(RemoteTestRunner.java:457)
    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)

After investigation,I find the class 
org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl seems have 
some problems.I modify its method called initEntries,then it works.

The attchment is the modified class.

btw: I use powermock 1.2.5

Original issue reported on code.google.com by netlogic...@gmail.com on 18 Jun 2009 at 7:00

Attachments:

GoogleCodeExporter commented 9 years ago
The chunking stuff that you've experienced here is a real mess right now and 
we'll
try to rewrite the whole thing till version 1.3. But I'll try to reproduce your 
error
and check-out if your fix works and I'll upload it to trunk in the meantime. 
Thanks you!

Original comment by johan.ha...@gmail.com on 18 Jun 2009 at 10:56

GoogleCodeExporter commented 9 years ago
Won't be fixed in the 1.3 release

Original comment by johan.ha...@gmail.com on 11 Sep 2009 at 6:23

GoogleCodeExporter commented 9 years ago
I have this problem with powermock 1.4.9, mockito 1.8.5 and JUnit3.
Try remove second adnotation: @PrepareForTest( { DbAccess.class}), and it 
should work.

Original comment by mstachniuk on 1 Jul 2011 at 12:56