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
master
Herve Boutemy 2008-04-05 11:09:56 +00:00
parent 0f8a88c25a
commit 31e3987e33
2 changed files with 10 additions and 5 deletions

View File

@ -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";

View File

@ -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
}
}