01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.i18n.rebind.util;
17:
18: import com.google.gwt.i18n.client.ColorsAndShapes;
19: import com.google.gwt.i18n.client.ColorsAndShapesAndConcepts;
20: import com.google.gwt.i18n.client.gen.Colors;
21:
22: import junit.framework.TestCase;
23:
24: import java.io.ByteArrayOutputStream;
25: import java.io.CharArrayWriter;
26: import java.io.OutputStreamWriter;
27: import java.io.PrintWriter;
28: import java.io.UnsupportedEncodingException;
29:
30: /**
31: * TODO: document me.
32: */
33: public class AbstractResourceTest extends TestCase {
34: public static final String UNICODE = "Îñţérñåţîöñåļîžåţîöñ";
35: private static final String LOCALE_NAME_PIGLATIN = "piglatin";
36: private static final String LOCALE_NAME_PIGLATIN_UK = "piglatin_UK";
37:
38: public void testBundle() {
39: // simple test
40: String s = Colors.class.getName();
41: AbstractResource resource = ResourceFactory.getBundle(s, null);
42: assertNotNull(resource);
43: AbstractResource pigLatinResource = ResourceFactory.getBundle(
44: s, LOCALE_NAME_PIGLATIN);
45: assertEquals(LOCALE_NAME_PIGLATIN, pigLatinResource
46: .getLocaleName());
47: assertNotNull(pigLatinResource);
48: assertEquals("ueblay", pigLatinResource.getString("blue"));
49: assertEquals("Ä?réý", pigLatinResource.getString("grey"));
50: }
51:
52: public void testInheritence() {
53: ResourceFactory.clearCache();
54: AbstractResource resource = ResourceFactory.getBundle(
55: ColorsAndShapes.class, LOCALE_NAME_PIGLATIN);
56: assertEquals(LOCALE_NAME_PIGLATIN, resource.getLocaleName());
57: assertEquals("ueblay", resource.getString("blue"));
58: assertEquals("Ä?réý", resource.getString("grey"));
59: }
60:
61: public void testByteStreamBehavior()
62: throws UnsupportedEncodingException {
63: ByteArrayOutputStream s = new ByteArrayOutputStream();
64: OutputStreamWriter writer = new OutputStreamWriter(s, "UTF-8");
65: PrintWriter t = new PrintWriter(writer, true);
66: t.print("Ä?réý");
67: t.close();
68: assertEquals("Ä?réý", s.toString("UTF-8"));
69: assertEquals("Ä?réý", (new String(s.toString("UTF-8")
70: .toCharArray())));
71: }
72:
73: public void testDoubleInherits() {
74: AbstractResource resource = ResourceFactory.getBundle(
75: ColorsAndShapesAndConcepts.class,
76: LOCALE_NAME_PIGLATIN_UK);
77: String s = resource.getString("internationalization");
78: assertEquals("Îñţérñåţîöñåļîžåţîöñ", s);
79: assertTrue(resource.keySet().size() > 5);
80: }
81:
82: public void testCharArrayBehavior() {
83: CharArrayWriter s = new CharArrayWriter();
84: PrintWriter t = new PrintWriter(s, true);
85: t.print(UNICODE);
86: t.close();
87: assertEquals(UNICODE, s.toString());
88: }
89: }
|