* under the License.
*/
-import java.io.File;
-
import junit.framework.TestCase;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.File;
/**
- * BaseFileTest
+ * BaseFileTest
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
String pathFile = "path/to/resource.xml";
BaseFile file = new BaseFile( repoDir, pathFile );
- assertEquals( "/home/user/foo/repository/path/to/resource.xml", file.getAbsolutePath() );
- assertEquals( "path/to/resource.xml", file.getRelativePath() );
- assertEquals( new File( "/home/user/foo/repository" ), file.getBaseDir() );
+ assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
+ assertRelativePath( "path/to/resource.xml", file );
+ assertBasedir( "/home/user/foo/repository", file );
}
public void testFileFile()
File pathFile = new File( "/home/user/foo/repository/path/to/resource.xml" );
BaseFile file = new BaseFile( repoDir, pathFile );
- assertEquals( "/home/user/foo/repository/path/to/resource.xml", file.getAbsolutePath() );
- assertEquals( "path/to/resource.xml", file.getRelativePath() );
- assertEquals( new File( "/home/user/foo/repository" ), file.getBaseDir() );
+ assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
+ assertRelativePath( "path/to/resource.xml", file );
+ assertBasedir( "/home/user/foo/repository", file );
}
public void testStringFile()
File pathFile = new File( "/home/user/foo/repository/path/to/resource.xml" );
BaseFile file = new BaseFile( repoDir, pathFile );
- assertEquals( "/home/user/foo/repository/path/to/resource.xml", file.getAbsolutePath() );
- assertEquals( "path/to/resource.xml", file.getRelativePath() );
- assertEquals( new File( "/home/user/foo/repository" ), file.getBaseDir() );
+ assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
+ assertRelativePath( "path/to/resource.xml", file );
+ assertBasedir( "/home/user/foo/repository", file );
}
public void testFileThenSetBaseString()
BaseFile file = new BaseFile( pathFile );
file.setBaseDir( repoDir );
- assertEquals( "/home/user/foo/repository/path/to/resource.xml", file.getAbsolutePath() );
- assertEquals( "path/to/resource.xml", file.getRelativePath() );
- assertEquals( new File( "/home/user/foo/repository" ), file.getBaseDir() );
+ assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
+ assertRelativePath( "path/to/resource.xml", file );
+ assertBasedir( "/home/user/foo/repository", file );
}
public void testFileThenSetBaseFile()
BaseFile file = new BaseFile( pathFile );
file.setBaseDir( repoDir );
- assertEquals( "/home/user/foo/repository/path/to/resource.xml", file.getAbsolutePath() );
- assertEquals( "path/to/resource.xml", file.getRelativePath() );
- assertEquals( new File( "/home/user/foo/repository" ), file.getBaseDir() );
+ assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
+ assertRelativePath( "path/to/resource.xml", file );
+ assertBasedir( "/home/user/foo/repository", file );
}
-
+
public void testStringThenSetBaseString()
{
String repoDir = "/home/user/foo/repository";
BaseFile file = new BaseFile( pathFile );
file.setBaseDir( repoDir );
- assertEquals( "/home/user/foo/repository/path/to/resource.xml", file.getAbsolutePath() );
- assertEquals( "path/to/resource.xml", file.getRelativePath() );
- assertEquals( new File( "/home/user/foo/repository" ), file.getBaseDir() );
+ assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
+ assertRelativePath( "path/to/resource.xml", file );
+ assertBasedir( "/home/user/foo/repository", file );
}
public void testStringThenSetBaseFile()
BaseFile file = new BaseFile( pathFile );
file.setBaseDir( repoDir );
- assertEquals( "/home/user/foo/repository/path/to/resource.xml", file.getAbsolutePath() );
- assertEquals( "path/to/resource.xml", file.getRelativePath() );
- assertEquals( new File( "/home/user/foo/repository" ), file.getBaseDir() );
- }
+ assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
+ assertRelativePath( "path/to/resource.xml", file );
+ 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() );
+ }
}