当前位置: 首页 > 知识库问答 >
问题:

如何解决此错误“java.lang.RuntimeException:PowerMock内部错误:不应在此级别引发异常”

姚雅珺
2023-03-14
java.lang.RuntimeException: PowerMock internal error: Should never throw exception at this level
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.handleException(PowerMockJUnit44RunnerDelegateImpl.java:384)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.evaluateStatement(PowerMockJUnit47RunnerDelegateImpl.java:110)
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$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

原因:mpl.java:1482无法使受保护的本机org.powermock.reflect.internal.对象mpl.findOmpl.java:862()抛出org.powermock.reflect.internal.CloneNotSupport异常可访问:模块mpl.do不会打开mpl.java:822到未命名的模块@5be6e01c在org.powermock.reflect.internal.(AccessibleOmpl.invoke)在mpl.java:690(AccessibleOorg.powermock.reflect.)在hitebox.invoke(Mhitebox.java:401)在java.base/java.lang.reflect.Method.setAccessible(Method.java:193)在org.powermock.reflect.internal.WhiteboxImpl.doGetAll方法(WhiteboxImpl.java:1508)在org.powermock.reflect.internal.WhiteboxImpl.getAll方法(WhiteboxIjava.lang.reflect.)在java.lang.WhiteboxIjava.lang.方法OrThrowException(WhiteboxIbject.clone)在java.lang.WhiteboxIjava.baseInvokeMethod(WhiteboxIjava.lang)在java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessibleWhiteboxIbject.java:354方法(WhiteboxIjava.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible)在bject.java:297Wjava.base/java.lang.reflect.Method.checkCanSetAccessible方法(Wethod.java:199)在org. powermock. annit4。

进程已完成,退出代码为-2

java.lang.reflect.无法使受保护的本机java.lang.对象java.lang.Object.clone()抛出java.lang.CloneNotSupport异常可访问:模块java.base不会打开java.lang未命名模块@6d21714c

at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
at org.powermock.reflect.internal.WhiteboxImpl.doGetAllMethods(WhiteboxImpl.java:1508)
at org.powermock.reflect.internal.WhiteboxImpl.getAllMethods(WhiteboxImpl.java:1482)
at org.powermock.reflect.internal.WhiteboxImpl.findMethodOrThrowException(WhiteboxImpl.java:862)
at org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:822)
at org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:805)
at org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:466)
at org.powermock.modules.junit4.common.internal.impl.PowerMockJUnit4RunListener.testFinished(PowerMockJUnit4RunListener.java:55)
at org.junit.runner.notification.SynchronizedRunListener.testFinished(SynchronizedRunListener.java:87)
at org.junit.runner.notification.RunNotifier$9.notifyListener(RunNotifier.java:225)
at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:72)
at org.junit.runner.notification.RunNotifier.fireTestFinished(RunNotifier.java:222)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:53)
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$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)




import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;

import java.util.ArrayList;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest({ SystemUnderTest.class /*To be able to mock the Constructor, we need to add in the Class that creates the new object*/})
@PowerMockIgnore({"javax.management.*", "javax.xml.*", "org.xml.sax.*", "org.w3c.dom.*", "org.springframework.context.*", "org.apache.log4j.*", "org.apache.commons.logging.*", "org.jacoco.*", "jdk.internal.reflect.*"})
public class PowerMockitoMockingConstructorTest {

    private static final int SOME_DUMMY_SIZE = 100;

    @Mock
    Dependency dependencyMock;

    @InjectMocks
    SystemUnderTest systemUnderTest;

    @Test
    public void powerMockito_MockingAConstructor() throws Exception {

        ArrayList<String> mockList = mock(ArrayList.class);

        stub(mockList.size()).toReturn(SOME_DUMMY_SIZE);

        PowerMockito.whenNew(ArrayList.class).withAnyArguments().thenReturn(
                mockList);

        int size = systemUnderTest.methodUsingAnArrayListConstructor();

        assertEquals(SOME_DUMMY_SIZE, size);
    }
}

共有1个答案

金昂熙
2023-03-14

对我来说,这解决了问题:我将IntelliJ中的SDK更改为Java 8。

 类似资料:
  • 问题内容: 我在下一行出现错误。我正在做添加到jsonarray的过程。请帮我。 问题答案: 这是我在重新编程时经常遇到的错误。此异常的原因或细节非常清楚。不允许在迭代时修改集合(正在添加新元素)。至少不支持语法。 为了解决您的问题,我认为有两种方法很简单。 1)。而不是使用语句来循环,更好的方法是使用迭代器来避免ConcurrentModificationException。 2)。在循环播放时

  • 错误-mssql08(系统找不到指定的文件)java.io.FileNotFoundException:mssql08(系统找不到指定的文件)在java.io.FileInputStream.Open0(本机方法)

  • 错误是: 错误:元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。您可能忘记了从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。 在App.js:22检查你的代码。在应用程序中(由ExpoRoot创建)在ExpoRoot中(位于renderApplication.js:45)在RCTView中(位于View.js:34)在视图中(位于AppConta

  • org.gradle.execution.multipleBuildFailures:生成完成,失败1次。 在org.gradle.initialization.defaultgradlelauncher$executeTasks.run(DefaultG radlelauncher.java:358)

  • 我是android studio的新手,我不明白为什么我的应用程序在开始使用seekbar时会崩溃。谁能帮帮我吗? 公共类MainActivity扩展了AppCompatActivity{SeekBar SeekBar;//声明SeekBar对象TextView TextView,textView2;ListView simpleListview;//声明SeekBar int离散的成员变量;in

  • 问题内容: 我在做xpath搜索 这为我提供了Firebug中所需的第一类项目,但显然python不允许我将[1]添加到find函数中。有什么解决方法吗?搜索返回2个项目,我只想要一个。我要解决这个错误吗? 问题答案: 与大多数Selenium WebDriver绑定一样,如果仅指定“ element”,则将仅返回找到的第一个元素。但是,如果在方法中指定“元素”,它将返回找到的元素数组。 因此,您