Author: grobmeier
Date: Fri Jan 29 07:47:21 2010
New Revision: 904403

URL: http://svn.apache.org/viewvc?rev=904403&view=rev
Log:
Applied COMPRESS-95 from Joerg Bellmann: Improve ExceptionMessages in 
ArchiveStreamFactory

Added:
    
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ExceptionMessageTest.java
Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java

Modified: commons/proper/compress/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=904403&r1=904402&r2=904403&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Fri Jan 29 07:47:21 
2010
@@ -23,6 +23,10 @@
   </properties>
   <body>
     <release version="1.1" date="as in SVN" description="Release 1.1">
+     <action type="add" issue="COMPRESS-95" date="2010-01-29"
+              due-to="Joerg Bellmann">
+        Improve ExceptionMessages in ArchiveStreamFactory
+      </action>
       <action type="fix" issue="COMPRESS-94" date="2010-01-07"
               due-to="Anon Devs">
         ZipArchiveEntry's equals method was broken for entries created

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java?rev=904403&r1=904402&r2=904403&view=diff
==============================================================================
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
 Fri Jan 29 07:47:21 2010
@@ -83,9 +83,12 @@
     public ArchiveInputStream createArchiveInputStream(
             final String archiverName, final InputStream in)
             throws ArchiveException {
-        if (archiverName == null || in == null) {
+        if (archiverName == null) {
             throw new IllegalArgumentException("Archivername must not be 
null.");
         }
+        if (in == null) {
+               throw new IllegalArgumentException("InputStream must not be 
null.");
+        }
 
         if ("ar".equalsIgnoreCase(archiverName)) {
             return new ArArchiveInputStream(in);
@@ -113,9 +116,11 @@
     public ArchiveOutputStream createArchiveOutputStream(
             final String archiverName, final OutputStream out)
             throws ArchiveException {
-        if (archiverName == null || out == null) {
-            throw new IllegalArgumentException(
-                    "Archivername and stream must not be null.");
+        if (archiverName == null) {
+            throw new IllegalArgumentException("Archivername must not be 
null.");
+        }
+        if (out == null) {
+               throw new IllegalArgumentException("OutputStream must not be 
null.");
         }
 
         if ("ar".equalsIgnoreCase(archiverName)) {

Added: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ExceptionMessageTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ExceptionMessageTest.java?rev=904403&view=auto
==============================================================================
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ExceptionMessageTest.java
 (added)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ExceptionMessageTest.java
 Fri Jan 29 07:47:21 2010
@@ -0,0 +1,62 @@
+package org.apache.commons.compress.archivers;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+public class ExceptionMessageTest extends TestCase {
+       
+       private static final String ARCHIVER_NULL_MESSAGE = "Archivername must 
not be null.";
+       
+       private static final String INPUTSTREAM_NULL_MESSAGE = "InputStream 
must not be null.";
+       
+       private static final String OUTPUTSTREAM_NULL_MESSAGE = "OutputStream 
must not be null.";
+       
+       
+       
+       public void testMessageWhenArchiverNameIsNull_1(){
+               try{
+                       new 
ArchiveStreamFactory().createArchiveInputStream(null, System.in);
+                       fail("Should raise an IllegalArgumentException.");
+               }catch (IllegalArgumentException e) {
+                       Assert.assertEquals(ARCHIVER_NULL_MESSAGE, 
e.getMessage());
+               } catch (ArchiveException e) {
+                       fail("ArchiveException not expected");
+               }
+       }
+       
+       public void testMessageWhenInputStreamIsNull(){
+               try{
+                       new 
ArchiveStreamFactory().createArchiveInputStream("zip", null);
+                       fail("Should raise an IllegalArgumentException.");
+               }catch (IllegalArgumentException e) {
+                       Assert.assertEquals(INPUTSTREAM_NULL_MESSAGE, 
e.getMessage());
+               } catch (ArchiveException e) {
+                       fail("ArchiveException not expected");
+               }
+       }
+       
+       public void testMessageWhenArchiverNameIsNull_2(){
+               try{
+                       new 
ArchiveStreamFactory().createArchiveOutputStream(null, System.out);
+                       fail("Should raise an IllegalArgumentException.");
+               } catch (IllegalArgumentException e) {
+                       Assert.assertEquals(ARCHIVER_NULL_MESSAGE, 
e.getMessage());
+               } catch (ArchiveException e){
+                       fail("ArchiveException not expected");
+               }
+       }
+       
+       public void testMessageWhenOutputStreamIsNull(){
+               try{
+                       new 
ArchiveStreamFactory().createArchiveOutputStream("zip", null);
+                       fail("Should raise an IllegalArgumentException.");
+               } catch (IllegalArgumentException e) {
+                       Assert.assertEquals(OUTPUTSTREAM_NULL_MESSAGE, 
e.getMessage());
+               } catch (ArchiveException e) {
+                       fail("ArchiveException not expected");
+               }
+       }
+       
+       
+
+}
\ No newline at end of file


Reply via email to