1 8 package org.apache.avalon.excalibur.i18n.test; 9 10 import java.util.Map ; 11 import java.util.HashMap ; 12 13 import org.apache.avalon.excalibur.testcase.ExcaliburTestCase; 14 import org.apache.avalon.excalibur.i18n.AbstractBundle; 15 16 20 public class AbstractBundleTestCase extends ExcaliburTestCase { 21 22 private TestBundle bundle = new TestBundle(); 23 private Map variables = new HashMap (5); 24 25 public AbstractBundleTestCase( String name ) { 26 super(name); 27 } 28 29 public void setUp() throws Exception { 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 { 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 store = new HashMap (); 59 60 public void setLoadOnInit(boolean set) { 61 } 62 63 public void init(String fileName) throws Exception { 64 } 66 67 void put(String key, String value) { 68 this.store.put(key, value); 69 } 70 71 public String getString(String key) { 72 return (String ) store.get(key); 73 } 74 } 75 76 } 77 | Popular Tags |