You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2016/09/13 19:30:23 UTC
[2/4] logging-log4j2 git commit: Use try-with-resources.
Use try-with-resources.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f4b75c8b
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f4b75c8b
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f4b75c8b
Branch: refs/heads/master
Commit: f4b75c8bab45a6766b7ed179584e18cc7b4ea030
Parents: 0c53da6
Author: Gary Gregory <gg...@apache.org>
Authored: Tue Sep 13 12:19:35 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Tue Sep 13 12:19:35 2016 -0700
----------------------------------------------------------------------
.../config/plugins/util/ResolverUtilTest.java | 42 +++++++++++---------
1 file changed, 24 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f4b75c8b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
index 1b16430..392da7b 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
@@ -37,13 +37,21 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.logging.log4j.core.config.plugins.util.PluginRegistry.PluginTest;
+import org.apache.logging.log4j.junit.CleanFolders;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.RuleChain;
/**
* Tests the ResolverUtil class.
*/
public class ResolverUtilTest {
+ static final String WORK_DIR = "target/testpluginsutil";
+
+ @Rule
+ public RuleChain chain = RuleChain.outerRule(new CleanFolders(WORK_DIR));
+
@Test
public void testExtractPathFromJarUrl() throws Exception {
final URL url = new URL("jar:file:/C:/Users/me/.m2/repository/junit/junit/4.11/junit-4.11.jar!/org/junit/Test.class");
@@ -141,28 +149,26 @@ public class ResolverUtilTest {
@Test
public void testFindInPackageFromDirectoryPath() throws Exception {
- final ClassLoader cl = compileAndCreateClassLoader("1");
-
- final ResolverUtil resolverUtil = new ResolverUtil();
- resolverUtil.setClassLoader(cl);
- resolverUtil.findInPackage(new PluginTest(), "customplugin1");
- assertEquals("Class not found in packages", 1, resolverUtil.getClasses().size());
- assertEquals("Unexpected class resolved",
- cl.loadClass("customplugin1.FixedString1Layout"),
- resolverUtil.getClasses().iterator().next());
+ try (final URLClassLoader cl = compileAndCreateClassLoader("1")) {
+ final ResolverUtil resolverUtil = new ResolverUtil();
+ resolverUtil.setClassLoader(cl);
+ resolverUtil.findInPackage(new PluginTest(), "customplugin1");
+ assertEquals("Class not found in packages", 1, resolverUtil.getClasses().size());
+ assertEquals("Unexpected class resolved", cl.loadClass("customplugin1.FixedString1Layout"),
+ resolverUtil.getClasses().iterator().next());
+ }
}
@Test
public void testFindInPackageFromJarPath() throws Exception {
- final ClassLoader cl = compileJarAndCreateClassLoader("2");
-
- final ResolverUtil resolverUtil = new ResolverUtil();
- resolverUtil.setClassLoader(cl);
- resolverUtil.findInPackage(new PluginTest(), "customplugin2");
- assertEquals("Class not found in packages", 1, resolverUtil.getClasses().size());
- assertEquals("Unexpected class resolved",
- cl.loadClass("customplugin2.FixedString2Layout"),
- resolverUtil.getClasses().iterator().next());
+ try (final URLClassLoader cl = compileJarAndCreateClassLoader("2")) {
+ final ResolverUtil resolverUtil = new ResolverUtil();
+ resolverUtil.setClassLoader(cl);
+ resolverUtil.findInPackage(new PluginTest(), "customplugin2");
+ assertEquals("Class not found in packages", 1, resolverUtil.getClasses().size());
+ assertEquals("Unexpected class resolved", cl.loadClass("customplugin2.FixedString2Layout"),
+ resolverUtil.getClasses().iterator().next());
+ }
}
static URLClassLoader compileJarAndCreateClassLoader(final String suffix) throws IOException, Exception {