gpt4 book ai didi

java - 模拟静态 block (错误 : java. lang.IllegalStateException)

转载 作者:行者123 更新时间:2023-11-30 05:28:40 27 4
gpt4 key购买 nike

Error: java.lang.IllegalStateException: Unable to load cache item

模拟静态 block

当模拟正在扩展具有静态 block 的父类(super class)的类的静态方法时,会发生这种情况。

java.lang.IllegalStateException:无法加载缓存项

at org.easymock.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:79)
at org.easymock.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
at org.easymock.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116)
at org.easymock.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291)
at org.easymock.cglib.proxy.Enhancer.createHelper(Enhancer.java:480)
at org.easymock.cglib.proxy.Enhancer.createClass(Enhancer.java:337)
at org.easymock.internal.ClassProxyFactory.createProxy(ClassProxyFactory.java:173)
at org.easymock.internal.MocksControl.createMock(MocksControl.java:116)
at org.easymock.internal.MocksControl.createMock(MocksControl.java:95)
at org.powermock.api.easymock.PowerMock.doCreateMock(PowerMock.java:2023)
at org.powermock.api.easymock.PowerMock.doMock(PowerMock.java:1970)
at org.powermock.api.easymock.PowerMock.mockStatic(PowerMock.java:259)

最佳答案

PowerMock @SuppressStaticInitialization fixed the issue.

Note: You must not pass the class name but a fully qualified name of class in parameter of @SuppressStaticInitialization

e.g.

@RunWith(PowerMockRunner.class)
@PrepareForTest({staticClassExample.class}
@SuppressStaticInitialization("com.services.ClassWithStaticBlockInitialization")
public class ClassNameTest {
...
}

关于java - 模拟静态 block (错误 : java. lang.IllegalStateException),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58012503/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com