Mockito mock of SecurityManager throwing an exception

前端 未结 2 741
逝去的感伤
逝去的感伤 2021-01-07 06:33

I\'m trying to mock the SecurityManager class. When I run the following code, Mockito throws an exception:

@After
public void tearDown()
{
             


        
2条回答
  •  醉梦人生
    2021-01-07 07:17

    When you change the SecurityManager, you should reset it to the original SecurityManager after the test.

    You may use the System Rules library for your test. Setting and resetting the security manager are just two lines of code with this rule.

    @Rule
    public ProvideSecurityManager provideSecurityManager
      = new ProvideSecurityManager(yourSecurityManager);
    

    Within your test yourSecurityManager is used and outside of the test the original security manager is used.

提交回复
热议问题