KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > i18n > TestCmsLocaleManager


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/i18n/TestCmsLocaleManager.java,v $
3  * Date : $Date: 2005/07/22 10:37:20 $
4  * Version: $Revision: 1.1 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (C) 2002 - 2005 Alkacon Software (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31  
32 package org.opencms.i18n;
33
34 import java.util.ArrayList JavaDoc;
35 import java.util.List JavaDoc;
36 import java.util.Locale JavaDoc;
37
38 import junit.framework.TestCase;
39
40 /**
41  * Tests for the OpenCms locale manager.<p>
42  *
43  * @author Alexander Kandzior
44  *
45  * @version $Revision: 1.1 $
46  *
47  * @since 6.0.0
48  */

49 public class TestCmsLocaleManager extends TestCase {
50
51     /**
52      * Tests selection of the default locale.<p>
53      *
54      * @throws Exception if the test fails
55      */

56     public void testDefaultLocaleSelection() throws Exception JavaDoc {
57         
58         CmsLocaleManager localeManager = new CmsLocaleManager();
59         
60         List JavaDoc available = new ArrayList JavaDoc();
61         
62         localeManager.addDefaultLocale(Locale.US.toString());
63         localeManager.addDefaultLocale(Locale.UK.toString());
64         localeManager.addDefaultLocale(Locale.GERMANY.toString());
65         localeManager.addDefaultLocale(Locale.ENGLISH.toString());
66         localeManager.addDefaultLocale(Locale.GERMAN.toString());
67         
68         available.add(Locale.GERMAN);
69         available.add(Locale.US);
70                 
71         // direct match
72
Locale JavaDoc result = localeManager.getBestMatchingLocale(Locale.GERMAN, localeManager.getDefaultLocales(), available);
73         assertEquals(Locale.GERMAN, result);
74         
75         // simplified direct match
76
result = localeManager.getBestMatchingLocale(Locale.GERMANY, localeManager.getDefaultLocales(), available);
77         assertEquals(Locale.GERMAN, result);
78         
79         // no match, result must be first default
80
result = localeManager.getBestMatchingLocale(Locale.FRENCH, localeManager.getDefaultLocales(), available);
81         assertEquals(Locale.US, result);
82     }
83 }
Popular Tags