View Javadoc
1   package org.apache.commons.compress.archivers;
2   
3   import static org.junit.Assert.*;
4   import org.junit.Test;
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 {
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      @Test
34      public void testMessageWhenArchiverNameIsNull_1(){
35          try{
36              new ArchiveStreamFactory().createArchiveInputStream(null, System.in);
37              fail("Should raise an IllegalArgumentException.");
38          }catch (IllegalArgumentException e) {
39              assertEquals(ARCHIVER_NULL_MESSAGE, e.getMessage());
40          } catch (ArchiveException e) {
41              fail("ArchiveException not expected");
42          }
43      }
44  
45      @Test
46      public void testMessageWhenInputStreamIsNull(){
47          try{
48              new ArchiveStreamFactory().createArchiveInputStream("zip", null);
49              fail("Should raise an IllegalArgumentException.");
50          }catch (IllegalArgumentException e) {
51              assertEquals(INPUTSTREAM_NULL_MESSAGE, e.getMessage());
52          } catch (ArchiveException e) {
53              fail("ArchiveException not expected");
54          }
55      }
56  
57      @Test
58      public void testMessageWhenArchiverNameIsNull_2(){
59          try{
60              new ArchiveStreamFactory().createArchiveOutputStream(null, System.out);
61              fail("Should raise an IllegalArgumentException.");
62          } catch (IllegalArgumentException e) {
63              assertEquals(ARCHIVER_NULL_MESSAGE, e.getMessage());
64          } catch (ArchiveException e){
65              fail("ArchiveException not expected");
66          }
67      }
68  
69      @Test
70      public void testMessageWhenOutputStreamIsNull(){
71          try{
72              new ArchiveStreamFactory().createArchiveOutputStream("zip", null);
73              fail("Should raise an IllegalArgumentException.");
74          } catch (IllegalArgumentException e) {
75              assertEquals(OUTPUTSTREAM_NULL_MESSAGE, e.getMessage());
76          } catch (ArchiveException e) {
77              fail("ArchiveException not expected");
78          }
79      }
80  
81  }