Got ExceptionInInitializerError when mocking constructor of a class with Powermock. How to fix it?

♀尐吖头ヾ 提交于 2019-12-05 05:33:44

You could use then:

 @SuppressStaticInitializationFor({AbstractController.class})

And then, in your test case, set manually all static fields that need to be initialized, including the DEFAULT_FOLDER:

Whitebox.setInternalState(Controller.class, "DEFAULT_FOLDER", "abcd");
Whitebox.setInternalState(Controller.class, "OTHER_FIELD", new Object());

The method Class<?>.getProtectionDomain() depends too much on class loader used, so you probably won't get it to work in JUnit/PowerMock, which use their own.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!