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