1 7 package com.inversoft.config.test; 8 9 10 import java.util.ResourceBundle ; 11 12 import junit.framework.TestCase; 13 14 import com.inversoft.config.ConfigFactory; 15 import com.inversoft.config.ConfigFactoryRegistry; 16 17 18 28 public class ConfigFactoryRegistryTest extends TestCase { 29 30 33 public ConfigFactoryRegistryTest(String name) { 34 super(name); 35 } 36 37 38 42 public void testEmpty() { 43 44 47 ConfigFactory factory = ConfigFactoryRegistry.lookup("good"); 48 assertNull(factory); 49 50 factory = ConfigFactoryRegistry.lookup("bad"); 51 assertNull(factory); 52 } 53 54 57 public void testCustomBundle() { 58 59 ResourceBundle bundle = ResourceBundle.getBundle( 60 "com.inversoft.config.test.ConfigBundle"); 61 ConfigFactoryRegistry.load(bundle); 62 63 ConfigFactory factory = ConfigFactoryRegistry.lookup("good"); 64 assertTrue("Should not be null", factory != null); 65 66 factory = ConfigFactoryRegistry.lookup("bad"); 67 assertTrue("Should be null", factory == null); 68 } 69 70 73 public void testMethods() { 74 75 ResourceBundle bundle = ResourceBundle.getBundle( 76 "com.inversoft.config.test.ConfigBundle"); 77 ConfigFactoryRegistry.load(bundle); 78 79 ConfigFactory factory1 = new TestConfigFactory(); 80 ConfigFactory factory2 = new TestConfigFactory(); 81 ConfigFactory factory3 = new TestConfigFactory(); 82 ConfigFactoryRegistry.register("1", factory1); 83 ConfigFactoryRegistry.register("2", factory2); 84 ConfigFactoryRegistry.register("3", factory3); 85 86 assertTrue("Should be 1", ConfigFactoryRegistry.lookup("1") == factory1); 87 assertTrue("Should be 2", ConfigFactoryRegistry.lookup("2") == factory2); 88 assertTrue("Should be 3", ConfigFactoryRegistry.lookup("3") == factory3); 89 90 assertTrue("Should have unregistered 1", ConfigFactoryRegistry.unregister("1") == factory1); 91 assertTrue("Should have unregistered 2", ConfigFactoryRegistry.unregister("2") == factory2); 92 assertTrue("Should have unregistered 3", ConfigFactoryRegistry.unregister("3") == factory3); 93 } 94 95 99 public void testWrongClass() { 100 101 ResourceBundle bundle = ResourceBundle.getBundle( 102 "com.inversoft.config.test.ConfigBundle"); 103 ConfigFactoryRegistry.load(bundle); 104 105 ConfigFactory factory = ConfigFactoryRegistry.lookup("wrongClass"); 106 assertNull(factory); 107 factory = ConfigFactoryRegistry.lookup("exception"); 108 assertNull(factory); 109 } 110 } | Popular Tags |