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 org.apache.commons.io.IOUtils;
22 import org.apache.rat.api.Document;
23 import org.apache.rat.document.MockLocation;
24 import org.apache.rat.report.claim.impl.xml.MockClaimReporter;
25 import org.apache.rat.test.utils.Resources;
26 import org.junit.Before;
27 import org.junit.Test;
28
29 import java.io.BufferedReader;
30 import java.io.File;
31 import java.io.FileReader;
32
33 import static org.junit.Assert.assertFalse;
34 import static org.junit.Assert.assertTrue;
35
36 public class JavaDocLicenseNotRequiredTest {
37
38 private MockClaimReporter reporter;
39 private JavaDocLicenseNotRequired license;
40
41 @Before
42 public void setUp() throws Exception {
43 license = new JavaDocLicenseNotRequired();
44 reporter = new MockClaimReporter();
45 }
46
47 @Test
48 public void matchIndexDoc() throws Exception {
49 boolean result = readAndMatch("index.html");
50 assertTrue("Is a javadoc", result);
51 }
52
53 @Test
54 public void matchClassDoc() throws Exception {
55 boolean result = readAndMatch("ArchiveElement.html");
56 assertTrue("Is a javadoc", result);
57 }
58
59 @Test
60 public void matchNonJavaDoc() throws Exception {
61 boolean result = readAndMatch("notjavadoc.html");
62 assertFalse("Not javadocs and so should return null", result);
63 }
64
65 boolean readAndMatch(String name) throws Exception {
66 File file = Resources.getResourceFile("javadocs/" + name);
67 boolean result = false;
68 BufferedReader in = null;
69 try {
70 in = new BufferedReader(new FileReader(file));
71 String line = in.readLine();
72 final Document subject = new MockLocation("subject");
73 while (line != null && !result) {
74 result = license.match(subject, line);
75 line = in.readLine();
76 }
77 } finally {
78 IOUtils.closeQuietly(in);
79 }
80 return result;
81 }
82 }