diff --git a/src/test/java/org/dstadler/commons/logging/jdk/LoggerFactoryTest.java b/src/test/java/org/dstadler/commons/logging/jdk/LoggerFactoryTest.java index 8fd74680..a3a1e6f5 100644 --- a/src/test/java/org/dstadler/commons/logging/jdk/LoggerFactoryTest.java +++ b/src/test/java/org/dstadler/commons/logging/jdk/LoggerFactoryTest.java @@ -32,28 +32,33 @@ public void testMake() { @Test public void testInitLogging() throws IOException { - Thread.currentThread().setContextClassLoader(new ClassLoader() { - @Override - public URL getResource(String name) { - return null; - } - }); - - try { - LoggerFactory.initLogging(); - fail("Should throw Exception, seems we found a resource: " + Thread.currentThread().getContextClassLoader().getResource("logging.properties")); - } catch (IOException e) { - // expected if we do not have a logging.properties here - assertNotNull(e); - } - - try (URLClassLoader cl = new URLClassLoader(new URL[] {new File("src/test/resources").toURI().toURL()}, - Thread.currentThread().getContextClassLoader())) { - Thread.currentThread().setContextClassLoader(cl); - - // now it should work - LoggerFactory.initLogging(); - } + ClassLoader prev = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(new ClassLoader() { + @Override + public URL getResource(String name) { + return null; + } + }); + + try { + LoggerFactory.initLogging(); + fail("Should throw Exception, seems we found a resource: " + Thread.currentThread().getContextClassLoader().getResource("logging.properties")); + } catch (IOException e) { + // expected if we do not have a logging.properties here + assertNotNull(e); + } + + try (URLClassLoader cl = new URLClassLoader(new URL[] {new File("src/test/resources").toURI().toURL()}, prev)) { + Thread.currentThread().setContextClassLoader(cl); + + // now it should work + LoggerFactory.initLogging(); + } + } finally { + // restore the previous class loader + Thread.currentThread().setContextClassLoader(prev); + } } // helper method to get coverage of the unused constructor diff --git a/src/test/java/org/dstadler/commons/svn/SVNCommandsTest.java b/src/test/java/org/dstadler/commons/svn/SVNCommandsTest.java index 7620a023..f71682fd 100644 --- a/src/test/java/org/dstadler/commons/svn/SVNCommandsTest.java +++ b/src/test/java/org/dstadler/commons/svn/SVNCommandsTest.java @@ -48,15 +48,11 @@ public class SVNCommandsTest { // use static-block to initialize "static final" members static { - assertNotNull(Thread.currentThread().getContextClassLoader().getResource("logging.properties"), - "Should have logging.properties, but had none with Classloader: " + - Thread.currentThread().getContextClassLoader()); - - try { - LoggerFactory.initLogging(); - } catch (IOException e) { - throw new RuntimeException(e); - } + try { + LoggerFactory.initLogging(); + } catch (IOException e) { + throw new RuntimeException(e); + } repoDir = createLocalSVNRepository();