01: /**
02: *
03: * Copyright 2004 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.ws.scout.registry.infomodel;
17:
18: import java.util.Locale;
19:
20: import javax.xml.registry.JAXRException;
21: import javax.xml.registry.infomodel.LocalizedString;
22:
23: import junit.framework.TestCase;
24:
25: /**
26: * @version $Revision$ $Date$
27: */
28: public class LocalizedStringTest extends TestCase {
29: public void testEquals() {
30: LocalizedString ls1 = new LocalizedStringImpl(Locale.US,
31: "Equal", "UTF-8");
32: LocalizedString ls2 = new LocalizedStringImpl(Locale.US,
33: "Equal", "UTF-8");
34: assertTrue(ls1.equals(ls2));
35: assertTrue(ls2.equals(ls1));
36: ls2 = new LocalizedStringImpl(Locale.US, "NotEqual", "UTF-8");
37: assertFalse(ls1.equals(ls2));
38: assertFalse(ls2.equals(ls1));
39: ls2 = new LocalizedStringImpl(Locale.US, "Equal", "US-ASCII");
40: assertFalse(ls1.equals(ls2));
41: assertFalse(ls2.equals(ls1));
42: }
43:
44: public void testNullEquals() {
45: LocalizedString ls1 = new LocalizedStringImpl(Locale.US, null,
46: "UTF-8");
47: LocalizedString ls2 = new LocalizedStringImpl(Locale.US, null,
48: "UTF-8");
49: assertTrue(ls1.equals(ls2));
50: assertTrue(ls2.equals(ls1));
51: ls2 = new LocalizedStringImpl(Locale.US, "NotEqual", "UTF-8");
52: assertFalse(ls1.equals(ls2));
53: assertFalse(ls2.equals(ls1));
54: ls2 = new LocalizedStringImpl(Locale.US, null, "US-ASCII");
55: assertFalse(ls1.equals(ls2));
56: assertFalse(ls2.equals(ls1));
57: }
58:
59: public void testSetCharsetName() throws JAXRException {
60: LocalizedString ls1 = new LocalizedStringImpl(Locale.US, "USA",
61: "UTF-8");
62: assertEquals("UTF-8", ls1.getCharsetName());
63: ls1.setCharsetName("US-ASCII");
64: assertEquals("US-ASCII", ls1.getCharsetName());
65: try {
66: ls1.setCharsetName(null);
67: fail("expected IllegalArgumentException for null charsetName");
68: } catch (IllegalArgumentException e) {
69: // ok
70: }
71: }
72:
73: public void testSetLocale() throws JAXRException {
74: LocalizedString ls1 = new LocalizedStringImpl(Locale.US, "USA",
75: "UTF-8");
76: assertEquals(Locale.US, ls1.getLocale());
77: ls1.setLocale(Locale.CANADA);
78: assertEquals(Locale.CANADA, ls1.getLocale());
79: try {
80: ls1.setLocale(null);
81: fail("expected IllegalArgumentException for null locale");
82: } catch (IllegalArgumentException e) {
83: // ok
84: }
85: }
86:
87: public void testSetValue() throws JAXRException {
88: LocalizedString ls1 = new LocalizedStringImpl(Locale.US, "USA",
89: "UTF-8");
90: assertEquals("USA", ls1.getValue());
91: ls1.setValue("Foo");
92: assertEquals("Foo", ls1.getValue());
93: ls1.setValue(null);
94: assertNull(ls1.getValue());
95: }
96: }
|