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 import java.util.Locale;
26
27 import org.apache.maven.plugins.shade.relocation.Relocator;
28 import org.junit.Before;
29 import org.junit.Test;
30
31 import static org.junit.Assert.assertFalse;
32 import static org.junit.Assert.assertTrue;
33 import static org.junit.Assert.fail;
34
35
36
37
38
39
40 public class ApacheNoticeResourceTransformerTest {
41
42 private static final String NOTICE_RESOURCE = "META-INF/NOTICE";
43 private ApacheNoticeResourceTransformer transformer;
44
45 static {
46
47
48
49
50 Locale.setDefault(new Locale("tr"));
51 }
52
53 @Before
54 public void setUp() {
55 transformer = new ApacheNoticeResourceTransformer();
56 }
57
58 @Test
59 public void testCanTransformResource() {
60 assertTrue(transformer.canTransformResource("META-INF/NOTICE"));
61 assertTrue(transformer.canTransformResource("META-INF/NOTICE.TXT"));
62 assertTrue(transformer.canTransformResource("META-INF/NOTICE.md"));
63 assertTrue(transformer.canTransformResource("META-INF/Notice.txt"));
64 assertTrue(transformer.canTransformResource("META-INF/Notice.md"));
65 assertFalse(transformer.canTransformResource("META-INF/MANIFEST.MF"));
66 }
67
68 @Test
69 public void testNoParametersShouldNotThrowNullPointerWhenNoInput() throws IOException {
70 processAndFailOnNullPointer("");
71 }
72
73 @Test
74 public void testNoParametersShouldNotThrowNullPointerWhenNoLinesOfInput() throws IOException {
75 processAndFailOnNullPointer("Some notice text");
76 }
77
78 @Test
79 public void testNoParametersShouldNotThrowNullPointerWhenOneLineOfInput() throws IOException {
80 processAndFailOnNullPointer("Some notice text\n");
81 }
82
83 @Test
84 public void testNoParametersShouldNotThrowNullPointerWhenTwoLinesOfInput() throws IOException {
85 processAndFailOnNullPointer("Some notice text\nSome notice text\n");
86 }
87
88 @Test
89 public void testNoParametersShouldNotThrowNullPointerWhenLineStartsWithSlashSlash() throws IOException {
90 processAndFailOnNullPointer("Some notice text\n//Some notice text\n");
91 }
92
93 @Test
94 public void testNoParametersShouldNotThrowNullPointerWhenLineIsSlashSlash() throws IOException {
95 processAndFailOnNullPointer("//\n");
96 }
97
98 @Test
99 public void testNoParametersShouldNotThrowNullPointerWhenLineIsEmpty() throws IOException {
100 processAndFailOnNullPointer("\n");
101 }
102
103 private void processAndFailOnNullPointer(final String noticeText) throws IOException {
104 try {
105 final ByteArrayInputStream noticeInputStream = new ByteArrayInputStream(noticeText.getBytes());
106 final List<Relocator> emptyList = Collections.emptyList();
107 transformer.processResource(NOTICE_RESOURCE, noticeInputStream, emptyList, 0);
108 noticeInputStream.close();
109 } catch (NullPointerException e) {
110 fail("Null pointer should not be thrown when no parameters are set.");
111 }
112 }
113 }