title: How to test different instances of java singleton in Junit
body: <p>I currently have Java singleton which reads some system properties when instantiated. In the production situation these system properties will be static, so once the JVM is restarted the system properties do not need to be changed. </p>
  
  <pre><code>public final class SoaJSONLogger {
  
      private static final String SCHEMA_PROPERTY = "com.reddipped.soa.jsonlogger.schema";
      private static final String SCHEMA_STRICT = "com.reddipped.soa.jsonlogger.strict";
      private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
      private final com.reddipped.soa.jsonlogger.JSONLogger LOGGER;
      private final Pattern fieldValuePattern = Pattern.compile("(\\w+)=(.+)");
      private final String schemaName;
      private final Boolean strictSchema;
  
      /**
       * Logging level
       *
       * TRACE (least serious) DEBUG INFO WARNING ERROR (most serious)
       *
       */
      public static enum LEVEL {
          ERROR, WARN, INFO, DEBUG, TRACE
      };
  
      private static class JSONLoggerLoader {
          private static final SoaJSONLogger INSTANCE = new SoaJSONLogger();
      }
  
      private SoaJSONLogger() {
  
          if (JSONLoggerLoader.INSTANCE != null) {
              throw new IllegalStateException("Already instantiated");
          }
  
          // Get schema name and strict settings 
          this.schemaName = System.getProperty(SoaJSONLogger.SCHEMA_PROPERTY);
          this.strictSchema = (System.getProperty("com.reddipped.soa.jsonlogger.strict") != null
              &amp;&amp; System.getProperty(SoaJSONLogger.SCHEMA_STRICT).equalsIgnoreCase("true"));
  
          if (this.schemaName != null) {
              this.LOGGER = JSONLogger.getLogger("JSONLogger", DATE_TIME_FORMAT, this.schemaName, this.strictSchema);
          } else {
              throw new IllegalArgumentException("Schema property " + SoaJSONLogger.SCHEMA_PROPERTY + " not set");
          }
  
      }
  
      public static SoaJSONLogger getInstance() {
          return JSONLoggerLoader.INSTANCE;
      }
  
      public void trace(String xmlLog) {
          this.LOGGER.xml(xmlLog).trace();
      }
  
      public void debug(String xmlLog) {
          this.LOGGER.xml(xmlLog).debug();
      }
  
      public void info(String xmlLog) {
          this.LOGGER.xml(xmlLog).info();
      }
  
      public void warn(String xmlLog) {
          this.LOGGER.xml(xmlLog).warn();
      }
  
      public void error(String xmlLog) {
          this.LOGGER.xml(xmlLog).error();
      }
  }
  </code></pre>
  
  <p>I need to test different values for the system properties. What is the best way to do this in JUnit without having to modify the Java class ? I need in some way to create a new instance of the class for each JUnit test.</p>