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.jupiter.api.AfterEach;
17  import org.junit.jupiter.api.Assertions;
18  import org.junit.jupiter.api.Disabled;
19  import org.junit.jupiter.api.Test;
20  
21  import java.text.DateFormatSymbols;
22  import java.util.Locale;
23  
24  import static org.junit.jupiter.api.Assertions.assertEquals;
25  
26  public class CharSequenceToRegexMapperTest {
27      static Locale KO_LOCALE = new Locale("ko", "KR");
28      Locale oldLocale = Locale.getDefault();
29  
30      @AfterEach
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      @Disabled
53      public void noneOfTheSymbolsAreOfZeroLengthForKorean() {
54          Locale.setDefault(KO_LOCALE);
55          noneOfTheSymbolsAreOfZeroLength();
56      }
57  
58      @Test
59      @Disabled
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              Assertions.assertTrue(s.length() > 0, category + " contains empty strings");
79          }
80      }
81  
82  }