### Question:
Configurator implements Cloneable { public <T> T get(Class<T> klass, String name) throws ConfigurationException { return get(klass, name, null); } Configurator(Configuration conf); Configuration getConf(); T get(Class<T> klass, String name); T get(Class<T> klass, String name, String runtimeKey, String runtimeValue); T get(Class<T> klass, String name, Map<String, String> runtimeParams); String resolveComponentName(Class klass, String name); Config getConfig(Class klass, String name); T construct(Class<T> klass, String name, Config conf, Map<String, String> runtimeParams); T get(Class<T> klass); void close(); static final int MAX_FILE_SIZE; }### Answer:
@Test public void testRuntimeParams() throws ConfigurationException, IOException { Configurator conf = new Configurator(new Configuration()); Integer i1 = conf.get(Integer.class, "foo"); assertEquals(i1, 42); Integer i2 = conf.get(Integer.class, "foo"); assertEquals(i1, i2); Map<String, String> args3 = new HashMap<String, String>(); args3.put("overrideConstant", "423523524"); Integer i3 = conf.get(Integer.class, "foo", args3); assertEquals(i3, 423523524); Map<String, String> args4 = new HashMap<String, String>(); args4.put("overrideConstant", "423523236"); Integer i4 = conf.get(Integer.class, "foo", args4); assertEquals(i4, 423523236); assertEquals(new Integer(423523524), i3); assertNotSame(new Integer(423523524), i3); Integer i5 = conf.get(Integer.class, "foo", args3); assertEquals(i3, i5); assertSame(i3, i5); }
@Test public void testSimple() throws ConfigurationException { Configurator conf = new Configurator(new Configuration()); Integer i = conf.get(Integer.class, "foo"); assertEquals(i, 42); Integer j = conf.get(Integer.class, "bar"); assertEquals(j, 23); Integer k = conf.get(Integer.class, "baz"); assertEquals(k, 0); Integer l = conf.get(Integer.class, "biff"); assertEquals(l, 1); }
@Test public void testNonExistentJar() throws ConfigurationException { String separator = System.getProperty("path.separator"); System.setProperty("java.class.path", System.getProperty("java.class.path") + separator + "foobarbaz.jar"); Configurator conf = new Configurator(new Configuration()); Integer i = conf.get(Integer.class, "foo"); assertEquals(i, 42); Integer j = conf.get(Integer.class, "bar"); assertEquals(j, 23); Integer k = conf.get(Integer.class, "baz"); assertEquals(k, 0); Integer l = conf.get(Integer.class, "biff"); assertEquals(l, 1); }