1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 public class MatcherMultiplexerTest extends TestCase {
30
31 private static final String LINE_ONE = "Line One";
32 private static final String LINE_TWO = "Line Two";
33
34 MockClaimReporter reporter;
35 MockLicenseMatcher matcherOne;
36 MockLicenseMatcher matcherTwo;
37
38 HeaderMatcherMultiplexer multiplexer;
39
40 protected void setUp() throws Exception {
41 super.setUp();
42 matcherOne = new MockLicenseMatcher();
43 matcherTwo = new MockLicenseMatcher();
44 IHeaderMatcher[] matchers = {matcherOne, matcherTwo};
45 multiplexer = new HeaderMatcherMultiplexer(matchers);
46 reporter = new MockClaimReporter();
47 }
48
49 protected void tearDown() throws Exception {
50 super.tearDown();
51 }
52
53 public void testMatcherLine() throws Exception {
54 matcherOne.result = false;
55 matcherTwo.result = false;
56 final Document subject = new MockLocation("subject");
57 multiplexer.match(subject, LINE_ONE);
58 assertEquals("One line", 1, matcherOne.lines.size());
59 assertEquals("Same as line passed", LINE_ONE, matcherOne.lines.get(0));
60 assertEquals("One line", 1, matcherTwo.lines.size());
61 assertEquals("Same as line passed", LINE_ONE, matcherTwo.lines.get(0));
62 multiplexer.match(subject, LINE_TWO);
63 assertEquals("One line", 2, matcherOne.lines.size());
64 assertEquals("Same as line passed", LINE_TWO, matcherOne.lines.get(1));
65 assertEquals("One line", 2, matcherTwo.lines.size());
66 assertEquals("Same as line passed", LINE_TWO, matcherTwo.lines.get(1));
67 }
68
69 public void testReset() {
70 multiplexer.reset();
71 assertEquals("Reset once", 1, matcherOne.resets);
72 assertEquals("Reset once", 1, matcherTwo.resets);
73 multiplexer.reset();
74 assertEquals("Reset twice", 2, matcherOne.resets);
75 assertEquals("Reset twice", 2, matcherTwo.resets);
76 }
77 }