1 package org.apache.maven.plugins.shade.resource;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.IOException;
5 import java.util.Collections;
6 import java.util.List;
7
8 import junit.framework.TestCase;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 public class ApacheNoticeResourceTransformerParameterTests extends TestCase {
34
35 private static final String NOTICE_RESOURCE = "META-INF/NOTICE";
36 private ApacheNoticeResourceTransformer subject;
37
38 protected void setUp() throws Exception {
39 super.setUp();
40 subject = new ApacheNoticeResourceTransformer();
41 }
42
43
44 public void testNoParametersShouldNotThrowNullPointerWhenNoInput() throws IOException {
45 processAndFailOnNullPointer("");
46 }
47
48 public void testNoParametersShouldNotThrowNullPointerWhenNoLinesOfInput() throws IOException {
49 processAndFailOnNullPointer("Some notice text");
50 }
51
52 public void testNoParametersShouldNotThrowNullPointerWhenOneLineOfInput() throws IOException {
53 processAndFailOnNullPointer("Some notice text\n");
54 }
55
56 public void testNoParametersShouldNotThrowNullPointerWhenTwoLinesOfInput() throws IOException {
57 processAndFailOnNullPointer("Some notice text\nSome notice text\n");
58 }
59
60 public void testNoParametersShouldNotThrowNullPointerWhenLineStartsWithSlashSlash() throws IOException {
61 processAndFailOnNullPointer("Some notice text\n//Some notice text\n");
62 }
63
64 public void testNoParametersShouldNotThrowNullPointerWhenLineIsSlashSlash() throws IOException {
65 processAndFailOnNullPointer("//\n");
66 }
67
68 public void testNoParametersShouldNotThrowNullPointerWhenLineIsEmpty() throws IOException {
69 processAndFailOnNullPointer("\n");
70 }
71
72 private void processAndFailOnNullPointer(final String noticeText)
73 throws IOException {
74 try {
75 final ByteArrayInputStream noticeInputStream = new ByteArrayInputStream(noticeText.getBytes());
76 final List emptyList = Collections.EMPTY_LIST;
77 subject.processResource(NOTICE_RESOURCE, noticeInputStream, emptyList);
78 } catch (NullPointerException e) {
79 fail("Null pointer should not be thrown when no parameters are set.");
80 }
81 }
82 }