You are viewing a plain text version of this content. The canonical link for it is here.
Posted to surefire-commits@maven.apache.org by hb...@apache.org on 2008/05/01 14:10:54 UTC
svn commit: r652491 -
/maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/UrlUtilsTest.java
Author: hboutemy
Date: Thu May 1 05:10:54 2008
New Revision: 652491
URL: http://svn.apache.org/viewvc?rev=652491&view=rev
Log:
changed the test code to compile and run (more precisely safely ignore) with JDK 1.3
Modified:
maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/UrlUtilsTest.java
Modified: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/UrlUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/UrlUtilsTest.java?rev=652491&r1=652490&r2=652491&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/UrlUtilsTest.java (original)
+++ maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/UrlUtilsTest.java Thu May 1 05:10:54 2008
@@ -23,7 +23,9 @@
import java.io.File;
import java.io.IOException;
-import java.net.URISyntaxException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.URL;
/**
@@ -46,24 +48,37 @@
}
private void verifyFileName( String fileName )
- throws IOException, URISyntaxException
+ throws Exception
{
verifyFileName( fileName, fileName );
}
private void verifyFileName( String fileName, String expectedFileName )
- throws IOException, URISyntaxException
+ throws Exception
{
File f = new File( homeDir, fileName );
URL u = UrlUtils.getURL( f );
String url = u.toString();
assertStartsWith( url, "file:" );
assertEndsWith( url, expectedFileName );
- // DGF this constructor is new for JDK 1.4, but we don't care if
- // the TEST works in JDK 1.3; we just need the
- // CODE to work in JDK 1.3, and this is a good way to test it.
- File urlFile = new File( u.toURI() );
- assertEquals( f, urlFile );
+
+ try
+ {
+ // use reflection to do "URI uri = u.toURI()" if JDK 1.5+
+ Method toURI = URL.class.getMethod( "toURI", null );
+ Object uri = toURI.invoke( u, null );
+
+ // use reflection to do "File urlFile = new File( uri )" if JDK 1.4+
+ Constructor newFile = File.class.getConstructor( new Class[] { uri.getClass() } );
+ File urlFile = (File) newFile.newInstance( new Object[] { uri } );
+
+ assertEquals( f, urlFile );
+ }
+ catch (NoSuchMethodException e )
+ {
+ // URL.toURI() method in JDK 1.5+, not available currently
+ // we won't be able to check for file equality...
+ }
}
private void assertStartsWith( String string, String substring )
@@ -77,7 +92,7 @@
}
public void testTestNoSpecialCharacters()
- throws IOException, URISyntaxException
+ throws Exception
{
verifyFileName( "foo.txt" );
verifyFileName( "qwertyuiopasdfghjklzxcvbnm.txt" );
@@ -87,13 +102,13 @@
}
public void testTestWithSpaces()
- throws IOException, URISyntaxException
+ throws Exception
{
verifyFileName( "foo bar.txt", "foo%20bar.txt" );
}
public void testTestWithUmlaut()
- throws IOException, URISyntaxException
+ throws Exception
{
verifyFileName( "fo\u00DC.txt", "fo%c3%9c.txt" );
}