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