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.util;
15  
16  import org.junit.After;
17  import org.junit.Ignore;
18  import org.junit.Test;
19  
20  import java.text.DateFormatSymbols;
21  import java.util.Locale;
22  
23  import static org.junit.Assert.assertTrue;
24  import static org.junit.Assert.assertEquals;
25  
26  public class CharSequenceToRegexMapperTest {
27      static Locale KO_LOCALE = new Locale("ko", "KR");
28      Locale oldLocale = Locale.getDefault();
29  
30      @After
31      public void tearDown() {
32          Locale.setDefault(oldLocale);
33      }
34  
35      @Test
36      public void findMinMaxLengthsInSymbolsWithTrivialInputs() {
37          String[] symbols = new String[] { "a", "bb" };
38          int[] results = CharSequenceToRegexMapper.findMinMaxLengthsInSymbols(symbols);
39          assertEquals(1, results[0]);
40          assertEquals(2, results[1]);
41      }
42  
43      @Test
44      public void emptyStringValuesShouldBeIgnoredByFindMinMaxLengthsInSymbols() {
45          String[] symbols = new String[] { "aaa", "" };
46          int[] results = CharSequenceToRegexMapper.findMinMaxLengthsInSymbols(symbols);
47          assertEquals(3, results[0]);
48          assertEquals(3, results[1]);
49      }
50  
51      @Test
52      @Ignore
53      public void noneOfTheSymbolsAreOfZeroLengthForKorean() {
54          Locale.setDefault(KO_LOCALE);
55          noneOfTheSymbolsAreOfZeroLength();
56      }
57  
58      @Test
59      @Ignore
60      public void noneOfTheSymbolsAreOfZeroLengthForSwiss() {
61          Locale.setDefault(new Locale("fr", "CH"));
62          noneOfTheSymbolsAreOfZeroLength();
63      }
64  
65      private void noneOfTheSymbolsAreOfZeroLength() {
66          DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance();
67          // checkEmptyString(dateFormatSymbols.getShortMonths(), "ShortMonths");
68          // checkEmptyString(dateFormatSymbols.getMonths(), "Months");
69          checkEmptyString(dateFormatSymbols.getShortWeekdays(), "ShortWeekdays");
70          checkEmptyString(dateFormatSymbols.getWeekdays(), "Weekdays");
71          checkEmptyString(dateFormatSymbols.getAmPmStrings(), "AmPmStrings");
72  
73      }
74  
75      private void checkEmptyString(String[] symbolArray, String category) {
76          for (String s : symbolArray) {
77              System.out.println(category + " [" + s + "]");
78              assertTrue(category + " contains empty strings", s.length() > 0);
79          }
80      }
81  
82  }