]> source.dussan.org Git - archiva.git/commitdiff
Changed boolean Digester methods to throw an exception instead for a more informative...
authorEdwin L. Punzalan <epunzalan@apache.org>
Fri, 16 Jun 2006 06:01:50 +0000 (06:01 +0000)
committerEdwin L. Punzalan <epunzalan@apache.org>
Fri, 16 Jun 2006 06:01:50 +0000 (06:01 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@414745 13f79535-47bb-0310-9956-ffa450edef68

13 files changed:
maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/EclipseRepositoryIndex.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java
maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java
maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumMetadataReporter.java
maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java
maven-repository-utils/src/main/java/org/apache/maven/repository/digest/DefaultDigester.java
maven-repository-utils/src/main/java/org/apache/maven/repository/digest/Digester.java
maven-repository-utils/src/main/java/org/apache/maven/repository/digest/DigesterException.java [new file with mode: 0644]
maven-repository-utils/src/test/java/org/apache/maven/repository/digest/DigesterTest.java

index e8252dca0c3b39072e048e7d58b4c2de2ca457db..28d398bee40a47a2c17189cac6e7f344401120aa 100644 (file)
@@ -19,8 +19,6 @@ package org.apache.maven.repository.converter;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
 import org.apache.maven.artifact.repository.metadata.Metadata;
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
@@ -39,6 +37,7 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
 import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.repository.converter.transaction.FileTransaction;
 import org.apache.maven.repository.digest.Digester;
+import org.apache.maven.repository.digest.DigesterException;
 import org.apache.maven.repository.reporting.ArtifactReporter;
 import org.codehaus.plexus.i18n.I18N;
 import org.codehaus.plexus.util.FileUtils;
@@ -51,7 +50,6 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.io.StringReader;
 import java.io.StringWriter;
-import java.security.NoSuchAlgorithmException;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
@@ -612,17 +610,10 @@ public class DefaultRepositoryConverter
     {
         boolean result;
 
-        try
-        {
-            result = verifyChecksum( file, file.getName() + ".md5", Digester.MD5, reporter, artifact,
-                                     "failure.incorrect.md5" );
-            result = result && verifyChecksum( file, file.getName() + ".sha1", Digester.SHA1, reporter, artifact,
-                                               "failure.incorrect.sha1" );
-        }
-        catch ( NoSuchAlgorithmException e )
-        {
-            throw new RepositoryConversionException( "Error copying artifact: " + e.getMessage(), e );
-        }
+        result = verifyChecksum( file, file.getName() + ".md5", Digester.MD5, reporter, artifact,
+                                 "failure.incorrect.md5" );
+        result = result && verifyChecksum( file, file.getName() + ".sha1", Digester.SHA1, reporter, artifact,
+                                           "failure.incorrect.sha1" );
         return result;
     }
 
@@ -632,7 +623,7 @@ public class DefaultRepositoryConverter
                                     ArtifactReporter reporter,
                                     Artifact artifact,
                                     String key )
