@Test public void testBasicConversion() throws Exception { Map<String, String> map = getTestMap(); MapToBeanConverter converter = new MapToBeanConverter(map); BeanA bean1 = (BeanA)converter.get("##bean1"); assertNotNull(bean1); assertEquals("Bean1", bean1.getName()); assertEquals(1, bean1.getNum()); assertEquals(new Long(1000000000), bean1.getBigNumber()); assertFalse(bean1.isPretty()); BeanB bean2 = bean1.getBeanB(); assertNotNull(bean2); assertEquals("Bean2", bean2.getName()); assertEquals(2, bean2.getNum()); assertEquals(new Long(2000000000), bean2.getBigNumber()); BeanA bean3 = bean2.getFirstBeanA(); assertNotNull(bean3); assertEquals("Bean3", bean3.getName()); assertEquals(3, bean3.getNum()); assertTrue(bean3.isPretty()); assertNull(bean3.getBigNumber()); assertEquals(bean3, bean2.getSecondBeanA()); assertEquals(bean1, converter.get("##bean1")); assertEquals(bean2, converter.get("##bean2")); assertEquals(bean3, converter.get("##bean3")); }
public Object get(String key) throws Exception { if (key == null || !key.startsWith(BEAN_ID_PREFIX)) { throw new IllegalArgumentException("Provided key does not start with " + BEAN_ID_PREFIX + ": " + key); } Object result = builtObjectsMap.get(key); if (result == null) { result = build(key); builtObjectsMap.put(key, result); } return result; }
MapToBeanConverter { public Object get(String key) throws Exception { if (key == null || !key.startsWith(BEAN_ID_PREFIX)) { throw new IllegalArgumentException("Provided key does not start with " + BEAN_ID_PREFIX + ": " + key); } Object result = builtObjectsMap.get(key); if (result == null) { result = build(key); builtObjectsMap.put(key, result); } return result; } }
MapToBeanConverter { public Object get(String key) throws Exception { if (key == null || !key.startsWith(BEAN_ID_PREFIX)) { throw new IllegalArgumentException("Provided key does not start with " + BEAN_ID_PREFIX + ": " + key); } Object result = builtObjectsMap.get(key); if (result == null) { result = build(key); builtObjectsMap.put(key, result); } return result; } MapToBeanConverter(Map<String, String> map); }
MapToBeanConverter { public Object get(String key) throws Exception { if (key == null || !key.startsWith(BEAN_ID_PREFIX)) { throw new IllegalArgumentException("Provided key does not start with " + BEAN_ID_PREFIX + ": " + key); } Object result = builtObjectsMap.get(key); if (result == null) { result = build(key); builtObjectsMap.put(key, result); } return result; } MapToBeanConverter(Map<String, String> map); Object get(String key); }
MapToBeanConverter { public Object get(String key) throws Exception { if (key == null || !key.startsWith(BEAN_ID_PREFIX)) { throw new IllegalArgumentException("Provided key does not start with " + BEAN_ID_PREFIX + ": " + key); } Object result = builtObjectsMap.get(key); if (result == null) { result = build(key); builtObjectsMap.put(key, result); } return result; } MapToBeanConverter(Map<String, String> map); Object get(String key); static final String BEAN_ID_PREFIX; static final String DOT; }