1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.analysis.license;
20
21 import org.apache.rat.api.Document;
22 import org.apache.rat.api.MetaData;
23 import org.apache.rat.document.MockLocation;
24 import org.apache.rat.report.claim.impl.xml.MockClaimReporter;
25 import org.junit.Before;
26 import org.junit.Test;
27
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertTrue;
30
31 public class CopyrightHeaderTest {
32
33 private static final String[] MATCHING_HEADERS =
34 { "/* Copyright 2012 FooBar.*/"
35 , "/* copyright 2012 foobar.*/"
36 , "/* Copyright 2012-2013 FooBar.*/" };
37 private static final String[] NON_MATCHING_HEADERS =
38 { "/* Copyright*/"
39 , "/* Copyright FooBar.*/"
40 , "/* Copyright 2013*/"
41 , "/* Copyright 123a*/"
42 , "/* Copyright 123f oobar*/"
43 , "/* Copyright 2013FooBar*/"
44 , "/* Copyright 2012 2013 FooBar.*/" };
45
46 CopyrightHeader header;
47 MockClaimReporter reporter;
48 Document subject = new MockLocation("subject");
49
50 @Before
51 public void setUp() throws Exception {
52 header = new CopyrightHeader(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_ASL,MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_APACHE_LICENSE_VERSION_2_0,"","FooBar");
53 reporter = new MockClaimReporter();
54 subject = new MockLocation("subject");
55 }
56
57 @Test
58 public void match() throws Exception {
59 for (String line : MATCHING_HEADERS) {
60 assertTrue("Copyright Header should be matched", header.match(subject, line));
61 header.reset();
62 assertFalse("After reset, content should build up again", header.match(subject, "New line"));
63 header.reset();
64 }
65 }
66
67 @Test
68 public void noMatch() throws Exception {
69 for (String line : NON_MATCHING_HEADERS) {
70 assertFalse("Copyright Header shouldn't be matched", header.match(subject, line));
71 header.reset();
72 assertTrue("After reset, content should build up again", header.match(subject, MATCHING_HEADERS[0]));
73 header.reset();
74 }
75 }
76 }