Class PreserveSystemPropertyRule

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

    public class PreserveSystemPropertyRule
    extends Object
    implements org.junit.rules.TestRule
    Rule which ensures tests that modify system properties doesn't interfere (eg. by concurrently modifying the properties). Additionally it will save modified properties before and restore them after running a test. There are tree ways to mark which tests will modify which properties: - passing list of properties name to the constructor. Then those properties will be preserved for each test in a test class - annotating test method with {@link @com.atlassian.bamboo.testutils.junit.rule.PreserveSystemProperties} - calling PreserveSystemPropertyRule#preserveProperties(SystemProperty... properties)
    • Constructor Detail

      • PreserveSystemPropertyRule

        public PreserveSystemPropertyRule()
      • PreserveSystemPropertyRule

        public PreserveSystemPropertyRule​(String... testClassProperties)
        Parameters:
        testClassProperties - names of System properties to preserve and restore for every test in a test class
    • Method Detail

      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base,
                                                       org.junit.runner.Description description)
        Specified by:
        apply in interface org.junit.rules.TestRule