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.util;
20  
21  import junit.framework.TestCase;
22  
23  import org.apache.rat.analysis.IHeaderMatcher;
24  import org.apache.rat.analysis.MockLicenseMatcher;
25  import org.apache.rat.api.Document;
26  import org.apache.rat.document.MockLocation;
27  import org.apache.rat.report.claim.impl.xml.MockClaimReporter;
28  
29  import java.util.Arrays;
30  
31  public class MatcherMultiplexerTest extends TestCase {
32  
33      private static final String LINE_ONE = "Line One";
34      private static final String LINE_TWO = "Line Two";
35  
36      MockClaimReporter reporter;
37      MockLicenseMatcher matcherOne;
38      MockLicenseMatcher matcherTwo;
39  
40      HeaderMatcherMultiplexer multiplexer;
41  
42      @Override
43      protected void setUp() throws Exception {
44          super.setUp();
45          matcherOne = new MockLicenseMatcher();
46          matcherTwo = new MockLicenseMatcher();
47          multiplexer = new HeaderMatcherMultiplexer(Arrays.<IHeaderMatcher>asList(matcherOne, matcherTwo));
48          reporter = new MockClaimReporter();
49      }
50  
51      @Override
52      protected void tearDown() throws Exception {
53          super.tearDown();
54      }
55  
56      public void testMatcherLine() throws Exception {
57          matcherOne.result = false;
58          matcherTwo.result = false;
59          final Document subject = new MockLocation("subject");
60          multiplexer.match(subject, LINE_ONE);
61          assertEquals("One line", 1, matcherOne.lines.size());
62          assertEquals("Same as line passed", LINE_ONE, matcherOne.lines.get(0));
63          assertEquals("One line", 1, matcherTwo.lines.size());
64          assertEquals("Same as line passed", LINE_ONE, matcherTwo.lines.get(0));
65          multiplexer.match(subject, LINE_TWO);
66          assertEquals("One line", 2, matcherOne.lines.size());
67          assertEquals("Same as line passed", LINE_TWO, matcherOne.lines.get(1));
68          assertEquals("One line", 2, matcherTwo.lines.size());
69          assertEquals("Same as line passed", LINE_TWO, matcherTwo.lines.get(1));
70      }
71  
72      public void testReset() {
73          multiplexer.reset();
74          assertEquals("Reset once", 1, matcherOne.resets);
75          assertEquals("Reset once", 1, matcherTwo.resets);
76          multiplexer.reset();
77          assertEquals("Reset twice", 2, matcherOne.resets);
78          assertEquals("Reset twice", 2, matcherTwo.resets);
79      }
80  }