From df7f8c8af291ecf4dfdb7882c230e2f1c8efd1cd Mon Sep 17 00:00:00 2001 From: Tianyao Chen Date: Fri, 26 May 2023 01:17:33 -0700 Subject: [PATCH] Add a test case for SystemPropertiesTest.java (#8034) Add a test case --- .../java/jenkins/util/SystemPropertiesTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/src/test/java/jenkins/util/SystemPropertiesTest.java b/test/src/test/java/jenkins/util/SystemPropertiesTest.java index 076bd4991e..4a0a2a78e9 100644 --- a/test/src/test/java/jenkins/util/SystemPropertiesTest.java +++ b/test/src/test/java/jenkins/util/SystemPropertiesTest.java @@ -31,6 +31,7 @@ import static org.hamcrest.Matchers.nullValue; import javax.servlet.ServletContextEvent; import org.eclipse.jetty.server.handler.ContextHandler; import org.hamcrest.Matchers; +import org.junit.After; import org.junit.Assume; import org.junit.Before; import org.junit.Rule; @@ -51,6 +52,12 @@ public class SystemPropertiesTest { new SystemProperties.Listener().contextInitialized(new ServletContextEvent(j.jenkins.servletContext)); } + @After + public void tearDown() { + System.clearProperty("foo.bar"); + } + + @Test public void shouldReturnNullIfUndefined() throws Exception { assertThat("Properties should be null by default", @@ -81,6 +88,15 @@ public class SystemPropertiesTest { SystemProperties.getString("install-wizard-path"), equalTo("myVal2")); } + @Test + public void shouldReturnWebAppPropertyIfSystemPropertyNotSetAndDefaultIsSet() throws Exception { + assertThat("Property is undefined before test", + SystemProperties.getString("foo.bar"), equalTo(null)); + setWebAppInitParameter("foo.bar", "myVal"); + assertThat("Should return web app property if system property is not set and default value is set", + SystemProperties.getString("foo.bar", "defaultVal"), equalTo("myVal")); + } + /** * Hack to set a web app initial parameter afterwards. Only works with Jetty. * @param property property to set