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 junit.framework.TestCase;
9   
10  
11  /*
12   * Licensed to the Apache Software Foundation (ASF) under one
13   * or more contributor license agreements.  See the NOTICE file
14   * distributed with this work for additional information
15   * regarding copyright ownership.  The ASF licenses this file
16   * to you under the Apache License, Version 2.0 (the
17   * "License"); you may not use this file except in compliance
18   * with the License.  You may obtain a copy of the License at
19   *
20   *  http://www.apache.org/licenses/LICENSE-2.0
21   *
22   * Unless required by applicable law or agreed to in writing,
23   * software distributed under the License is distributed on an
24   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
25   * KIND, either express or implied.  See the License for the
26   * specific language governing permissions and limitations
27   * under the License.
28   */
29  
30  /**
31   * Tests {@link ApacheLicenseResourceTransformer} parameters.
32   */
33  public class ApacheNoticeResourceTransformerParameterTests extends TestCase {
34  	
35  	private static final String NOTICE_RESOURCE = "META-INF/NOTICE";
36  	private ApacheNoticeResourceTransformer subject;
37  
38  	protected void setUp() throws Exception {
39  		super.setUp();
40  		subject = new ApacheNoticeResourceTransformer();
41  	}
42  
43  	
44  	public void testNoParametersShouldNotThrowNullPointerWhenNoInput() throws IOException {
45  		processAndFailOnNullPointer("");
46  	}
47  	
48  	public void testNoParametersShouldNotThrowNullPointerWhenNoLinesOfInput() throws IOException {
49  		processAndFailOnNullPointer("Some notice text");
50  	}
51  
52  	public void testNoParametersShouldNotThrowNullPointerWhenOneLineOfInput() throws IOException {
53  		processAndFailOnNullPointer("Some notice text\n");
54  	}
55  
56  	public void testNoParametersShouldNotThrowNullPointerWhenTwoLinesOfInput() throws IOException {
57  		processAndFailOnNullPointer("Some notice text\nSome notice text\n");
58  	}
59  
60  	public void testNoParametersShouldNotThrowNullPointerWhenLineStartsWithSlashSlash() throws IOException {
61  		processAndFailOnNullPointer("Some notice text\n//Some notice text\n");
62  	}
63  
64  	public void testNoParametersShouldNotThrowNullPointerWhenLineIsSlashSlash() throws IOException {
65  		processAndFailOnNullPointer("//\n");
66  	}
67  
68  	public void testNoParametersShouldNotThrowNullPointerWhenLineIsEmpty() throws IOException {
69  		processAndFailOnNullPointer("\n");
70  	}
71  	
72  	private void processAndFailOnNullPointer(final String noticeText)
73  			throws IOException {
74  		try {
75  			final ByteArrayInputStream noticeInputStream = new ByteArrayInputStream(noticeText.getBytes());
76  			final List emptyList = Collections.EMPTY_LIST;
77  			subject.processResource(NOTICE_RESOURCE, noticeInputStream, emptyList);
78  		} catch (NullPointerException e) {
79  			fail("Null pointer should not be thrown when no parameters are set.");
80  		}
81  	}
82  }