Class ProvideSecurityManager

java.lang.Object
org.junit.rules.ExternalResource
org.junit.contrib.java.lang.system.ProvideSecurityManager
All Implemented Interfaces:
org.junit.rules.TestRule

public class ProvideSecurityManager extends org.junit.rules.ExternalResource
The ProvideSecurityManager rule provides an arbitrary security manager to a test. After the test the original security manager is restored.
   public void MyTest {
     private final MySecurityManager securityManager
       = new MySecurityManager();

     @Rule
     public final ProvideSecurityManager provideSecurityManager
       = new ProvideSecurityManager(securityManager);

     @Test
     public void overrideProperty() {
       assertEquals(securityManager, System.getSecurityManager());
     }
   }
 
  • Field Details

  • Constructor Details

    • ProvideSecurityManager

      public ProvideSecurityManager(SecurityManager manager)
  • Method Details

    • before

      protected void before() throws Throwable
      Overrides:
      before in class org.junit.rules.ExternalResource
      Throws:
      Throwable
    • after

      protected void after()
      Overrides:
      after in class org.junit.rules.ExternalResource