This project has retired. For details please refer to its Attic page.
LocalizedStringTest xref
View Javadoc
1   /**
2    *
3    * Copyright 2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  package org.apache.ws.scout.registry.infomodel;
18  
19  import java.util.Locale;
20  
21  import javax.xml.registry.JAXRException;
22  import javax.xml.registry.infomodel.LocalizedString;
23  
24  import junit.framework.TestCase;
25  
26  /**
27   * @version $Revision$ $Date$
28   */
29  public class LocalizedStringTest extends TestCase {
30      public void testEquals() {
31          LocalizedString ls1 = new LocalizedStringImpl(Locale.US, "Equal", "UTF-8");
32          LocalizedString ls2 = new LocalizedStringImpl(Locale.US, "Equal", "UTF-8");
33          assertTrue(ls1.equals(ls2));
34          assertTrue(ls2.equals(ls1));
35          ls2 = new LocalizedStringImpl(Locale.US, "NotEqual", "UTF-8");
36          assertFalse(ls1.equals(ls2));
37          assertFalse(ls2.equals(ls1));
38          ls2 = new LocalizedStringImpl(Locale.US, "Equal", "US-ASCII");
39          assertFalse(ls1.equals(ls2));
40          assertFalse(ls2.equals(ls1));
41      }
42  
43      public void testNullEquals() {
44          LocalizedString ls1 = new LocalizedStringImpl(Locale.US, null, "UTF-8");
45          LocalizedString ls2 = new LocalizedStringImpl(Locale.US, null, "UTF-8");
46          assertTrue(ls1.equals(ls2));
47          assertTrue(ls2.equals(ls1));
48          ls2 = new LocalizedStringImpl(Locale.US, "NotEqual", "UTF-8");
49          assertFalse(ls1.equals(ls2));
50          assertFalse(ls2.equals(ls1));
51          ls2 = new LocalizedStringImpl(Locale.US, null, "US-ASCII");
52          assertFalse(ls1.equals(ls2));
53          assertFalse(ls2.equals(ls1));
54      }
55  
56      public void testSetCharsetName() throws JAXRException {
57          LocalizedString ls1 = new LocalizedStringImpl(Locale.US, "USA", "UTF-8");
58          assertEquals("UTF-8", ls1.getCharsetName());
59          ls1.setCharsetName("US-ASCII");
60          assertEquals("US-ASCII", ls1.getCharsetName());
61          try {
62              ls1.setCharsetName(null);
63              fail("expected IllegalArgumentException for null charsetName");
64          } catch (IllegalArgumentException e) {
65              // ok
66          }
67      }
68  
69      public void testSetLocale() throws JAXRException {
70          LocalizedString ls1 = new LocalizedStringImpl(Locale.US, "USA", "UTF-8");
71          assertEquals(Locale.US, ls1.getLocale());
72          ls1.setLocale(Locale.CANADA);
73          assertEquals(Locale.CANADA, ls1.getLocale());
74          try {
75              ls1.setLocale(null);
76              fail("expected IllegalArgumentException for null locale");
77          } catch (IllegalArgumentException e) {
78              // ok
79          }
80      }
81  
82      public void testSetValue() throws JAXRException {
83          LocalizedString ls1 = new LocalizedStringImpl(Locale.US, "USA", "UTF-8");
84          assertEquals("USA", ls1.getValue());
85          ls1.setValue("Foo");
86          assertEquals("Foo", ls1.getValue());
87          ls1.setValue(null);
88          assertNull(ls1.getValue());
89      }
90  }