1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.rat.header;
21
22 import org.junit.Before;
23 import org.junit.Test;
24
25 import java.io.StringReader;
26 import java.util.regex.Pattern;
27
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertTrue;
30
31 public class HeaderMatcherWithBeansTest {
32
33 private int capacity;
34 private HeaderMatcher matcher;
35 private SimpleCharFilter filter;
36 private HeaderBean[] beans;
37
38 @Before
39 public void setUp() throws Exception {
40 HeaderBean[] beans = {
41 new HeaderBean(),
42 new HeaderBean(),
43 new HeaderBean()
44 };
45 this.beans = beans;
46 capacity = 20;
47 filter = new SimpleCharFilter();
48 matcher = new HeaderMatcher(filter, 20, beans);
49 }
50
51 @Test
52 public void nulls() throws Exception {
53 beans[0].setMatch(false);
54 beans[1].setMatch(true);
55 beans[2].setMatch(false);
56 StringReader reader = new StringReader("Whatever");
57 matcher.read(reader);
58 assertFalse("State preserved", beans[0].isMatch());
59 assertTrue("State preserved", beans[1].isMatch());
60 assertFalse("State preserved", beans[2].isMatch());
61 beans[0].setMatch(true);
62 beans[1].setMatch(false);
63 beans[2].setMatch(true);
64 assertTrue("State preserved", beans[0].isMatch());
65 assertFalse("State preserved", beans[1].isMatch());
66 assertTrue("State preserved", beans[2].isMatch());
67 }
68
69 @Test
70 public void matches() throws Exception {
71 beans[0].setHeaderPattern(Pattern.compile("What(.*)"));
72 beans[1].setHeaderPattern(Pattern.compile("(.*)ever"));
73 beans[2].setHeaderPattern(Pattern.compile("What"));
74 StringReader reader = new StringReader("Whatever");
75 matcher.read(reader);
76 assertTrue("Match header pattern", beans[0].isMatch());
77 assertTrue("Match header pattern", beans[1].isMatch());
78 assertFalse("Match header pattern", beans[2].isMatch());
79 }
80 }