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.matchers;
20  
21  
22  import org.junit.jupiter.api.BeforeEach;
23  import org.junit.jupiter.api.Test;
24  
25  import static org.junit.jupiter.api.Assertions.assertEquals;
26  
27  import org.apache.rat.analysis.IHeaderMatcher.State;
28  
29  public class FullTextMatcherTest {
30  
31      FullTextMatcher target = new FullTextMatcher("Hello world");
32      
33      @BeforeEach
34      public void setup() {
35          target.reset();
36      }
37      
38      @Test
39      public void testMatch() {
40          assertEquals( State.i, target.currentState());
41          assertEquals( State.i, target.matches("what in the world"));
42          assertEquals( State.i, target.currentState());
43          assertEquals( State.t, target.matches("hello world"));
44          assertEquals( State.t, target.currentState());
45          assertEquals( State.t, target.finalizeState()); 
46          assertEquals( State.t, target.currentState());
47          target.reset();
48          assertEquals( State.i, target.currentState());
49      }
50      
51      @Test
52      public void testNoMatch() {
53          assertEquals( State.i, target.currentState());
54          assertEquals( State.i, target.matches("what in the world"));
55          assertEquals( State.i, target.currentState());
56          assertEquals( State.i, target.matches("hello there"));
57          assertEquals( State.i, target.currentState());
58          assertEquals( State.f, target.finalizeState());
59          assertEquals( State.f, target.currentState());
60          target.reset();
61          assertEquals( State.i, target.currentState());
62      }
63      
64      @Test
65      public void testTrueIsAlwaysTrue() {
66          assertEquals( State.i, target.currentState());
67          assertEquals( State.t, target.matches("hello world"));
68          assertEquals( State.t, target.currentState());
69          assertEquals( State.t, target.matches("A non matching line"));
70          assertEquals( State.t, target.currentState());        
71          assertEquals( State.t, target.finalizeState()); 
72          assertEquals( State.t, target.currentState());
73          target.reset();
74          assertEquals( State.i, target.currentState());
75      }
76  }