1 package org.apache.commons.compress.archivers;
2
3 import org.junit.Assert;
4 import junit.framework.TestCase;
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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 }