Class SystemPropertiesRestoreRule

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    public class SystemPropertiesRestoreRule
    extends java.lang.Object
    implements org.junit.rules.TestRule
    A TestRule which restores system properties from before the nested Statement. This rule requires appropriate security permission to read and write system properties (System.getProperties()) if running under a security manager.
    See Also:
    SystemPropertiesInvariantRule, ClassRule, Rule
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.HashSet<java.lang.String> ignoredProperties
      Ignored property keys.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement s, org.junit.runner.Description d)  
      private static java.util.TreeMap<java.lang.String,​java.lang.String> cloneAsMap​(java.util.Properties properties)  
      (package private) static void restore​(java.util.TreeMap<java.lang.String,​java.lang.String> before, java.util.TreeMap<java.lang.String,​java.lang.String> after, java.util.Set<java.lang.String> ignoredKeys)  
      (package private) static java.util.TreeMap<java.lang.String,​java.lang.String> systemPropertiesAsMap()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ignoredProperties

        private final java.util.HashSet<java.lang.String> ignoredProperties
        Ignored property keys.
    • Constructor Detail

      • SystemPropertiesRestoreRule

        public SystemPropertiesRestoreRule()
        Restores all properties.
      • SystemPropertiesRestoreRule

        public SystemPropertiesRestoreRule​(java.util.Set<java.lang.String> ignoredProperties)
        Parameters:
        ignoredProperties - Properties that will be ignored (and will not be restored).
      • SystemPropertiesRestoreRule

        public SystemPropertiesRestoreRule​(java.lang.String... ignoredProperties)
        Parameters:
        ignoredProperties - Properties that will be ignored (and will not be restored).
    • Method Detail

      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement s,
                                                       org.junit.runner.Description d)
        Specified by:
        apply in interface org.junit.rules.TestRule
      • cloneAsMap

        private static java.util.TreeMap<java.lang.String,​java.lang.String> cloneAsMap​(java.util.Properties properties)
      • restore

        static void restore​(java.util.TreeMap<java.lang.String,​java.lang.String> before,
                            java.util.TreeMap<java.lang.String,​java.lang.String> after,
                            java.util.Set<java.lang.String> ignoredKeys)
      • systemPropertiesAsMap

        static java.util.TreeMap<java.lang.String,​java.lang.String> systemPropertiesAsMap()