mock静态方法步骤
- 使用PowerMockito.mockStatic()
- 加上@RunWith和@PrepareForTest注释
- 如果报错下面的错则考虑加上@PowerMockIgnore
public class Demo {
public static String setName(String name) {
return name;
}
}
@RunWith(PowerMockRunner.class)
@PrepareForTest(RateLimiterMetric.class)
@PowerMockIgnore({"javax.management.*", "javax.script.*"})
public class DemoTest {
@Test
public void testSetName(){
PowerMockito.mockStatic(Demo.class);
String method = "hello";
PowerMockito.when(Demo.setName(method)).thenReturn("hello");
}
}
报错
- ERROR StatusLogger Unable to unregister MBeans
java.lang.LinkageError: javax/management/MBeanServer(具体如下)
解决:加上@PowerMockIgnore("javax.management.*)
D:\Java\java-1.8.0-openjdk-1.8.0.232-3\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:F:\Software\IntelliJ IDEA 2020.2.3\lib\idea_rt.jar=52348:F:\Software\IntelliJ IDEA 2020.2.3\bin" -Dfile.encoding=UTF-8 -classpath "F:\Software\IntelliJ IDEA 2020.2.3\lib\idea_rt.jar;F:\Software\IntelliJ IDEA 2020.2.3\plugins\junit\lib\junit5-rt.jar;F:\Software\IntelliJ IDEA 2020.2.3\plugins\junit\lib\junit-rt.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\charsets.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\ext\access-bridge-64.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\ext\cldrdata.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\ext\dnsns.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\ext\jaccess.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\ext\localedata.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\ext\nashorn.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\ext\sunec.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\ext\sunjce_provider.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\ext\sunmscapi.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\ext\sunpkcs11.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\ext\zipfs.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\jce.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\jsse.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\management-agent.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\resources.jar;D:\Java\java-1.8.0-openjdk-1.8.0.232-3\jre\lib\rt.jar;D:\UserData\admindesktop\课题\cloud_rpc_2.x_v1.0\cloud_rpc_2.x\cloud-rpc-core\target\test-classes;D:\UserData\admindesktop\课题\cloud_rpc_2.x_v1.0\cloud_rpc_2.x\cloud-rpc-core\target\classes;D:\UserData\admindesktop\课题\cloud_rpc_2.x_v1.0\cloud_rpc_2.x\cloud-rpc-common\target\classes;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\tplink\cloud-global-common-utils\2.1.0\cloud-global-common-utils-2.1.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\dropwizard\metrics\metrics-core\3.2.5\metrics-core-3.2.5.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\springframework\retry\spring-retry\1.2.5.RELEASE\spring-retry-1.2.5.RELEASE.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\springframework\spring-core\4.3.22.RELEASE\spring-core-4.3.22.RELEASE.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\tplink\cloud-global-common-checker\1.1.1\cloud-global-common-checker-1.1.1.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\softee\pojo-mbean\1.1\pojo-mbean-1.1.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\jolokia\jolokia-jvm\1.3.1\jolokia-jvm-1.3.1-agent.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\jolokia\jolokia-core\1.3.1\jolokia-core-1.3.1.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\googlecode\json-simple\json-simple\1.1.1\json-simple-1.1.1.jar;D:\UserData\admindesktop\课题\cloud_rpc_2.x_v1.0\cloud_rpc_2.x\cloud-rpc-remote\target\classes;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\logging\log4j\log4j-api\2.17.1\log4j-api-2.17.1.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\logging\log4j\log4j-core\2.17.0\log4j-core-2.17.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\logging\log4j\log4j-slf4j-impl\2.17.0\log4j-slf4j-impl-2.17.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\netty\netty-all\4.1.53.Final\netty-all-4.1.53.Final.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\caucho\hessian\4.0.33\hessian-4.0.33.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\commons\commons-pool2\2.4.3\commons-pool2-2.4.3.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\tplink\cloud-global-api\1.9.3\cloud-global-api-1.9.3.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\tplink\cloud-global-common-errorcode\1.3.0\cloud-global-common-errorcode-1.3.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\thrift\libthrift\0.9.1\libthrift-0.9.1.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\commons\commons-lang3\3.1\commons-lang3-3.1.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\json\json\20140107\json-20140107.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\tplink\cloud-dal-global-api\1.25.17\cloud-dal-global-api-1.25.17.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\tplink\cloud-dal-global-common\1.25.17\cloud-dal-global-common-1.25.17.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\tplink\cloud-global-common-rediscluster\1.4.0\cloud-global-common-rediscluster-1.4.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\redis\clients\jedis\2.9.3\jedis-2.9.3.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\netflix\hystrix\hystrix-core\1.5.12\hystrix-core-1.5.12.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\netflix\archaius\archaius-core\0.4.1\archaius-core-0.4.1.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\commons-configuration\commons-configuration\1.8\commons-configuration-1.8.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\reactivex\rxjava\1.2.0\rxjava-1.2.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\tplink\cloud-global-common-kafka\3.1.0\cloud-global-common-kafka-3.1.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\kafka\kafka-clients\2.0.0\kafka-clients-2.0.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\lz4\lz4-java\1.4.1\lz4-java-1.4.1.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\xerial\snappy\snappy-java\1.1.7.1\snappy-java-1.1.7.1.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\kafka\kafka-streams\2.0.0\kafka-streams-2.0.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\kafka\connect-json\2.0.0\connect-json-2.0.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\kafka\connect-api\2.0.0\connect-api-2.0.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\javax\ws\rs\javax.ws.rs-api\2.1\javax.ws.rs-api-2.1.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\rocksdb\rocksdbjni\5.7.3\rocksdbjni-5.7.3.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\hibernate\hibernate-validator\4.2.0.Final\hibernate-validator-4.2.0.Final.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\zookeeper\zookeeper\3.4.13\zookeeper-3.4.13.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\jline\jline\0.9.94\jline-0.9.94.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\yetus\audience-annotations\0.5.0\audience-annotations-0.5.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\netty\netty\3.10.6.Final\netty-3.10.6.Final.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\tplink\cloud-dubbo\1.1.0\cloud-dubbo-1.1.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\curator\curator-framework\2.12.0\curator-framework-2.12.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\curator\curator-client\2.12.0\curator-client-2.12.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\curator\curator-recipes\2.12.0\curator-recipes-2.12.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\netflix\hystrix\hystrix-javanica\1.5.12\hystrix-javanica-1.5.12.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\aspectj\aspectjrt\1.8.6\aspectjrt-1.8.6.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\aspectj\aspectjweaver\1.8.6\aspectjweaver-1.8.6.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\google\code\findbugs\jsr305\2.0.0\jsr305-2.0.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\netflix\hystrix\hystrix-metrics-event-stream\1.5.12\hystrix-metrics-event-stream-1.5.12.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\netflix\hystrix\hystrix-serialization\1.5.12\hystrix-serialization-1.5.12.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\fasterxml\jackson\module\jackson-module-afterburner\2.7.5\jackson-module-afterburner-2.7.5.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\zipkin\brave\brave-core\4.1.3\brave-core-4.1.3.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\zipkin\java\zipkin\1.19.2\zipkin-1.19.2.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\zipkin\reporter\zipkin-reporter\0.10.0\zipkin-reporter-0.10.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\zipkin\reporter\zipkin-sender-okhttp3\0.10.0\zipkin-sender-okhttp3-0.10.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\squareup\okhttp3\okhttp\3.8.0\okhttp-3.8.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\squareup\okio\okio\1.13.0\okio-1.13.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\dubbo\dubbo\2.7.11\dubbo-2.7.11.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\springframework\spring-context\5.2.8.RELEASE\spring-context-5.2.8.RELEASE.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\springframework\spring-aop\5.2.8.RELEASE\spring-aop-5.2.8.RELEASE.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\springframework\spring-beans\5.2.8.RELEASE\spring-beans-5.2.8.RELEASE.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\springframework\spring-expression\5.2.8.RELEASE\spring-expression-5.2.8.RELEASE.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\alibaba\spring\spring-context-support\1.0.10\spring-context-support-1.0.10.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\google\code\gson\gson\2.8.5\gson-2.8.5.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\yaml\snakeyaml\1.20\snakeyaml-1.20.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\alibaba\fastjson\1.2.70\fastjson-1.2.70.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\tplink\nbu\common\pii\2.0.4\pii-2.0.4.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\bouncycastle\bcprov-jdk15on\1.68\bcprov-jdk15on-1.68.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\jayway\jsonpath\json-path\2.6.0\json-path-2.6.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\net\minidev\json-smart\2.4.7\json-smart-2.4.7.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\net\minidev\accessors-smart\2.4.7\accessors-smart-2.4.7.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\tplink\nbu\common\nbu-common-utils\2.0.4\nbu-common-utils-2.0.4.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\fasterxml\jackson\core\jackson-databind\2.9.10.6\jackson-databind-2.9.10.6.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\commons-codec\commons-codec\1.9\commons-codec-1.9.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\httpcomponents\httpcore\4.4.11\httpcore-4.4.11.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\software\amazon\awssdk\ssm\2.13.51\ssm-2.13.51.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\software\amazon\awssdk\aws-json-protocol\2.13.51\aws-json-protocol-2.13.51.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\fasterxml\jackson\core\jackson-core\2.10.4\jackson-core-2.10.4.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\software\amazon\awssdk\protocol-core\2.13.51\protocol-core-2.13.51.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\software\amazon\awssdk\sdk-core\2.13.51\sdk-core-2.13.51.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\software\amazon\awssdk\profiles\2.13.51\profiles-2.13.51.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\reactivestreams\reactive-streams\1.0.2\reactive-streams-1.0.2.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\software\amazon\awssdk\auth\2.13.51\auth-2.13.51.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\software\amazon\eventstream\eventstream\1.0.1\eventstream-1.0.1.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\software\amazon\awssdk\http-client-spi\2.13.51\http-client-spi-2.13.51.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\software\amazon\awssdk\regions\2.13.51\regions-2.13.51.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\fasterxml\jackson\core\jackson-annotations\2.10.4\jackson-annotations-2.10.4.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\software\amazon\awssdk\annotations\2.13.51\annotations-2.13.51.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\software\amazon\awssdk\utils\2.13.51\utils-2.13.51.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\software\amazon\awssdk\aws-core\2.13.51\aws-core-2.13.51.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\software\amazon\awssdk\apache-client\2.13.51\apache-client-2.13.51.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\apache\httpcomponents\httpclient\4.5.9\httpclient-4.5.9.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\software\amazon\awssdk\netty-nio-client\2.13.51\netty-nio-client-2.13.51.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\netty\netty-codec-http\4.1.46.Final\netty-codec-http-4.1.46.Final.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\netty\netty-codec-http2\4.1.46.Final\netty-codec-http2-4.1.46.Final.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\netty\netty-codec\4.1.46.Final\netty-codec-4.1.46.Final.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\netty\netty-transport\4.1.46.Final\netty-transport-4.1.46.Final.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\netty\netty-resolver\4.1.46.Final\netty-resolver-4.1.46.Final.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\netty\netty-common\4.1.46.Final\netty-common-4.1.46.Final.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\netty\netty-buffer\4.1.46.Final\netty-buffer-4.1.46.Final.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\netty\netty-handler\4.1.46.Final\netty-handler-4.1.46.Final.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\netty\netty-transport-native-epoll\4.1.46.Final\netty-transport-native-epoll-4.1.46.Final-linux-x86_64.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\netty\netty-transport-native-unix-common\4.1.46.Final\netty-transport-native-unix-common-4.1.46.Final.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\typesafe\netty\netty-reactive-streams-http\2.0.4\netty-reactive-streams-http-2.0.4.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\typesafe\netty\netty-reactive-streams\2.0.4\netty-reactive-streams-2.0.4.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\github\resilience4j\resilience4j-circuitbreaker\1.7.1\resilience4j-circuitbreaker-1.7.1.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\vavr\vavr\0.10.2\vavr-0.10.2.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\vavr\vavr-match\0.10.2\vavr-match-0.10.2.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\github\resilience4j\resilience4j-core\1.7.1\resilience4j-core-1.7.1.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\com\google\guava\guava\18.0\guava-18.0.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\easymock\easymock\3.2\easymock-3.2.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\cglib\cglib-nodep\2.2.2\cglib-nodep-2.2.2.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\easymock\easymockclassextension\3.2\easymockclassextension-3.2.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\powermock\powermock-module-junit4\2.0.7\powermock-module-junit4-2.0.7.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\powermock\powermock-module-junit4-common\2.0.7\powermock-module-junit4-common-2.0.7.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\powermock\powermock-reflect\2.0.7\powermock-reflect-2.0.7.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\net\bytebuddy\byte-buddy\1.9.10\byte-buddy-1.9.10.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\net\bytebuddy\byte-buddy-agent\1.9.10\byte-buddy-agent-1.9.10.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\powermock\powermock-core\2.0.7\powermock-core-2.0.7.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\powermock\powermock-api-mockito2\2.0.7\powermock-api-mockito2-2.0.7.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\powermock\powermock-api-support\2.0.7\powermock-api-support-2.0.7.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\mockito\mockito-core\2.28.2\mockito-core-2.28.2.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\objenesis\objenesis\2.6\objenesis-2.6.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\javassist\javassist\3.27.0-GA\javassist-3.27.0-GA.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\net\sourceforge\findbugs\annotations\1.3.2\annotations-1.3.2.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\junit\junit\4.13\junit-4.13.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\org\slf4j\slf4j-api\1.7.2\slf4j-api-1.7.2.jar;D:\tools\Maven\apache-maven-3.5.3\maven_respository\io\prometheus\jmx\jmx_prometheus_javaagent\1.0.3\jmx_prometheus_javaagent-1.0.3.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 com.tplink.cloud.rpc.core.ratelimiter.RateLimiterFilterTest,testRateLimiterInvoke
ERROR StatusLogger Could not reconfigure JMX
java.lang.LinkageError: loader constraint violation: loader (instance of org/powermock/core/classloader/javassist/JavassistMockClassLoader) previously initiated loading for a different type with name "javax/management/MBeanServer"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at org.powermock.core.classloader.javassist.JavassistMockClassLoader.loadUnmockedClass(JavassistMockClassLoader.java:90)
at org.powermock.core.classloader.MockClassLoader.loadClassByThisClassLoader(MockClassLoader.java:104)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass1(DeferSupportingClassLoader.java:147)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:98)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at org.apache.logging.log4j.core.jmx.Server.unregisterAllMatching(Server.java:337)
at org.apache.logging.log4j.core.jmx.Server.unregisterLoggerContext(Server.java:261)
at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:165)
at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:141)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:637)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:699)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:716)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:270)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:137)
at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:55)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:47)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:33)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:270)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)
at com.tplink.cloud.rpc.core.invoker.AbstractClientInvoker.<clinit>(AbstractClientInvoker.java:27)
at sun.reflect.GeneratedSerializationConstructorAccessor5.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:48)
at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:73)
at org.mockito.internal.creation.instance.ObjenesisInstantiator.newInstance(ObjenesisInstantiator.java:19)
at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:47)
at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25)
at org.powermock.api.mockito.mockmaker.PowerMockMaker.createMock(PowerMockMaker.java:41)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:62)
at org.mockito.Mockito.mock(Mockito.java:1908)
at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.createMethodInvocationControl(DefaultMockCreator.java:108)
at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.doCreateMock(DefaultMockCreator.java:61)
at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.createMock(DefaultMockCreator.java:53)
at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.mock(DefaultMockCreator.java:40)
at org.powermock.api.mockito.PowerMockito.mock(PowerMockito.java:126)
at com.tplink.cloud.rpc.core.ratelimiter.RateLimiterFilterTest.testRateLimiterInvoke(RateLimiterFilterTest.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:68)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:326)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:89)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:97)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:310)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:131)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.access$100(PowerMockJUnit47RunnerDelegateImpl.java:59)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner$TestExecutorStatement.evaluate(PowerMockJUnit47RunnerDelegateImpl.java:147)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.evaluateStatement(PowerMockJUnit47RunnerDelegateImpl.java:107)
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:298)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:50)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:218)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:160)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:134)
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:136)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:117)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:57)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
stat.ratelimit.service.hello1
ERROR StatusLogger Unable to unregister MBeans
java.lang.LinkageError: javax/management/MBeanServer
at org.apache.logging.log4j.core.jmx.Server.unregisterAllMatching(Server.java:337)
at org.apache.logging.log4j.core.jmx.Server.unregisterLoggerContext(Server.java:261)
at org.apache.logging.log4j.core.jmx.Server.unregisterLoggerContext(Server.java:249)
at org.apache.logging.log4j.core.LoggerContext.stop(LoggerContext.java:379)
at org.apache.logging.log4j.core.LoggerContext$1.run(LoggerContext.java:320)
at org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry$RegisteredCancellable.run(DefaultShutdownCallbackRegistry.java:119)
at org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry.run(DefaultShutdownCallbackRegistry.java:78)
at java.lang.Thread.run(Thread.java:748)
Process finished with exit code 0
- ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider jdk.nashorn.api.scripting.NashornScriptEngineFactory not a subtype(具体如下)
解决:加上@PowerMockIgnore("javax.script.*)
文章来源地址https://www.toymoban.com/news/detail-554909.html
文章来源:https://www.toymoban.com/news/detail-554909.html
到了这里,关于非Springboot项目使用powermockito单元测试 mock静态方法和ScriptEngineManager providers.next()...not a subtype报错解决的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!