01: /* Licensed to the Apache Software Foundation (ASF) under one or more
02: * contributor license agreements. See the NOTICE file distributed with
03: * this work for additional information regarding copyright ownership.
04: * The ASF licenses this file to You under the Apache License, Version 2.0
05: * (the "License"); you may not use this file except in compliance with
06: * the License. You may obtain a copy of 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,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.harmony.luni.tests.util;
18:
19: import org.apache.harmony.luni.util.MsgHelp;
20:
21: import junit.framework.TestCase;
22:
23: public class MsgHelpTest extends TestCase {
24:
25: public MsgHelpTest(String name) {
26: super (name);
27: }
28:
29: /*
30: * Test method for 'org.apache.harmony.luni.util.MsgHelp.format(String,
31: * Object[])'
32: */
33: public void testFormatLjava_lang_String$Ljava_lang_Object() {
34: assertEquals("empty", MsgHelp.format("empty", new Object[0]));
35:
36: assertEquals("<null>", MsgHelp.format("{0}", new Object[1]));
37: assertEquals("<missing argument>", MsgHelp.format("{0}",
38: new Object[0]));
39: assertEquals("fixture {} fixture", MsgHelp.format(
40: "{0} \\{} {0}", new Object[] { "fixture" }));
41:
42: assertEquals("<null> fixture", MsgHelp.format("{0} {1}",
43: new Object[] { null, "fixture" }));
44: assertEquals("<null> fixture <missing argument>",
45: MsgHelp.format("{0} {1} {2}", new Object[] { null,
46: "fixture" }));
47: assertEquals("<null> fixture", MsgHelp.format("{0} {1}",
48: new Object[] { null, "fixture", "extra" }));
49:
50: assertEquals("0 1 2 3 4 5 6 7 8 9", MsgHelp.format(
51: "{0} {1} {2} {3} {4} {5} {6} {7} {8} {9}",
52: new Object[] { "0", "1", "2", "3", "4", "5", "6", "7",
53: "8", "9" }));
54: assertEquals("9 8 7 6 5 4 3 2 1 0", MsgHelp.format(
55: "{0} {1} {2} {3} {4} {5} {6} {7} {8} {9}",
56: new Object[] { "9", "8", "7", "6", "5", "4", "3", "2",
57: "1", "0" }));
58:
59: assertEquals("0 1 2 3 4 5 6 7 8 9 {10}", MsgHelp.format(
60: "{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10}",
61: new Object[] { "0", "1", "2", "3", "4", "5", "6", "7",
62: "8", "9", "10" }));
63:
64: try {
65: MsgHelp.format(null, new Object[0]);
66: fail("No NPE");
67: } catch (NullPointerException e) {
68: }
69:
70: try {
71: MsgHelp.format("fixture", null);
72: fail("No NPE");
73: } catch (NullPointerException e) {
74: }
75: }
76:
77: }
|