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.tools;
17:
18: import junit.framework.TestCase;
19:
20: import java.io.File;
21: import java.io.IOException;
22:
23: /**
24: * Testing <code>I18NSync</code>.Cannot be currently run as part of automated
25: * junit tests due to it's code generation.
26: */
27: public class I18NSyncTest_ extends TestCase {
28: static final File CLIENT_SOURCE_DIR = new File(
29: "../../gwt-user/src/test/java");
30: static final String CLIENT_SOURCE_PACKAGE = "com.google.gwt.i18n.client.gen.";
31:
32: /**
33: * Test Constant Creation.
34: *
35: * @throws IOException
36: */
37: public void testConstantCreation() throws IOException {
38:
39: String javaName = CLIENT_SOURCE_PACKAGE + "Colors";
40: // Examine the interface in eclipse for formatting.
41: I18NSync.createConstantsInterfaceFromClassName(javaName,
42: CLIENT_SOURCE_DIR);
43:
44: String target = CLIENT_SOURCE_PACKAGE + "SingleConstant";
45: I18NSync.createConstantsInterfaceFromClassName(target, null);
46: I18NSync.createConstantsInterfaceFromClassName(target,
47: CLIENT_SOURCE_DIR);
48: String empty = CLIENT_SOURCE_PACKAGE + "EmptyConstants";
49: try {
50: I18NSync.createConstantsInterfaceFromClassName(empty,
51: CLIENT_SOURCE_DIR);
52: fail("Should have thrown IllegalStateException");
53: } catch (IllegalStateException e) {
54: // Should be caught
55: }
56: }
57:
58: public void testFileIsDirCase() {
59: try {
60: I18NSync.createMessagesInterfaceFromClassName(
61: CLIENT_SOURCE_PACKAGE, null);
62: fail("Should have thrown IOException");
63: } catch (IOException e) {
64: assertEquals(-1, e.getMessage().indexOf("directory"));
65: }
66: }
67:
68: public void testMainAccess() {
69: // Cannot check bad ones due to System.exit(1);
70: String[] constants = { CLIENT_SOURCE_PACKAGE + "Shapes",
71: "-out", CLIENT_SOURCE_DIR.getPath() };
72: I18NSync.main(constants);
73:
74: String[] messages = { "-createMessages",
75: CLIENT_SOURCE_PACKAGE + "SingleMessages", "-out",
76: CLIENT_SOURCE_DIR.getPath() };
77: I18NSync.main(messages);
78: }
79:
80: public void testMessageCreation() throws IOException {
81: String className = CLIENT_SOURCE_PACKAGE + "TestMessages";
82: I18NSync.createMessagesInterfaceFromClassName(className,
83: CLIENT_SOURCE_DIR);
84: }
85:
86: public void testMethodRenaming() throws IOException {
87: String className = CLIENT_SOURCE_PACKAGE + "TestBadKeys";
88: I18NSync.createConstantsWithLookupInterfaceFromClassName(
89: className, CLIENT_SOURCE_DIR);
90: }
91:
92: public void testWarning() throws IOException {
93: String className = CLIENT_SOURCE_PACKAGE + "TestReallyBadKeys";
94: I18NSync
95: .createConstantsWithLookupInterfaceFromClassName(className);
96: }
97:
98: }
|