01: // Copyright 2006 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.ioc.internal.util;
16:
17: import org.testng.Assert;
18: import org.testng.annotations.Test;
19:
20: public class MessageFormatterImplTest extends Assert {
21: private String run(String format, Object... args) {
22: return new MessageFormatterImpl(format).format(args);
23: }
24:
25: @Test
26: public void standard_args() {
27: assertEquals(run("Tapestry is %s.", "cool"),
28: "Tapestry is cool.");
29: assertEquals(run("Tapestry release #%d.", 5),
30: "Tapestry release #5.");
31: assertEquals(run("%s is %s at version %d.", "Tapestry", "cool",
32: 5), "Tapestry is cool at version 5.");
33: }
34:
35: @Test
36: public void throwable_argument() {
37: Throwable t = new RuntimeException("Just didn't feel right.");
38:
39: assertEquals(run("%s failed: %s", "Something", t),
40: "Something failed: Just didn't feel right.");
41: }
42:
43: @Test
44: public void throwable_argument_with_null_message() {
45: Throwable t = new NullPointerException();
46:
47: assertEquals(run("%s failed: %s", "Something", t),
48: "Something failed: java.lang.NullPointerException");
49: }
50: }
|