View Javadoc
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   * Licensed to the Apache Software Foundation (ASF) under one
15   * or more contributor license agreements.  See the NOTICE file
16   * distributed with this work for additional information
17   * regarding copyright ownership.  The ASF licenses this file
18   * to you under the Apache License, Version 2.0 (the
19   * "License"); you may not use this file except in compliance
20   * with the License.  You may obtain a copy of the License at
21   *
22   *  http://www.apache.org/licenses/LICENSE-2.0
23   *
24   * Unless required by applicable law or agreed to in writing,
25   * software distributed under the License is distributed on an
26   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
27   * KIND, either express or implied.  See the License for the
28   * specific language governing permissions and limitations
29   * under the License.
30   */
31  
32  /**
33   * Tests {@link ApacheLicenseResourceTransformer} parameters.
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 }