1 23 24 package com.sun.enterprise.cli.framework; 25 26 import java.util.Properties ; 27 import java.util.Vector ; 28 import java.util.ResourceBundle ; 29 30 import junit.framework.*; 31 36 37 public class LocalStringsManagerTest extends TestCase { 38 public void testGettingAnAbsentKey(){ 39 final LocalStringsManager lsm = new LocalStringsManager("com.sun.enterprise.cli.framework", "P1"); 40 assertEquals("Key not found (absent)", lsm.getString("absent")); 41 } 42 43 public void testReplacementException() throws Exception { 44 final LocalStringsManager lsm = new LocalStringsManager("com.sun.enterprise.cli.framework", "P1"); 45 try { 46 assertEquals("15% of 1,000 makes 150", lsm.getString("bad_format", new Object [0])); 47 fail("Expected CommandValidationException indicating that the formatting was incorrect"); 48 } 49 catch (CommandValidationException cve){ 50 assertEquals("java.lang.IllegalArgumentException: unknown format type at ", cve.getMessage()); 51 } 52 } 53 54 private Properties makeProperty(String f){ 55 final Properties p = new Properties (); 56 p.setProperty("base-package", "com.sun.enterprise.cli.framework"); 57 p.setProperty("property-file-name", f); 58 return p; 59 } 60 61 public void testInitializationFromProperties(){ 62 final Vector v = new Vector (); 63 v.add(makeProperty("P1")); 64 v.add(makeProperty("P2")); 65 final LocalStringsManager lsm = new LocalStringsManager(v); 66 assertEquals("P1.a", lsm.getString("a")); 67 68 ResourceBundle rb1 = 69 ResourceBundle.getBundle("com.sun.enterprise.cli.framework" + 70 "." + "P1"); 71 ResourceBundle rb2 = 72 ResourceBundle.getBundle("com.sun.enterprise.cli.framework" + 73 "." + "P2"); final Vector v2 = new Vector (); 74 v2.add(rb1); 75 v2.add(rb2); 76 assertEquals("Comparing Resource Properties", v2, lsm.getResourceBundles()); 77 } 78 79 80 public void testReplacement() throws Exception { 81 final Object [] arguments = { 82 new Double (.15), 83 new Integer (1000), 84 new Integer (150) 85 }; 86 final LocalStringsManager lsm = new LocalStringsManager("com.sun.enterprise.cli.framework", "P1"); 87 assertEquals("15% of 1,000 makes 150", lsm.getString("good_format", arguments)); 88 } 89 90 91 public void testSimpleUse(){ 92 final LocalStringsManager lsm = new LocalStringsManager("com.sun.enterprise.cli.framework", "P1"); 93 assertEquals("P1.a", lsm.getString("a")); 94 } 95 96 public void testWithLocale() 97 { 98 final Vector v = new Vector (); 99 v.add("com.sun.enterprise.cli.framework.P1"); 100 final LocalStringsManager lsm = new LocalStringsManager(v, java.util.Locale.US); 101 assertEquals("P1.a", lsm.getString("a")); 102 } 103 104 105 public void testSimpleCreation() { 106 final LocalStringsManager lsm = new LocalStringsManager("com.sun.enterprise.cli.framework", "P1"); 107 assertEquals("P1", lsm.getPropertiesFile()); 108 assertEquals("com.sun.enterprise.cli.framework", lsm.getPackageName()); 109 } 110 111 public LocalStringsManagerTest(String name){ 112 super(name); 113 } 114 115 protected void setUp() { 116 } 117 118 119 protected void tearDown() { 120 } 121 122 private void nyi(){ 123 fail("Not Yet Implemented"); 124 } 125 126 public static void main(String args[]){ 127 if (args.length == 0){ 128 junit.textui.TestRunner.run(LocalStringsManagerTest.class); 129 } else { 130 junit.textui.TestRunner.run(makeSuite(args)); 131 } 132 } 133 private static TestSuite makeSuite(String args[]){ 134 final TestSuite ts = new TestSuite(); 135 for (int i = 0; i < args.length; i++){ 136 ts.addTest(new LocalStringsManagerTest(args[i])); 137 } 138 return ts; 139 } 140 } 141 | Popular Tags |