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