View Javadoc
1   package org.apache.commons.compress.archivers;
2   
3   import org.junit.Assert;
4   import junit.framework.TestCase;
5   
6   /*
7    * Licensed to the Apache Software Foundation (ASF) under one
8    * or more contributor license agreements.  See the NOTICE file
9    * distributed with this work for additional information
10   * regarding copyright ownership.  The ASF licenses this file
11   * to you under the Apache License, Version 2.0 (the
12   * "License"); you may not use this file except in compliance
13   * with the License.  You may obtain a copy of the License at
14   *
15   * http://www.apache.org/licenses/LICENSE-2.0
16   *
17   * Unless required by applicable law or agreed to in writing,
18   * software distributed under the License is distributed on an
19   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20   * KIND, either express or implied.  See the License for the
21   * specific language governing permissions and limitations
22   * under the License.
23   */
24  public class ExceptionMessageTest extends TestCase {
25  
26      private static final String ARCHIVER_NULL_MESSAGE = "Archivername must not be null.";
27  
28      private static final String INPUTSTREAM_NULL_MESSAGE = "InputStream must not be null.";
29  
30      private static final String OUTPUTSTREAM_NULL_MESSAGE = "OutputStream must not be null.";
31  
32  
33      public void testMessageWhenArchiverNameIsNull_1(){
34          try{
35              new ArchiveStreamFactory().createArchiveInputStream(null, System.in);
36              fail("Should raise an IllegalArgumentException.");
37          }catch (IllegalArgumentException e) {
38              Assert.assertEquals(ARCHIVER_NULL_MESSAGE, e.getMessage());
39          } catch (ArchiveException e) {
40              fail("ArchiveException not expected");
41          }
42      }
43  
44      public void testMessageWhenInputStreamIsNull(){
45          try{
46              new ArchiveStreamFactory().createArchiveInputStream("zip", null);
47              fail("Should raise an IllegalArgumentException.");
48          }catch (IllegalArgumentException e) {
49              Assert.assertEquals(INPUTSTREAM_NULL_MESSAGE, e.getMessage());
50          } catch (ArchiveException e) {
51              fail("ArchiveException not expected");
52          }
53      }
54  
55      public void testMessageWhenArchiverNameIsNull_2(){
56          try{
57              new ArchiveStreamFactory().createArchiveOutputStream(null, System.out);
58              fail("Should raise an IllegalArgumentException.");
59          } catch (IllegalArgumentException e) {
60              Assert.assertEquals(ARCHIVER_NULL_MESSAGE, e.getMessage());
61          } catch (ArchiveException e){
62              fail("ArchiveException not expected");
63          }
64      }
65  
66      public void testMessageWhenOutputStreamIsNull(){
67          try{
68              new ArchiveStreamFactory().createArchiveOutputStream("zip", null);
69              fail("Should raise an IllegalArgumentException.");
70          } catch (IllegalArgumentException e) {
71              Assert.assertEquals(OUTPUTSTREAM_NULL_MESSAGE, e.getMessage());
72          } catch (ArchiveException e) {
73              fail("ArchiveException not expected");
74          }
75      }
76  
77  }