Fix tests for windows

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@511809 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Emmanuel Venisse 2007-02-26 14:05:24 +00:00
parent dee0d5a300
commit 43bb7a6d9a
2 changed files with 45 additions and 27 deletions

View File

@ -20,6 +20,7 @@ package org.apache.maven.archiva.common.consumers;
*/ */
import org.apache.maven.archiva.common.utils.BaseFile; import org.apache.maven.archiva.common.utils.BaseFile;
import org.codehaus.plexus.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -46,6 +47,7 @@ public class FileProblemsTracker
private void addProblem( String path, String message ) private void addProblem( String path, String message )
{ {
path = StringUtils.replace( path, "\\", "/" );
List problems = getProblems( path ); List problems = getProblems( path );
problems.add( message ); problems.add( message );
problemMap.put( path, problems ); problemMap.put( path, problems );

View File

@ -19,9 +19,10 @@ package org.apache.maven.archiva.common.utils;
* under the License. * under the License.
*/ */
import java.io.File;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
/** /**
* BaseFileTest * BaseFileTest
@ -38,9 +39,9 @@ public class BaseFileTest
String pathFile = "path/to/resource.xml"; String pathFile = "path/to/resource.xml";
BaseFile file = new BaseFile( repoDir, pathFile ); BaseFile file = new BaseFile( repoDir, pathFile );
assertEquals( "/home/user/foo/repository/path/to/resource.xml", file.getAbsolutePath() ); assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
assertEquals( "path/to/resource.xml", file.getRelativePath() ); assertRelativePath( "path/to/resource.xml", file );
assertEquals( new File( "/home/user/foo/repository" ), file.getBaseDir() ); assertBasedir( "/home/user/foo/repository", file );
} }
public void testFileFile() public void testFileFile()
@ -49,9 +50,9 @@ public class BaseFileTest
File pathFile = new File( "/home/user/foo/repository/path/to/resource.xml" ); File pathFile = new File( "/home/user/foo/repository/path/to/resource.xml" );
BaseFile file = new BaseFile( repoDir, pathFile ); BaseFile file = new BaseFile( repoDir, pathFile );
assertEquals( "/home/user/foo/repository/path/to/resource.xml", file.getAbsolutePath() ); assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
assertEquals( "path/to/resource.xml", file.getRelativePath() ); assertRelativePath( "path/to/resource.xml", file );
assertEquals( new File( "/home/user/foo/repository" ), file.getBaseDir() ); assertBasedir( "/home/user/foo/repository", file );
} }
public void testStringFile() public void testStringFile()
@ -60,9 +61,9 @@ public class BaseFileTest
File pathFile = new File( "/home/user/foo/repository/path/to/resource.xml" ); File pathFile = new File( "/home/user/foo/repository/path/to/resource.xml" );
BaseFile file = new BaseFile( repoDir, pathFile ); BaseFile file = new BaseFile( repoDir, pathFile );
assertEquals( "/home/user/foo/repository/path/to/resource.xml", file.getAbsolutePath() ); assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
assertEquals( "path/to/resource.xml", file.getRelativePath() ); assertRelativePath( "path/to/resource.xml", file );
assertEquals( new File( "/home/user/foo/repository" ), file.getBaseDir() ); assertBasedir( "/home/user/foo/repository", file );
} }
public void testFileThenSetBaseString() public void testFileThenSetBaseString()
@ -72,9 +73,9 @@ public class BaseFileTest
BaseFile file = new BaseFile( pathFile ); BaseFile file = new BaseFile( pathFile );
file.setBaseDir( repoDir ); file.setBaseDir( repoDir );
assertEquals( "/home/user/foo/repository/path/to/resource.xml", file.getAbsolutePath() ); assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
assertEquals( "path/to/resource.xml", file.getRelativePath() ); assertRelativePath( "path/to/resource.xml", file );
assertEquals( new File( "/home/user/foo/repository" ), file.getBaseDir() ); assertBasedir( "/home/user/foo/repository", file );
} }
public void testFileThenSetBaseFile() public void testFileThenSetBaseFile()
@ -84,9 +85,9 @@ public class BaseFileTest
BaseFile file = new BaseFile( pathFile ); BaseFile file = new BaseFile( pathFile );
file.setBaseDir( repoDir ); file.setBaseDir( repoDir );
assertEquals( "/home/user/foo/repository/path/to/resource.xml", file.getAbsolutePath() ); assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
assertEquals( "path/to/resource.xml", file.getRelativePath() ); assertRelativePath( "path/to/resource.xml", file );
assertEquals( new File( "/home/user/foo/repository" ), file.getBaseDir() ); assertBasedir( "/home/user/foo/repository", file );
} }
public void testStringThenSetBaseString() public void testStringThenSetBaseString()
@ -96,9 +97,9 @@ public class BaseFileTest
BaseFile file = new BaseFile( pathFile ); BaseFile file = new BaseFile( pathFile );
file.setBaseDir( repoDir ); file.setBaseDir( repoDir );
assertEquals( "/home/user/foo/repository/path/to/resource.xml", file.getAbsolutePath() ); assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
assertEquals( "path/to/resource.xml", file.getRelativePath() ); assertRelativePath( "path/to/resource.xml", file );
assertEquals( new File( "/home/user/foo/repository" ), file.getBaseDir() ); assertBasedir( "/home/user/foo/repository", file );
} }
public void testStringThenSetBaseFile() public void testStringThenSetBaseFile()
@ -108,8 +109,23 @@ public class BaseFileTest
BaseFile file = new BaseFile( pathFile ); BaseFile file = new BaseFile( pathFile );
file.setBaseDir( repoDir ); file.setBaseDir( repoDir );
assertEquals( "/home/user/foo/repository/path/to/resource.xml", file.getAbsolutePath() ); assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
assertEquals( "path/to/resource.xml", file.getRelativePath() ); assertRelativePath( "path/to/resource.xml", file );
assertEquals( new File( "/home/user/foo/repository" ), file.getBaseDir() ); assertBasedir( "/home/user/foo/repository", file );
}
private void assertAbsolutePath( String expectedPath, BaseFile actualFile )
{
assertEquals( new File( expectedPath ).getAbsolutePath(), actualFile.getAbsolutePath() );
}
private void assertRelativePath( String expectedPath, BaseFile actualFile )
{
assertEquals( expectedPath, StringUtils.replace( actualFile.getRelativePath(), "\\", "/" ) );
}
private void assertBasedir( String expectedPath, BaseFile actualFile )
{
assertEquals( new File( expectedPath ), actualFile.getBaseDir() );
} }
} }