* under the License.
*/
-import java.io.File;
import org.apache.commons.io.FilenameUtils;
+import java.nio.file.Path;
+
/**
* Enumeration of available ChecksumAlgorithm techniques.
*
SHA1("SHA-1", "sha1", "SHA1"),
MD5("MD5", "md5", "MD5");
- public static ChecksumAlgorithm getByExtension( File file )
+ public static ChecksumAlgorithm getByExtension( Path file )
{
- String ext = FilenameUtils.getExtension( file.getName() ).toLowerCase();
+ String ext = FilenameUtils.getExtension( file.getFileName().toString() ).toLowerCase();
if ( ChecksumAlgorithm.SHA1.getExt().equals( ext ) )
{
return ChecksumAlgorithm.SHA1;
return ChecksumAlgorithm.MD5;
}
- throw new IllegalArgumentException( "Filename " + file.getName() + " has no associated extension." );
+ throw new IllegalArgumentException( "Filename " + file.getFileName() + " has no associated extension." );
}
/**
*/
import java.io.File;
+import java.nio.file.Paths;
import junit.framework.TestCase;
import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
@Test
public void testGetHashByExtensionSha1()
{
- assertEquals( ChecksumAlgorithm.SHA1, ChecksumAlgorithm.getByExtension( new File( "something.jar.sha1" ) ) );
- assertEquals( ChecksumAlgorithm.SHA1, ChecksumAlgorithm.getByExtension( new File( "OTHER.JAR.SHA1" ) ) );
+ assertEquals( ChecksumAlgorithm.SHA1, ChecksumAlgorithm.getByExtension( Paths.get( "something.jar.sha1" ) ) );
+ assertEquals( ChecksumAlgorithm.SHA1, ChecksumAlgorithm.getByExtension( Paths.get( "OTHER.JAR.SHA1" ) ) );
}
@Test
public void testGetHashByExtensionMd5()
{
- assertEquals( ChecksumAlgorithm.MD5, ChecksumAlgorithm.getByExtension( new File( "something.jar.md5" ) ) );
- assertEquals( ChecksumAlgorithm.MD5, ChecksumAlgorithm.getByExtension( new File( "OTHER.JAR.MD5" ) ) );
+ assertEquals( ChecksumAlgorithm.MD5, ChecksumAlgorithm.getByExtension( Paths.get( "something.jar.md5" ) ) );
+ assertEquals( ChecksumAlgorithm.MD5, ChecksumAlgorithm.getByExtension( Paths.get( "OTHER.JAR.MD5" ) ) );
}
@Test
{
try
{
- ChecksumAlgorithm.getByExtension( new File( "something.jar" ) );
+ ChecksumAlgorithm.getByExtension( Paths.get( "something.jar" ) );
fail( "Expected " + IllegalArgumentException.class.getName() );
}
catch ( IllegalArgumentException e )