### Question:
ScopedSystemProperties { public static PropertyEnvironment newPropertyEnvironment() { return new PropertyEnvironment(); } private  ScopedSystemProperties(); static PropertyEnvironment newPropertyEnvironment();  }### Answer:
@Test void onlySeesScopedValueWithinScope() { try (PropertyEnvironment env = ScopedSystemProperties.newPropertyEnvironment()) { env.setProperty("scopedKey", "scopedValue"); assertThatSystemPropertyHasValue("scopedKey", "scopedValue"); } assertThatSystemPropertyHasValue("scopedKey", null); }
@Test void otherThreadDoesNotSeeScopedValue() throws Exception { CountDownLatch setupLatch = new CountDownLatch(1); CountDownLatch assertionLatch = new CountDownLatch(1); new Thread(() -> { try { setupLatch.await(1, TimeUnit.MINUTES); } catch (InterruptedException e) { throw new AssertionError(e); } assertThatSystemPropertyHasValue("scopedKey", null); assertionLatch.countDown(); }, "outside scope").start(); try (PropertyEnvironment env = ScopedSystemProperties.newPropertyEnvironment()) { env.setProperty("scopedKey", "scopedValue"); setupLatch.countDown(); assertThatSystemPropertyHasValue("scopedKey", "scopedValue"); } assertionLatch.await(1, TimeUnit.MINUTES); assertThatSystemPropertyHasValue("scopedKey", null); }
@Test void booleanMethodUsesScopedValue() { try (PropertyEnvironment env = ScopedSystemProperties.newPropertyEnvironment()) { env.setProperty("scopedKey", "true"); assertThat(Boolean.getBoolean("scopedKey")).isTrue(); } assertThatSystemPropertyHasValue("scopedKey", null); }