我正在尝试在 Eclipse 中运行 junits 案例。我在本地面临以下错误,在更高的环境中运行时我们没有遇到任何问题。我使用的版本是-mockito-all-1.10.19、javassist-3.24.0-GA 和 powermock-mockito-release-full-1.6.4-full。我还观察到我们没有模拟 CloseableHttpClient 的类工作正常,这意味着没有 http 调用工作正常。知道如何解决这个问题吗?
类的顶部
@RunWith(PowerMockRunner.class)
@PrepareForTest({HttpClientBuilder.class,
PoolingHttpClientConnectionManager.class,Registry.class})
@SuppressStaticInitializationFor({ "com.yantra.yfs.core.YFSSystem" ,
"org.apache.http.client.config.RequestConfig",
"org.apache.http.conn.ssl.SSLConnectionSocketFactory","org.apache.http.impl.client.HttpClients","org.apache.http.impl.client.HttpClientBuilder","org.apache.http.config.Registry","org.apache.http.config.RegistryBuilder","org.apache.http.HttpEntity"})
堆栈跟踪-
java.lang.IllegalStateException: Failed to transform class with name org.apache.http.impl.client.HttpClientBuilder. Reason: by javassist.bytecode.BadBytecode: build ()Lorg/apache/http/impl/client/CloseableHttpClient; in org.apache.http.impl.client.HttpClientBuilder: inconsistent stack height null
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:267)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:180)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:70)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2575)
at java.lang.Class.getDeclaredFields(Class.java:1908)
at org.powermock.reflect.internal.WhiteboxImpl.getField(WhiteboxImpl.java:170)
at org.powermock.core.MockGateway.fieldCall(MockGateway.java:221)
at com.walmart.ecommerce.oms.business.flexe.GetEcomResponseTest.testScenario4(GetEcomResponseTest.java:215)
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:483)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: javassist.CannotCompileException: by javassist.bytecode.BadBytecode: build ()Lorg/apache/http/impl/client/CloseableHttpClient; in org.apache.http.impl.client.HttpClientBuilder: inconsistent stack height null
at javassist.CtBehavior.insertBefore(CtBehavior.java:809)
at javassist.CtBehavior.insertBefore(CtBehavior.java:766)
at org.powermock.core.transformers.impl.MainMockTransformer.modifyMethod(MainMockTransformer.java:197)
at org.powermock.core.transformers.impl.MainMockTransformer.allowMockingOfStaticAndFinalAndNativeMethods(MainMockTransformer.java:133)
at org.powermock.core.transformers.impl.MainMockTransformer.transform(MainMockTransformer.java:65)
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:252)
... 22 more
Caused by: javassist.bytecode.BadBytecode: build
()Lorg/apache/http/impl/client/CloseableHttpClient; in org.apache.http.impl.client.HttpClientBuilder: inconsistent stack height null
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:119)
at javassist.bytecode.MethodInfo.rebuildStackMap(MethodInfo.java:458)
at javassist.bytecode.MethodInfo.rebuildStackMapIf6(MethodInfo.java:440)
at javassist.CtBehavior.insertBefore(CtBehavior.java:800)
... 27 more