01: /*
02: * Copyright 2003-2006 Rick Knowles <winstone-devel at lists sourceforge net>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: */
07: package winstone.testCase;
08:
09: import junit.framework.TestCase;
10: import winstone.WinstoneResourceBundle;
11:
12: /**
13: * Simple tests for the string replacer
14: *
15: * @author <a href="mailto:rick_knowles@hotmail.com">Rick Knowles</a>
16: * @version $Id: WinstoneResourceBundleTest.java,v 1.1 2006/11/09 05:39:43 rickknowles Exp $
17: */
18: public class WinstoneResourceBundleTest extends TestCase {
19:
20: public static void testGlobalReplace() throws Exception {
21: assertEquals("One token", "Foo = bar squared",
22: WinstoneResourceBundle.globalReplace(
23: "Foo = [#0] squared", "[#0]", "bar"));
24: assertEquals("Repeated token", "Foo = bar bar squared",
25: WinstoneResourceBundle.globalReplace(
26: "Foo = [#0] [#0] squared", "[#0]", "bar"));
27: assertEquals("Two tokens", "Foo = blah bar squared",
28: WinstoneResourceBundle
29: .globalReplace("Foo = [#1] [#0] squared",
30: new String[][] { { "[#0]", "bar" },
31: { "[#1]", "blah" } }));
32: }
33:
34: // public static void testSpeed() throws Exception {
35: // String tokens[][] = new String[20][2];
36: // for (int n = 0; n < tokens.length; n++) {
37: // tokens[n] = new String[] {"[#" + n + "]", "token" + n};
38: // }
39: // Random rnd = new Random();
40: // String inputs[] = new String[5000];
41: // for (int n = 0; n < inputs.length; n++) {
42: // inputs[n] = "";
43: // for (int k = 0; k < tokens.length; k++) {
44: // inputs[n] += "[#" + (rnd.nextInt() % tokens.length) + "] abc";
45: // }
46: // }
47: //
48: // long startTime = System.currentTimeMillis();
49: // for (int n = 0; n < inputs.length; n++) {
50: // WinstoneResourceBundle.globalReplace(inputs[n], tokens);
51: // }
52: // System.out.println("Replaced " + tokens.length + " tokens in " + inputs.length + " strings in " +
53: // (System.currentTimeMillis() - startTime) + "ms");
54: // }
55: }
|