KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > i18n > test > AbstractBundleTestCase


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.i18n.test;
9
10 import java.util.Map JavaDoc;
11 import java.util.HashMap JavaDoc;
12
13 import org.apache.avalon.excalibur.testcase.ExcaliburTestCase;
14 import org.apache.avalon.excalibur.i18n.AbstractBundle;
15
16 /**
17  * @author <a HREF="mailto:neeme@apache.org">Neeme Praks</a>
18  * @version $Id: AbstractBundleTestCase.java,v 1.8 2001/12/11 09:53:35 jefft Exp $
19  */

20 public class AbstractBundleTestCase extends ExcaliburTestCase {
21
22     private TestBundle bundle = new TestBundle();
23     private Map JavaDoc variables = new HashMap JavaDoc(5);
24
25     public AbstractBundleTestCase( String JavaDoc name ) {
26         super(name);
27     }
28
29     public void setUp() throws Exception JavaDoc {
30         this.variables.put("nice", "not so nice");
31         this.variables.put("bad", "too bad");
32         this.variables.put("value", "a cat");
33
34         this.bundle.enableLogging( getLogEnabledLogger() );
35         this.bundle.put("cat", "Here is an example of {value}.");
36         this.bundle.put("nice", "This is a {nice} test!");
37         this.bundle.put("nice.nice", "This is a {nice}, {nice} test!");
38         this.bundle.put("nice.bad", "This is a {nice} but not {bad} test!");
39         this.bundle.put("test.plain", "This is a test!");
40         this.bundle.put("test.empty", "");
41     }
42
43     public void tearDown() throws Exception JavaDoc {
44         this.variables.clear();
45         this.bundle.store.clear();
46     }
47
48     public void testSubstitute() {
49         assertEquals("This is a not so nice test!", this.bundle.getString("nice", variables));
50         assertEquals("This is a not so nice, not so nice test!", this.bundle.getString("nice.nice", variables));
51         assertEquals("This is a not so nice but not too bad test!", this.bundle.getString("nice.bad", variables));
52         assertEquals("This is a test!", this.bundle.getString("test.plain", variables));
53         assertEquals("", this.bundle.getString("test.empty", variables));
54         assertEquals("Here is an example of a cat.", this.bundle.getString("cat", this.variables));
55     }
56
57     private static class TestBundle extends AbstractBundle {
58         private Map JavaDoc store = new HashMap JavaDoc();
59
60         public void setLoadOnInit(boolean set) {
61         }
62
63         public void init(String JavaDoc fileName) throws Exception JavaDoc {
64             // do nothing
65
}
66
67         void put(String JavaDoc key, String JavaDoc value) {
68             this.store.put(key, value);
69         }
70
71         public String JavaDoc getString(String JavaDoc key) {
72             return (String JavaDoc) store.get(key);
73         }
74     }
75
76 }
77
Popular Tags