From b69deb90ddf58273d70feb5fc74bb7158baf6d48 Mon Sep 17 00:00:00 2001 From: Simon Kitching Date: Wed, 6 Jul 2005 06:28:24 +0000 Subject: [PATCH] Move duplicated testResetContext tests out of ParentFirst and ChildFirst into GeneralTestCase. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@209414 13f79535-47bb-0310-9956-ffa450edef68 --- .../logging/pathable/ChildFirstTestCase.java | 36 ------------------- .../logging/pathable/GeneralTestCase.java | 36 +++++++++++++++++++ .../logging/pathable/ParentFirstTestCase.java | 36 ------------------- 3 files changed, 36 insertions(+), 72 deletions(-) diff --git a/src/test/org/apache/commons/logging/pathable/ChildFirstTestCase.java b/src/test/org/apache/commons/logging/pathable/ChildFirstTestCase.java index d46f700..124d130 100644 --- a/src/test/org/apache/commons/logging/pathable/ChildFirstTestCase.java +++ b/src/test/org/apache/commons/logging/pathable/ChildFirstTestCase.java @@ -281,40 +281,4 @@ public class ChildFirstTestCase extends TestCase { // but with different contents. That's a little tricky to set up so we'll // skip that for now. } - - /** - * Verify that the context classloader is a custom one, then reset it to - * a non-custom one. - */ - private static void checkAndSetContext() { - ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); - assertEquals("ContextLoader is of unexpected type", - contextLoader.getClass().getName(), - PathableClassLoader.class.getName()); - - URL[] noUrls = new URL[0]; - Thread.currentThread().setContextClassLoader(new URLClassLoader(noUrls)); - } - - /** - * Verify that when a test method modifies the context classloader it is - * reset before the next test is run. - *

- * This method works in conjunction with testResetContext2. 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 contextClassloader. - * If the PathableTestSuite isn't resetting the contextClassLoader 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 testResetContext1() { - checkAndSetContext(); - } - - /** - * See testResetContext1. - */ - public void testResetContext2() { - checkAndSetContext(); - } } diff --git a/src/test/org/apache/commons/logging/pathable/GeneralTestCase.java b/src/test/org/apache/commons/logging/pathable/GeneralTestCase.java index 1cb0090..8a6fd80 100644 --- a/src/test/org/apache/commons/logging/pathable/GeneralTestCase.java +++ b/src/test/org/apache/commons/logging/pathable/GeneralTestCase.java @@ -83,4 +83,40 @@ public class GeneralTestCase extends TestCase { public void testResetProps2() { checkAndSetProperties(); } + + /** + * Verify that the context classloader is a custom one, then reset it to + * a non-custom one. + */ + private static void checkAndSetContext() { + ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); + assertEquals("ContextLoader is of unexpected type", + contextLoader.getClass().getName(), + PathableClassLoader.class.getName()); + + URL[] noUrls = new URL[0]; + Thread.currentThread().setContextClassLoader(new URLClassLoader(noUrls)); + } + + /** + * Verify that when a test method modifies the context classloader it is + * reset before the next test is run. + *

+ * This method works in conjunction with testResetContext2. 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 contextClassloader. + * If the PathableTestSuite isn't resetting the contextClassLoader 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 testResetContext1() { + checkAndSetContext(); + } + + /** + * See testResetContext1. + */ + public void testResetContext2() { + checkAndSetContext(); + } } diff --git a/src/test/org/apache/commons/logging/pathable/ParentFirstTestCase.java b/src/test/org/apache/commons/logging/pathable/ParentFirstTestCase.java index a27d0d8..6407442 100644 --- a/src/test/org/apache/commons/logging/pathable/ParentFirstTestCase.java +++ b/src/test/org/apache/commons/logging/pathable/ParentFirstTestCase.java @@ -278,40 +278,4 @@ public class ParentFirstTestCase extends TestCase { // but with different contents. That's a little tricky to set up so we'll // skip that for now. } - - /** - * Verify that the context classloader is a custom one, then reset it to - * a non-custom one. - */ - private static void checkAndSetContext() { - ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); - assertEquals("ContextLoader is of unexpected type", - contextLoader.getClass().getName(), - PathableClassLoader.class.getName()); - - URL[] noUrls = new URL[0]; - Thread.currentThread().setContextClassLoader(new URLClassLoader(noUrls)); - } - - /** - * Verify that when a test method modifies the context classloader it is - * reset before the next test is run. - *

- * This method works in conjunction with testResetContext2. 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 contextClassloader. - * If the PathableTestSuite isn't resetting the contextClassLoader 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 testResetContext1() { - checkAndSetContext(); - } - - /** - * See testResetContext1. - */ - public void testResetContext2() { - checkAndSetContext(); - } }