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 junit.framework.TestCase;
17  import ch.qos.logback.core.Context;
18  import ch.qos.logback.core.ContextBase;
19  
20  public class MatcherTest extends TestCase {
21  
22      Context context;
23      Matcher matcher;
24  
25      public void setUp() throws Exception {
26          context = new ContextBase();
27          matcher = new Matcher();
28          matcher.setContext(context);
29          matcher.setName("testMatcher");
30          super.setUp();
31      }
32  
33      public void tearDown() throws Exception {
34          matcher = null;
35          super.tearDown();
36      }
37  
38      public void testFullRegion() throws Exception {
39          matcher.setRegex(".*test.*");
40          matcher.start();
41          assertTrue(matcher.matches("test"));
42          assertTrue(matcher.matches("xxxxtest"));
43          assertTrue(matcher.matches("testxxxx"));
44          assertTrue(matcher.matches("xxxxtestxxxx"));
45      }
46  
47      public void testPartRegion() throws Exception {
48          matcher.setRegex("test");
49          matcher.start();
50          assertTrue(matcher.matches("test"));
51          assertTrue(matcher.matches("xxxxtest"));
52          assertTrue(matcher.matches("testxxxx"));
53          assertTrue(matcher.matches("xxxxtestxxxx"));
54      }
55  
56      public void testCaseInsensitive() throws Exception {
57          matcher.setRegex("test");
58          matcher.setCaseSensitive(false);
59          matcher.start();
60  
61          assertTrue(matcher.matches("TEST"));
62          assertTrue(matcher.matches("tEst"));
63          assertTrue(matcher.matches("tESt"));
64          assertTrue(matcher.matches("TesT"));
65      }
66  
67      public void testCaseSensitive() throws Exception {
68          matcher.setRegex("test");
69          matcher.setCaseSensitive(true);
70          matcher.start();
71  
72          assertFalse(matcher.matches("TEST"));
73          assertFalse(matcher.matches("tEst"));
74          assertFalse(matcher.matches("tESt"));
75          assertFalse(matcher.matches("TesT"));
76      }
77  }