1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   */ 
19  package org.apache.rat.analysis.generation;
20  
21  import java.io.BufferedReader;
22  import java.io.File;
23  import java.io.FileReader;
24  
25  import junit.framework.TestCase;
26  
27  import org.apache.rat.api.Document;
28  import org.apache.rat.document.MockLocation;
29  import org.apache.rat.report.claim.impl.xml.MockClaimReporter;
30  import org.apache.rat.test.utils.Resources;
31  
32  public class JavaDocLicenseNotRequiredTest extends TestCase {
33  
34      MockClaimReporter reporter;
35      JavaDocLicenseNotRequired license;
36      
37      protected void setUp() throws Exception {
38          super.setUp();
39          license = new JavaDocLicenseNotRequired();
40          reporter = new MockClaimReporter();
41      }
42  
43      protected void tearDown() throws Exception {
44          super.tearDown();
45      }
46      
47      public void testMatchIndexDoc() throws Exception {
48          boolean result = readAndMatch("index.html");
49          assertTrue("Is a javadoc", result);
50      }
51  
52      public void testMatchClassDoc() throws Exception {
53          boolean result = readAndMatch("ArchiveElement.html");
54          assertTrue("Is a javadoc", result);
55      }
56  
57      public void testMatchNonJavaDoc() throws Exception {
58          boolean result = readAndMatch("notjavadoc.html");
59          assertFalse("Not javadocs and so should return null", result);
60      }
61      
62      boolean readAndMatch(String name) throws Exception {
63          File file = Resources.getResourceFile("javadocs/" + name);
64          boolean result = false;
65          BufferedReader in = new BufferedReader(new FileReader(file));
66          String line = in.readLine();
67          final Document subject = new MockLocation("subject");
68          while (line != null && !result) {
69              result = license.match(subject, line);
70              line = in.readLine();
71          }
72          return result;
73      }
74  }