View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.boolex;
15  
16  import ch.qos.logback.core.Context;
17  import ch.qos.logback.core.ContextBase;
18  import org.junit.jupiter.api.AfterEach;
19  import org.junit.jupiter.api.BeforeEach;
20  import org.junit.jupiter.api.Test;
21  
22  import static org.junit.jupiter.api.Assertions.assertFalse;
23  import static org.junit.jupiter.api.Assertions.assertTrue;
24  
25  public class MatcherTest {
26  
27      Context context;
28      Matcher matcher;
29  
30      @BeforeEach
31      public void setUp() throws Exception {
32          context = new ContextBase();
33          matcher = new Matcher();
34          matcher.setContext(context);
35          matcher.setName("testMatcher");
36      }
37  
38      @AfterEach
39      public void tearDown() throws Exception {
40          matcher = null;
41      }
42  
43      @Test
44      public void testFullRegion() throws Exception {
45          matcher.setRegex(".*test.*");
46          matcher.start();
47          assertTrue(matcher.matches("test"));
48          assertTrue(matcher.matches("xxxxtest"));
49          assertTrue(matcher.matches("testxxxx"));
50          assertTrue(matcher.matches("xxxxtestxxxx"));
51      }
52  
53      public void testPartRegion() throws Exception {
54          matcher.setRegex("test");
55          matcher.start();
56          assertTrue(matcher.matches("test"));
57          assertTrue(matcher.matches("xxxxtest"));
58          assertTrue(matcher.matches("testxxxx"));
59          assertTrue(matcher.matches("xxxxtestxxxx"));
60      }
61  
62      public void testCaseInsensitive() throws Exception {
63          matcher.setRegex("test");
64          matcher.setCaseSensitive(false);
65          matcher.start();
66  
67          assertTrue(matcher.matches("TEST"));
68          assertTrue(matcher.matches("tEst"));
69          assertTrue(matcher.matches("tESt"));
70          assertTrue(matcher.matches("TesT"));
71      }
72  
73      public void testCaseSensitive() throws Exception {
74          matcher.setRegex("test");
75          matcher.setCaseSensitive(true);
76          matcher.start();
77  
78          assertFalse(matcher.matches("TEST"));
79          assertFalse(matcher.matches("tEst"));
80          assertFalse(matcher.matches("tESt"));
81          assertFalse(matcher.matches("TesT"));
82      }
83  }