View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.util;
21  
22  import org.junit.Assert;
23  import org.junit.Test;
24  
25  import java.util.Locale;
26  
27  public class LocaleUtilsUnitTest {
28  
29    private static final Locale D1 = new Locale("de");
30    private static final Locale D2 = new Locale("de", "DE");
31    private static final Locale D3 = new Locale("de", "DE", "NS");
32  
33    private static final String S1 = "de";
34    private static final String S2 = "de_DE";
35    private static final String S3 = "de_DE_NS";
36  
37    private static final String D = "default";
38  
39    @Test
40    public void testCreateLocale() {
41      Assert.assertEquals(D1, LocaleUtils.createLocale(S1));
42      Assert.assertEquals(D2, LocaleUtils.createLocale(S2));
43      Assert.assertEquals(D3, LocaleUtils.createLocale(S3));
44    }
45  
46    @Test
47    public void testLocaleList() {
48      Assert.assertArrayEquals(new Locale[]{D1}, LocaleUtils.getLocaleList(D1).toArray());
49      Assert.assertArrayEquals(new Locale[]{D2, D1}, LocaleUtils.getLocaleList(D2).toArray());
50      Assert.assertArrayEquals(new Locale[]{D3, D2, D1}, LocaleUtils.getLocaleList(D3).toArray());
51    }
52  
53    @Test
54    public void testLocaleSuffixList() {
55      Assert.assertArrayEquals(new String[]{'_' + S1, ""}, LocaleUtils.getLocaleSuffixList(D1).toArray());
56      Assert.assertArrayEquals(new String[]{'_' + S2, '_' + S1, ""}, LocaleUtils.getLocaleSuffixList(D2).toArray());
57      Assert.assertArrayEquals(new String[]{'_' + S3, '_' + S2, '_' + S1, ""},
58          LocaleUtils.getLocaleSuffixList(D3).toArray());
59    }
60  }