powermock / powermock

PowerMock is a Java framework that allows you to unit test code normally regarded as untestable.
Apache License 2.0
4.16k stars 586 forks source link

powermock2.0.2 fail for NoSuchMethodError InvocationFactory.createInvocation(java.lang.Object, org.mockito.mock.MockCreationSettings, java.lang.reflect.Method, java.util.concurrent.Callable, java.lang.Object[])' #1125

Open liweiye-2021 opened 2 years ago

liweiye-2021 commented 2 years ago

dependency:

<dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>2.0.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito2</artifactId>
            <version>2.0.2</version>
            <scope>test</scope>
        </dependency>

sample:

@RunWith(PowerMockRunner.class)
@PowerMockIgnore({ "javax.management.*","jdk.internal.reflect.*" })
@PrepareForTest({ TradeDateUtils.class })
@SuppressStaticInitializationFor("com.ubssdic.ufos.framework.utils.TradeDateUtils") // 
public class TestOne {

    @Test
    public void test11() throws Throwable {
        PowerMockito.mockStatic(TradeDateUtils.class);
        PowerMockito.when(TradeDateUtils.queryDayTradeOffset(anyString(), anyInt())).thenReturn("2021-12-01");
        Assert.assertEquals("2021-12-01", TradeDateUtils.queryDayTradeOffset("",1));
    }
}

Java17

java.lang.NoSuchMethodError: 'org.mockito.invocation.Invocation org.mockito.invocation.InvocationFactory.createInvocation(java.lang.Object, org.mockito.mock.MockCreationSettings, java.lang.reflect.Method, java.util.concurrent.Callable, java.lang.Object[])'

at org.powermock.api.mockito.invocation.InvocationFactory.createInvocation(InvocationFactory.java:41)
at org.powermock.api.mockito.invocation.MockHandlerAdaptor.createInvocation(MockHandlerAdaptor.java:81)
at org.powermock.api.mockito.invocation.MockHandlerAdaptor.performIntercept(MockHandlerAdaptor.java:61)
at org.powermock.api.mockito.invocation.MockitoMethodInvocationControl.invoke(MockitoMethodInvocationControl.java:93)
at org.powermock.core.MockGateway.doMethodCall(MockGateway.java:186)
at org.powermock.core.MockGateway.doMethodCall(MockGateway.java:168)
at org.powermock.core.MockGateway.methodCall(MockGateway.java:145)
at com.weiye.util.TradeDateUtils.queryDayTradeOffset(TradeDateUtils.java)
liweiye-2021 commented 2 years ago

image

image

the method is deprecated in version 3.XX,is removed in version 4.0

nmorkar commented 2 years ago

having same issue, any workaround to fix it?

nmorkar commented 2 years ago

Seems fix in this PR - https://github.com/powermock/powermock/pull/1113/files When this PR is expected to merge and release?

class101 commented 2 years ago

2-3 more years probably ...

yassir78 commented 2 years ago

Hello , did you find the solution for the error or not ?

liweiye-2021 commented 2 years ago

No,as nmorkar say,no one release this PR - https://github.com/powermock/powermock/pull/1113/files

yassir78 commented 2 years ago

The only solution is to migrate and use mockito inline

liweiye-2021 commented 2 years ago

Thanks,I will try do it