-        throws IOException, NoSuchAlgorithmException
+        throws IOException
     {
         boolean result = true;
 
@@ -640,7 +631,11 @@ public class DefaultRepositoryConverter
         if ( md5.exists() )
         {
             String checksum = FileUtils.fileRead( md5 );
-            if ( !digester.verifyChecksum( file, checksum, algorithm ) )
+            try
+            {
+                digester.verifyChecksum( file, checksum, algorithm );
+            }
+            catch ( DigesterException e )
             {
                 reporter.addFailure( artifact, getI18NString( key ) );
                 result = false;
index 8a1f8fb553348546154b04554c5c24a8cfbedc30..c86908109d5e880b12df1528e167b632aa566647 100644 (file)
@@ -22,11 +22,10 @@ import org.apache.lucene.index.Term;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.repository.digest.Digester;
+import org.apache.maven.repository.digest.DigesterException;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -158,18 +157,10 @@ public class ArtifactRepositoryIndex
             sha1sum = digester.createChecksum( artifact.getFile(), Digester.SHA1 );
             md5sum = digester.createChecksum( artifact.getFile(), Digester.MD5 );
         }
-        catch ( NoSuchAlgorithmException e )
+        catch ( DigesterException e )
         {
             throw new RepositoryIndexException( "Unable to create a checksum", e );
         }
-        catch ( FileNotFoundException e )
-        {
-            throw new RepositoryIndexException( "Error reading from artifact file", e );
-        }
-        catch ( IOException e )
-        {
-            throw new RepositoryIndexException( "Error reading from artifact file", e );
-        }
 
         try
         {
index a0a298c84428e4f7dadcfdec1cc1a9d5920edae1..20eb1037511014e96eda61dc3d79c14c2e71213d 100644 (file)
@@ -26,21 +26,20 @@ import org.apache.lucene.document.Field;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.repository.digest.Digester;
+import org.apache.maven.repository.digest.DigesterException;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.Reader;
-import java.security.NoSuchAlgorithmException;
-import java.util.Enumeration;
-import java.util.Collections;
-import java.util.List;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
 import java.util.Iterator;
+import java.util.List;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
@@ -150,15 +149,7 @@ public class EclipseRepositoryIndex
             {
                 md5 = digester.createChecksum( artifactFile, "MD5" );
             }
-            catch ( FileNotFoundException e )
-            {
-                throw new RepositoryIndexException( "Unable to compute checksum.", e );
-            }
-            catch ( NoSuchAlgorithmException e )
-            {
-                throw new RepositoryIndexException( "Unable to compute checksum.", e );
-            }
-            catch ( IOException e )
+            catch ( DigesterException e )
             {
                 throw new RepositoryIndexException( "Unable to compute checksum.", e );
             }
index 0a13c9716b104e890ee455e60709160c3fdf0491..7396ecc029cc9e9a36e4e54234a855adfc56b035 100644 (file)
@@ -28,12 +28,11 @@ import org.apache.maven.model.Model;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.model.ReportPlugin;
 import org.apache.maven.repository.digest.Digester;
+import org.apache.maven.repository.digest.DigesterException;
 import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
@@ -310,17 +309,9 @@ public class PomRepositoryIndex
         {
             return digester.createChecksum( new File( file ), algorithm );
         }
-        catch ( FileNotFoundException e )
+        catch ( DigesterException e )
         {
-            throw new RepositoryIndexException( e.getMessage(), e );
-        }
-        catch ( IOException e )
-        {
-            throw new RepositoryIndexException( e.getMessage(), e );
-        }
-        catch ( NoSuchAlgorithmException e )
-        {
-            throw new RepositoryIndexException( e.getMessage(), e );
+            throw new RepositoryIndexException( "Failed to create checksum", e );
         }
     }
 
index 7048fae234a6f793c7cc0074702624e5186f8be8..838045a6891bb942fce65c5db72b543e8c8cced1 100644 (file)
@@ -20,11 +20,11 @@ import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.model.Model;
 import org.apache.maven.repository.digest.Digester;
+import org.apache.maven.repository.digest.DigesterException;
 import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
 import java.io.IOException;
-import java.security.NoSuchAlgorithmException;
 
 /**
  * This class reports invalid and mismatched checksums of artifacts and metadata files.
@@ -74,22 +74,17 @@ public class ChecksumArtifactReporter
         {
             try
             {
-                if ( digester.verifyChecksum( file, FileUtils.fileRead( checksumFile ), checksumAlgorithm ) )
-                {
-                    reporter.addSuccess( artifact );
-                }
-                else
-                {
-                    reporter.addFailure( artifact, checksumAlgorithm + " checksum does not match." );
-                }
+                digester.verifyChecksum( file, FileUtils.fileRead( checksumFile ), checksumAlgorithm );
+
+                reporter.addSuccess( artifact );
             }
-            catch ( NoSuchAlgorithmException e )
+            catch ( DigesterException e )
             {
-                reporter.addFailure( artifact, "Unable to read " + checksumAlgorithm + ": " + e.getMessage() );
+                reporter.addFailure( artifact, e.getMessage() );
             }
             catch ( IOException e )
             {
-                reporter.addFailure( artifact, "Unable to read " + checksumAlgorithm + ": " + e.getMessage() );
+                reporter.addFailure( artifact, "Read file error: " + e.getMessage() );
             }
         }
         else
index e33e6f8ca540871ef4ba074652eed5125bb9e24b..885d44d15b05a6ec7aae8a5ece0b9abd66e357fe 100644 (file)
@@ -19,11 +19,11 @@ package org.apache.maven.repository.reporting;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
 import org.apache.maven.repository.digest.Digester;
+import org.apache.maven.repository.digest.DigesterException;
 import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
 import java.io.IOException;
-import java.security.NoSuchAlgorithmException;
 
 /**
  * This class reports invalid and mismatched checksums of artifacts and metadata files.
@@ -69,22 +69,17 @@ public class ChecksumMetadataReporter
         {
             try
             {
-                if ( digester.verifyChecksum( file, FileUtils.fileRead( checksumFile ), checksumAlgorithm ) )
-                {
-                    reporter.addSuccess( metadata );
-                }
-                else
-                {
-                    reporter.addFailure( metadata, checksumAlgorithm + " checksum does not match." );
-                }
+                digester.verifyChecksum( file, FileUtils.fileRead( checksumFile ), checksumAlgorithm );
+
+                reporter.addSuccess( metadata );
             }
-            catch ( NoSuchAlgorithmException e )
+            catch ( DigesterException e )
             {
-                reporter.addFailure( metadata, "Unable to read " + checksumAlgorithm + ": " + e.getMessage() );
+                reporter.addFailure( metadata, e.getMessage() );
             }
             catch ( IOException e )
             {
-                reporter.addFailure( metadata, "Unable to read " + checksumAlgorithm + ": " + e.getMessage() );
+                reporter.addFailure( metadata, "Read file error: " + e.getMessage() );
             }
         }
         else
index 3d665553101d78e33578654ecfb0df283f6c9e78..b5f5d7c3d411b10a7d8f0bb828a4a1a56e409e95 100644 (file)
@@ -20,6 +20,7 @@ import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.model.Model;
 import org.apache.maven.repository.digest.Digester;
+import org.apache.maven.repository.digest.DigesterException;
 import org.apache.maven.repository.indexing.RepositoryIndex;
 import org.apache.maven.repository.indexing.RepositoryIndexException;
 import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
@@ -30,8 +31,6 @@ import org.apache.maven.repository.indexing.query.Query;
 import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
 
 import java.io.File;
-import java.io.IOException;
-import java.security.NoSuchAlgorithmException;
 import java.util.Iterator;
 import java.util.List;
 
@@ -88,11 +87,7 @@ public class DuplicateArtifactFileReportProcessor
             {
                 checksum = digester.createChecksum( artifact.getFile(), algorithm );
             }
-            catch ( IOException e )
-            {
-                throw new ReportProcessorException( "Failed to generate checksum", e );
-            }
-            catch ( NoSuchAlgorithmException e )
+            catch ( DigesterException e )
             {
                 throw new ReportProcessorException( "Failed to generate checksum", e );
             }
index c8d03eb813b8459ce1cd34d4b82b69a723dc1b1b..86b60cdca1a90d68f11cd4ad8f637b330fd89116 100644 (file)
@@ -17,6 +17,7 @@ package org.apache.maven.repository.reporting;
  */
 
 import org.apache.maven.repository.digest.Digester;
+import org.apache.maven.repository.digest.DigesterException;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
 
@@ -28,7 +29,6 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
-import java.security.NoSuchAlgorithmException;
 import java.util.jar.JarEntry;
 import java.util.jar.JarOutputStream;
 
@@ -61,7 +61,7 @@ public abstract class AbstractChecksumArtifactReporterTestCase
      * @param type The type of checksum file to be created.
      */
     protected void createChecksumFile( String type )
-        throws NoSuchAlgorithmException, IOException
+        throws DigesterException, IOException
     {
         //loop through the valid artifact names..
         if ( "VALID".equals( type ) )
@@ -86,7 +86,7 @@ public abstract class AbstractChecksumArtifactReporterTestCase
      * @param type The type of checksum to be created. (Valid or invalid)
      */
     protected void createMetadataFile( String type )
-        throws NoSuchAlgorithmException, IOException
+        throws DigesterException, IOException
     {
         //loop through the valid artifact names..
         if ( "VALID".equals( type ) )
@@ -110,7 +110,7 @@ public abstract class AbstractChecksumArtifactReporterTestCase
      * @param isValid      Indicates whether the checksum to be created is valid or not.
      */
     private void writeChecksumFile( String relativePath, String filename, String type, boolean isValid )
-        throws IOException, NoSuchAlgorithmException
+        throws IOException, DigesterException
     {
         //Initialize variables for creating jar files
         String repoUrl = repository.getBasedir();
@@ -177,7 +177,7 @@ public abstract class AbstractChecksumArtifactReporterTestCase
      * @param isValid      Indicates whether the checksum to be created is valid or not.
      */
     private void writeMetadataFile( String relativePath, String filename, String type, boolean isValid )
-        throws IOException, NoSuchAlgorithmException
+        throws IOException, DigesterException
     {
         //create checksum for the metadata file..
         String repoUrl = repository.getBasedir();
index 1e2f2a8da14382cc2562a91d361c9aa0a3767514..64585c52d4eaad0617dc670d91ef2f84ae1c49c0 100644 (file)
@@ -25,10 +25,10 @@ import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
 import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
 import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.repository.digest.DigesterException;
 
 import java.io.File;
 import java.io.IOException;
-import java.security.NoSuchAlgorithmException;
 import java.util.Iterator;
 
 /**
@@ -56,7 +56,7 @@ public class ChecksumArtifactReporterTest
      * Test the ChecksumArtifactReporter when the checksum files are valid.
      */
     public void testChecksumArtifactReporterSuccess()
-        throws ReportProcessorException, NoSuchAlgorithmException, IOException
+        throws ReportProcessorException, IOException, DigesterException
     {
         createChecksumFile( "VALID" );
         createChecksumFile( "INVALID" );
@@ -90,7 +90,7 @@ public class ChecksumArtifactReporterTest
      * The reporter should report 2 success validation.
      */
     public void testChecksumMetadataReporterSuccess()
-        throws ReportProcessorException, NoSuchAlgorithmException, IOException
+        throws ReportProcessorException, DigesterException, IOException
     {
         createMetadataFile( "VALID" );
         createMetadataFile( "INVALID" );
@@ -195,7 +195,7 @@ public class ChecksumArtifactReporterTest
      * Test the conditional when the checksum files of the artifact & metadata do not exist.
      */
     public void testChecksumFilesDoNotExist()
-        throws ReportProcessorException, NoSuchAlgorithmException, IOException
+        throws ReportProcessorException, DigesterException, IOException
     {
         createChecksumFile( "VALID" );
         createMetadataFile( "VALID" );
index 4974fb05d1d52aa03de572ec34b864d0ef8d2d47..a342227a38d73a601a8dc902e5e58c7c593d0d73 100644 (file)
@@ -17,11 +17,13 @@ package org.apache.maven.repository.digest;
  */
 
 import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.FileNotFoundException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.regex.Matcher;
@@ -41,11 +43,28 @@ public class DefaultDigester
     private static final int BYTE_MASK = 0xFF;
 
     public String createChecksum( File file, String algorithm )
-        throws IOException, NoSuchAlgorithmException
+        throws DigesterException
     {
-        MessageDigest digest = MessageDigest.getInstance( algorithm );
+        MessageDigest digest;
+        try
+        {
+            digest = MessageDigest.getInstance( algorithm );
+        }
+        catch ( NoSuchAlgorithmException e )
+        {
+            throw new DigesterException( "Specified algorithm not found: " + algorithm, e );
+        }
+
+        InputStream fis = null;
+        try
+        {
+            fis = new FileInputStream( file );
+        }
+        catch ( FileNotFoundException e )
+        {
+            throw new DigesterException( "Specified file not found: " + file.getAbsolutePath(), e );
+        }
 
-        InputStream fis = new FileInputStream( file );
         try
         {
             byte[] buffer = new byte[CHECKSUM_BUFFER_SIZE];
@@ -60,6 +79,10 @@ public class DefaultDigester
             }
             while ( numRead != -1 );
         }
+        catch( IOException e )
+        {
+            throw new DigesterException( "Failed to read from file: " + file.getAbsolutePath(), e );
+        }
         finally
         {
             IOUtil.close( fis );
@@ -68,11 +91,9 @@ public class DefaultDigester
         return byteArrayToHexStr( digest.digest() );
     }
 
-    public boolean verifyChecksum( File file, String checksum, String algorithm )
-        throws NoSuchAlgorithmException, IOException
+    public void verifyChecksum( File file, String checksum, String algorithm )
+        throws DigesterException
     {
-        boolean result = true;
-
         String trimmedChecksum = checksum.replace( '\n', ' ' ).trim();
         // Free-BSD / openssl
         Matcher m =
@@ -83,8 +104,7 @@ public class DefaultDigester
             String filename = m.group( 1 );
             if ( !filename.equals( file.getName() ) )
             {
-                // TODO: provide better warning
-                result = false;
+                throw new DigesterException( "Supplied checksum does not match checksum pattern" );
             }
             trimmedChecksum = m.group( 2 );
         }
@@ -97,20 +117,18 @@ public class DefaultDigester
                 String filename = m.group( 2 );
                 if ( !filename.equals( file.getName() ) )
                 {
-                    // TODO: provide better warning
-                    result = false;
+                    throw new DigesterException( "Supplied checksum does not match checksum pattern" );
                 }
                 trimmedChecksum = m.group( 1 );
             }
         }
 
-        if ( result )
+        //Create checksum for jar file
+        String sum = createChecksum( file, algorithm );
+        if ( !StringUtils.equalsIgnoreCase( trimmedChecksum, sum ) )
         {
-            //Create checksum for jar file
-            String sum = createChecksum( file, algorithm );
-            result = trimmedChecksum.toUpperCase().equals( sum.toUpperCase() );
+            throw new DigesterException( "Checksum failed" );
         }
-        return result;
     }
 
     /**
index 1757dab569c35d7e36703d340d7893b198f3eea8..ef555bb7421737cf279c29fa633471799c03bf82 100644 (file)
@@ -17,9 +17,6 @@ package org.apache.maven.repository.digest;
  */
 
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.security.NoSuchAlgorithmException;
 
 /**
  * Create a digest for a file.
@@ -35,8 +32,8 @@ public interface Digester
     String MD5 = "MD5";
 
     String createChecksum( File file, String algorithm )
-        throws FileNotFoundException, IOException, NoSuchAlgorithmException;
+        throws DigesterException;
 
-    boolean verifyChecksum( File file, String checksum, String algorithm )
-        throws NoSuchAlgorithmException, IOException;
+    void verifyChecksum( File file, String checksum, String algorithm )
+        throws DigesterException;
 }
diff --git a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/DigesterException.java b/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/DigesterException.java
new file mode 100644 (file)
index 0000000..789957b
--- /dev/null
@@ -0,0 +1,34 @@
+package org.apache.maven.repository.digest;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Edwin Punzalan
+ */
+public class DigesterException
+    extends Exception
+{
+    public DigesterException( String message )
+    {
+        super( message );
+    }
+
+    public DigesterException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+}
index 20a86e18b2c2b5ecb18153e7aeb14d630c36bffd..31a47376ca41c01ae25899ec07247fef555cbe55 100644 (file)
@@ -39,54 +39,172 @@ public class DigesterTest
     private static final String WRONG_SHA1 = "4d8703779816556cdb8be7f6bb5c954f4b5730e2";
 
     public void testBareDigestFormat()
-        throws NoSuchAlgorithmException, IOException
+        throws DigesterException, IOException
     {
         File file = new File( getClass().getResource( "/test-file.txt" ).getPath() );
-        assertTrue( "test bare format MD5", digester.verifyChecksum( file, MD5, Digester.MD5 ) );
-        assertTrue( "test bare format SHA1", digester.verifyChecksum( file, SHA1, Digester.SHA1 ) );
 
-        assertFalse( "test wrong sha1", digester.verifyChecksum( file, WRONG_SHA1, Digester.SHA1 ) );
+        try
+        {
+            digester.verifyChecksum( file, MD5, Digester.MD5 );
+        }
+        catch ( DigesterException e )
+        {
+            fail( "Bare format MD5 must not throw exception" );
+        }
+
+        try
+        {
+            digester.verifyChecksum( file, SHA1, Digester.SHA1 );
+        }
+        catch ( DigesterException e )
+        {
+            fail( "Bare format SHA1 must not throw exception" );
+        }
+
+        try
+        {
+            digester.verifyChecksum( file, WRONG_SHA1, Digester.SHA1 );
+            fail( "wrong checksum must throw an exception" );
+        }
+        catch ( DigesterException e )
+        {
+            //expected
+        }
     }
 
     public void testOpensslDigestFormat()
-        throws NoSuchAlgorithmException, IOException
+        throws IOException
     {
         File file = new File( getClass().getResource( "/test-file.txt" ).getPath() );
-        assertTrue( "test openssl format MD5",
-                    digester.verifyChecksum( file, "MD5(test-file.txt)= " + MD5, Digester.MD5 ) );
-        assertTrue( "test openssl format SHA1",
-                    digester.verifyChecksum( file, "SHA1(test-file.txt)= " + SHA1, Digester.SHA1 ) );
-
-        assertTrue( "test freebsd format MD5",
-                    digester.verifyChecksum( file, "MD5 (test-file.txt) = " + MD5, Digester.MD5 ) );
-        assertTrue( "test freebsd format SHA1",
-                    digester.verifyChecksum( file, "SHA1 (test-file.txt) = " + SHA1, Digester.SHA1 ) );
-
-        assertFalse( "test wrong filename", digester.verifyChecksum( file, "SHA1 (FOO) = " + SHA1, Digester.SHA1 ) );
-        assertFalse( "test wrong sha1",
-                     digester.verifyChecksum( file, "SHA1 (test-file.txt) = " + WRONG_SHA1, Digester.SHA1 ) );
+        try
+        {
+            digester.verifyChecksum( file, "MD5(test-file.txt)= " + MD5, Digester.MD5 );
+        }
+        catch ( DigesterException e )
+        {
+            fail( "OpenSSL MD5 format must not cause exception" );
+        }
+
+        try
+        {
+            digester.verifyChecksum( file, "SHA1(test-file.txt)= " + SHA1, Digester.SHA1 );
+        }
+        catch ( DigesterException e )
+        {
+            fail( "OpenSSL SHA1 format must not cause exception" );
+        }
+
+        try
+        {
+            digester.verifyChecksum( file, "MD5 (test-file.txt) = " + MD5, Digester.MD5 );
+        }
+        catch ( DigesterException e )
+        {
+            fail( "FreeBSD MD5 format must not cause exception" );
+        }
+
+        try
+        {
+            digester.verifyChecksum( file, "SHA1 (test-file.txt) = " + SHA1, Digester.SHA1 );
+        }
+        catch ( DigesterException e )
+        {
+            fail( "FreeBSD SHA1 format must not cause exception" );
+        }
+
+        try
+        {
+            digester.verifyChecksum( file, "SHA1 (FOO) = " + SHA1, Digester.SHA1 );
+            fail( "Wrong filename should cause an exception" );
+        }
+        catch ( DigesterException e )
+        {
+            //expected
+        }
+
+        try
+        {
+            digester.verifyChecksum( file, "SHA1 (test-file.txt) = " + WRONG_SHA1, Digester.SHA1 );
+            fail( "Wrong sha1 should cause an exception" );
+        }
+        catch ( DigesterException e )
+        {
+            //expected
+        }
     }
 
     public void testGnuDigestFormat()
         throws NoSuchAlgorithmException, IOException
     {
         File file = new File( getClass().getResource( "/test-file.txt" ).getPath() );
-        assertTrue( "test GNU format MD5", digester.verifyChecksum( file, MD5 + " *test-file.txt", Digester.MD5 ) );
-        assertTrue( "test GNU format SHA1", digester.verifyChecksum( file, SHA1 + " *test-file.txt", Digester.SHA1 ) );
-
-        assertTrue( "test GNU text format MD5", digester.verifyChecksum( file, MD5 + " test-file.txt", Digester.MD5 ) );
-        assertTrue( "test GNU text format SHA1",
-                    digester.verifyChecksum( file, SHA1 + " test-file.txt", Digester.SHA1 ) );
-
-        assertFalse( "test wrong filename", digester.verifyChecksum( file, SHA1 + " FOO", Digester.SHA1 ) );
-        assertFalse( "test wrong sha1", digester.verifyChecksum( file, WRONG_SHA1 + " test-file.txt", Digester.SHA1 ) );
+        try
+        {
+            digester.verifyChecksum( file, MD5 + " *test-file.txt", Digester.MD5 );
+        }
+        catch ( DigesterException e )
+        {
+            fail( "GNU format MD5 must not cause exception" );
+        }
+
+        try
+        {
+            digester.verifyChecksum( file, SHA1 + " *test-file.txt", Digester.SHA1 );
+        }
+        catch ( DigesterException e )
+        {
+            fail( "GNU format SHA1 must not cause exception" );
+        }
+
+        try
+        {
+            digester.verifyChecksum( file, MD5 + " test-file.txt", Digester.MD5 );
+        }
+        catch ( DigesterException e )
+        {
+            fail( "GNU text format MD5 must not cause exception" );
+        }
+
+        try
+        {
+            digester.verifyChecksum( file, SHA1 + " test-file.txt", Digester.SHA1 );
+        }
+        catch ( DigesterException e )
+        {
+            fail( "GNU text format SHA1 must not cause exception" );
+        }
+
+        try
+        {
+            digester.verifyChecksum( file, SHA1 + " FOO", Digester.SHA1 );
+            fail( "Wrong filename cause an exception" );
+        }
+        catch ( DigesterException e )
+        {
+            //expected
+        }
+
+        try
+        {
+            digester.verifyChecksum( file, WRONG_SHA1 + " test-file.txt", Digester.SHA1 );
+            fail( "Wrong SHA1 cause an exception" );
+        }
+        catch ( DigesterException e )
+        {
+            //expected
+        }
     }
 
     public void testUntrimmedContent()
         throws NoSuchAlgorithmException, IOException
     {
         File file = new File( getClass().getResource( "/test-file.txt" ).getPath() );
-        assertTrue( "test untrimmed GNU format SHA1",
-                    digester.verifyChecksum( file, SHA1 + " *test-file.txt \n", Digester.SHA1 ) );
+        try
+        {
+            digester.verifyChecksum( file, SHA1 + " *test-file.txt \n", Digester.SHA1 );
+        }
+        catch ( DigesterException e )
+        {
+            fail( "GNU untrimmed SHA1 must not cause exception" );
+        }
     }
 }