View Javadoc
1   package com.atlassian.plugin.servlet.filter;
2   
3   import org.junit.Test;
4   
5   import java.util.Locale;
6   
7   import static org.junit.Assert.assertEquals;
8   import static org.junit.Assert.fail;
9   
10  public class TestFilterLocation {
11      @Test
12      public void testParse() {
13          assertEquals(FilterLocation.AFTER_ENCODING, FilterLocation.parse("after-encoding"));
14          assertEquals(FilterLocation.AFTER_ENCODING, FilterLocation.parse("after_encoding"));
15          assertEquals(FilterLocation.AFTER_ENCODING, FilterLocation.parse("After-Encoding"));
16          try {
17              FilterLocation.parse(null);
18              fail();
19          } catch (IllegalArgumentException ex) {
20              // test passed
21          }
22          try {
23              FilterLocation.parse("asf");
24              fail();
25          } catch (IllegalArgumentException ex) {
26              // test passed
27          }
28      }
29  
30      @Test
31      public void testParseWithTurkishCharacters() {
32          Locale defLocale = Locale.getDefault();
33          try {
34              Locale.setDefault(new Locale("tr", "", ""));
35              assertEquals(FilterLocation.BEFORE_LOGIN, FilterLocation.parse("before-log\u0069n"));
36              assertEquals(FilterLocation.BEFORE_LOGIN, FilterLocation.parse("before-log\u0131n"));
37              assertEquals(FilterLocation.BEFORE_LOGIN, FilterLocation.parse("before-login"));
38          } finally {
39              Locale.setDefault(defLocale);
40          }
41      }
42  }