From 5c049a9e11608be583ddc7090b79167140adeaad Mon Sep 17 00:00:00 2001 From: Vivien Tintillier Date: Thu, 11 Jan 2024 22:02:11 +0000 Subject: [PATCH] add test --- .../properties/SystemPropertiesTest.java | 3 +-- .../jupiter/SystemStubsExtensionTest.java | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/system-stubs-core/src/test/java/uk/org/webcompere/systemstubs/properties/SystemPropertiesTest.java b/system-stubs-core/src/test/java/uk/org/webcompere/systemstubs/properties/SystemPropertiesTest.java index 58a83ae..33feaad 100644 --- a/system-stubs-core/src/test/java/uk/org/webcompere/systemstubs/properties/SystemPropertiesTest.java +++ b/system-stubs-core/src/test/java/uk/org/webcompere/systemstubs/properties/SystemPropertiesTest.java @@ -147,8 +147,7 @@ void settingAfterPreDeleteAlsoWorks() throws Exception { properties.set("bar", "h"); assertThat(System.getProperty("bar")).isEqualTo("h"); - SystemProperties nested = new SystemProperties(); - nested.remove("bar"); + SystemProperties nested = new SystemProperties().remove("bar"); nested.execute(() -> { nested.set("bar", "bong"); assertThat(System.getProperty("bar")).isEqualTo("bong"); diff --git a/system-stubs-jupiter/src/test/java/uk/org/webcompere/systemstubs/jupiter/SystemStubsExtensionTest.java b/system-stubs-jupiter/src/test/java/uk/org/webcompere/systemstubs/jupiter/SystemStubsExtensionTest.java index 46f6fa9..f3719fc 100644 --- a/system-stubs-jupiter/src/test/java/uk/org/webcompere/systemstubs/jupiter/SystemStubsExtensionTest.java +++ b/system-stubs-jupiter/src/test/java/uk/org/webcompere/systemstubs/jupiter/SystemStubsExtensionTest.java @@ -43,6 +43,29 @@ void method3_hasCleanPropertiesAndEnvironment() { } } + @ExtendWith(SystemStubsExtension.class) + @Nested + class SystemPropertiesAsParentClass { + + @SystemStub + private SystemProperties systemProperties = new WithDefaultsSystemProperties() + .set("key1", "value3"); + + @Test + void defaultValuesAreSet() { + assertThat(System.getProperty("key1")).isEqualTo("value3"); + assertThat(System.getProperty("key2")).isEqualTo("value2"); + } + } + + private static class WithDefaultsSystemProperties extends SystemProperties { + + WithDefaultsSystemProperties() { + super("key1", "value1"); + this.set("key2", "value2"); + } + } + @ExtendWith(SystemStubsExtension.class) @Nested class FieldWithoutAnnotation {