From 31e3987e335f6e4c0a5efe08f5450ea058bcbc27 Mon Sep 17 00:00:00 2001 From: Herve Boutemy Date: Sat, 5 Apr 2008 11:09:56 +0000 Subject: [PATCH] fixed tests when there are spaces in directory name git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@645076 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/tools/plugin/util/PluginUtilsTest.java | 5 +++-- .../org/apache/maven/tools/plugin/util/TestUtils.java | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java b/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java index 047f0ea..93396e7 100644 --- a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java +++ b/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java @@ -27,6 +27,7 @@ import org.codehaus.plexus.util.xml.CompactXMLWriter; import org.codehaus.plexus.util.xml.XMLWriter; import java.io.StringWriter; +import java.io.UnsupportedEncodingException; import java.util.Collections; /** @@ -71,7 +72,7 @@ public class PluginUtilsTest assertEquals( pattern, output ); } - public void testShouldFindTwoScriptsWhenNoExcludesAreGiven() + public void testShouldFindTwoScriptsWhenNoExcludesAreGiven() throws UnsupportedEncodingException { String testScript = "test.txt"; @@ -83,7 +84,7 @@ public class PluginUtilsTest assertEquals( 2, files.length ); } - public void testShouldFindOneScriptsWhenAnExcludeIsGiven() + public void testShouldFindOneScriptsWhenAnExcludeIsGiven() throws UnsupportedEncodingException { String testScript = "test.txt"; diff --git a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/TestUtils.java b/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/TestUtils.java index fb3fde4..8476dc9 100644 --- a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/TestUtils.java +++ b/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/TestUtils.java @@ -21,7 +21,9 @@ package org.apache.maven.tools.plugin.util; import junit.framework.TestCase; +import java.io.UnsupportedEncodingException; import java.net.URL; +import java.net.URLDecoder; /** * @author jdcasey @@ -30,7 +32,7 @@ public class TestUtils extends TestCase { - public void testDirnameFunction_METATEST() + public void testDirnameFunction_METATEST() throws UnsupportedEncodingException { String classname = getClass().getName().replace( '.', '/' ) + ".class"; String basedir = TestUtils.dirname( classname ); @@ -41,14 +43,16 @@ public class TestUtils assertEquals( resource.getPath(), basedir + classname ); } - public static String dirname( String file ) + public static String dirname( String file ) throws UnsupportedEncodingException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL fileResource = cl.getResource( file ); String fullPath = fileResource.getPath(); - return fullPath.substring( 0, fullPath.length() - file.length() ); + String path = fullPath.substring( 0, fullPath.length() - file.length() ); + + return URLDecoder.decode( path, "UTF-8" ); // necessary for JDK 1.5+, where spaces are escaped to %20 } } \ No newline at end of file