From 4a0c89295784aebf94cc807df7577eedff8235f2 Mon Sep 17 00:00:00 2001 From: Simon Kitching Date: Wed, 6 Jul 2005 06:19:32 +0000 Subject: [PATCH] Save and restore system properties around tests. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@209412 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/logging/PathableTestSuite.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/test/org/apache/commons/logging/PathableTestSuite.java b/src/test/org/apache/commons/logging/PathableTestSuite.java index 48588a7..5ba8483 100644 --- a/src/test/org/apache/commons/logging/PathableTestSuite.java +++ b/src/test/org/apache/commons/logging/PathableTestSuite.java @@ -16,6 +16,7 @@ package org.apache.commons.logging; +import java.util.Properties; import junit.framework.Test; import junit.framework.TestSuite; import junit.framework.TestResult; @@ -66,7 +67,9 @@ import junit.framework.TestResult; * * This class ensures that any context classloader changes applied by a test * is undone after the test is run, so tests don't need to worry about - * restoring the context classloader on exit. + * restoring the context classloader on exit. This class also ensures that + * the system properties are restored to their original settings after each + * test, so tests that manipulate those don't need to worry about resetting them. *

* This class does not provide facilities for manipulating system properties; * tests that need specific system properties can simply set them in the @@ -114,13 +117,18 @@ public class PathableTestSuite extends TestSuite { * This method is invoked once for each Test in the current TestSuite. * Note that a Test may itself be a TestSuite object (ie a collection * of tests). + *

+ * The context classloader and system properties are saved before each + * test, and restored after the test completes to better isolate tests. */ public void runTest(Test test, TestResult result) { ClassLoader origContext = Thread.currentThread().getContextClassLoader(); + Properties oldSysProps = (Properties) System.getProperties().clone(); try { Thread.currentThread().setContextClassLoader(contextLoader); test.run(result); } finally { + System.setProperties(oldSysProps); Thread.currentThread().setContextClassLoader(origContext); } }