Class SystemPropertyOverrides

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class SystemPropertyOverrides
    extends java.lang.Object
    implements java.lang.AutoCloseable
    Utility to make it easier for tests to override system properties (instead of directly using System.setProperty(String, String)). By using this class within try-with-resources, the test can be assured that any property set will be restored to its initial state after the test completes (success & failure).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void setProperty​(java.lang.String key, java.lang.String value)
      Sets a system property (by calling System.setProperty(String, String)) while backing up the original value and replacing it once this class is closed.
      • Methods inherited from class java.lang.Object

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

      • SystemPropertyOverrides

        public SystemPropertyOverrides()
    • Method Detail

      • setProperty

        public void setProperty​(@NonNull
                                java.lang.String key,
                                java.lang.String value)
        Sets a system property (by calling System.setProperty(String, String)) while backing up the original value and replacing it once this class is closed.
      • close

        public void close()
                   throws java.lang.Exception
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.lang.Exception