1   /**
2    * This program is free software: you can redistribute it and/or modify
3    * it under the terms of the GNU General Public License as published by
4    * the Free Software Foundation, version 3.
5    *
6    * This program is distributed in the hope that it will be useful,
7    * but WITHOUT ANY WARRANTY; without even the implied warranty of
8    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9    * GNU General Public License for more details.
10   *
11   * You should have received a copy of the GNU General Public License
12   * along with this program. If not, see <http://www.gnu.org/licenses/>.
13   */
14  
15  package net.curre.prefcount.util;
16  
17  import java.util.logging.Logger;
18  
19  import net.curre.prefcount.test.BaseTestCase;
20  
21  import org.apache.commons.lang.StringUtils;
22  
23  /**
24   * This is a junit test for testing <code>LocaleExt</code> class.
25   * <p/>
26   * Created date: Nov 25, 2007
27   *
28   * @author Yevgeny Nyden
29   */
30  public class LocaleExtTest extends BaseTestCase {
31  
32    /** Private class logger. */
33    private static Logger log = Logger.getLogger(LocaleExtTest.class.toString());
34  
35    /**
36     * Tests constructor.
37     *
38     * @throws Exception on error.
39     */
40    public void testConstructor() throws Exception {
41  
42      log.info("Running testConstructor()...");
43  
44      final String dispLang = "\u0420\u0443\u0441\u0441\u043A\u0438\u0439";
45      LocaleExt loc = new LocaleExt("ru", "RU", dispLang);
46      assertNotNull("Locale is null", loc.getLocale());
47      assertEquals("Wrong locale's country", "RU", loc.getLocale().getCountry());
48      assertEquals("Wrong locale's language", "ru", loc.getLocale().getLanguage());
49      assertEquals("Wrong display language", dispLang, loc.getDisplayLanguage());
50      assertNotNull("Enabled icon reference is null", loc.getEnabledIcon());
51      assertNotNull("Disabled icon reference is null", loc.getDisabledIcon());
52    }
53  
54    /**
55     * Tests the equals method.
56     *
57     * @throws Exception on error.
58     */
59    public void testEquals() throws Exception {
60  
61      log.info("Running testEquals()...");
62  
63      LocaleExt loc0 = new LocaleExt("ru", "RU", "\u0420\u0443\u0441\u0441\u043A\u0438\u0439");
64      assertNotNull("RU locale is null", loc0.getLocale());
65  
66      LocaleExt loc1 = new LocaleExt("us", "US", "English US");
67      assertNotNull("First US locale is null", loc1.getLocale());
68  
69      LocaleExt loc2 = new LocaleExt("us", "US", "Another English US");
70      assertNotNull("Second US locale is null", loc2.getLocale());
71  
72      assertFalse("RU and US locales should not be equal", loc0.equals(loc1));
73      assertTrue("Locale should be equal to itself", loc0.equals(loc0));
74      assertTrue("Different display language should not make locale different", loc1.equals(loc2));
75      Object o = "TESTY";
76      assertFalse("Locale should not be equal to a string", loc0.equals(o));
77      o = null;
78      assertFalse("Locale should not be equal to null", loc0.equals(o));
79    }
80  
81    /**
82     * Tests the hashCode method.
83     *
84     * @throws Exception on error.
85     */
86    public void testHashCode() throws Exception {
87  
88      log.info("Running testHashCode()...");
89  
90      LocaleExt loc = new LocaleExt("us", "US", "English US");
91      assertNotNull("US locale is null", loc.getLocale());
92  
93      assertEquals("ExtLocale's hash code should be the same as of it's locale's",
94                   loc.getLocale().hashCode(), loc.hashCode());
95    }
96  
97    /**
98     * Tests miscellaneous functionality.
99     *
100    * @throws Exception on error.
101    */
102   public void testMiscellaneous() throws Exception {
103 
104     log.info("Running testMiscellaneous()...");
105 
106     LocaleExt loc = new LocaleExt("us", "US", "English US");
107     assertTrue("toString() is blank", StringUtils.isNotBlank(loc.toString()));
108   }
109 
110   /** Private methods ***********************/
111 
112 }