ConfigFactory { @SuppressWarnings("unchecked") public static <T> T bind(Config config, Class<? extends T> clazz) { Class<?>[] interfaces = {clazz}; ConfigInvocationHandler h = new ConfigInvocationHandler(config, false); return (T) Proxy.newProxyInstance(ConfigFactory.class.getClassLoader(), interfaces, h); } private  ConfigFactory(); static Config fromMap(Map<String, ? extends Object> m); static Config fromProperties(Properties m); static Config from(ConfigMap m); static ReplaceableConfigMap replaceable(ConfigMap m); static ConfigMap chain(ConfigMap ... m); static ConfigMap chain(Iterable<ConfigMap> m); @SuppressWarnings("unchecked") static T bind(Config config, Class<? extends T> clazz); @SuppressWarnings("unchecked") static T bind(Config config, Class<? extends T> clazz, BindConfig bc); static Config fromBean(Class<?> c, Object o); static String prettyPrint(Config c); static ConfigMap toConfigMap(Map<?, ? extends Object> m); static ConfigMap toConfigMap(Class<?> clazz, Object target); static String validatePath(String path); static boolean isKey(String s); static boolean isSubPath(String parentPath, String childPath); static String joinPath(List<String> elements); static List<String> splitPath(String path); static String parentPath(String path); static Set<String> filterParentPaths(Iterator<String> paths);  }
@Test public void testBind() throws Exception { Map<String, Object> o = newLinkedHashMap(); o.put("host", "localhost"); o.put("port", 2); o.put("auto", true); Config c = ConfigFactory.fromMap(o); Example e = ConfigFactory.bind(c, Example.class); assertEquals(2, e.getPort()); String host = e.getHost().get(); assertEquals("localhost", host); assertEquals(true, e.isAuto()); try { e.getUser(); fail("user"); } catch (IllegalStateException se) { } BindConfig bc = new BindConfig(); bc.setAllowMissing(true); e = ConfigFactory.bind(c, Example.class, bc); assertNull(e.getUser()); assertTrue(!e.alias().isPresent()); o.put("alias", "demo"); assertEquals("demo", e.alias().get()); }