1
0

New test case for additional PathableTestSuite functionality.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@209413 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Simon Kitching
2005-07-06 06:26:02 +00:00
parent 4a0c892957
commit c542c21c29

View File

@@ -0,0 +1,86 @@
/*
* Copyright 2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging.pathable;
import java.net.URL;
import java.util.Enumeration;
import java.util.ArrayList;
import java.net.URLClassLoader;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.PathableClassLoader;
/**
* Tests for the PathableTestSuite class.
*/
public class GeneralTestCase extends TestCase {
/**
* Set up a custom classloader hierarchy for this test case.
*/
public static Test suite() throws Exception {
Class thisClass = GeneralTestCase.class;
ClassLoader thisClassLoader = thisClass.getClassLoader();
PathableClassLoader loader = new PathableClassLoader(null);
loader.useExplicitLoader("junit.", thisClassLoader);
loader.addLogicalLib("testclasses");
// reload this class via the child classloader
Class testClass = loader.loadClass(thisClass.getName());
// and return our custom TestSuite class
return new PathableTestSuite(testClass, loader);
}
/**
* Verify that a certain system property is not set, then set it.
*/
private static void checkAndSetProperties() {
String prop = System.getProperty("no.such.property");
assertNull("no.such.property is unexpectedly defined", prop);
System.setProperty("no.such.property", "dummy value");
prop = System.getProperty("no.such.property");
assertNotNull("no.such.property is unexpectedly undefined", prop);
}
/**
* Verify that when a test method modifies the system properties they are
* reset before the next test is run.
* <p>
* This method works in conjunction with testResetProps2. There is no
* way of knowing which test method junit will run first, but it doesn't
* matter; whichever one of them runs first will modify the system properties.
* If the PathableTestSuite isn't resetting the system properties then whichever
* of them runs second will fail. Of course if other methods are run in-between
* then those methods might also fail...
*/
public void testResetProps1() {
checkAndSetProperties();
}
/**
* See testResetProps1.
*/
public void testResetProps2() {
checkAndSetProperties();
}
}