View Javadoc
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.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  }