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