1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }