1 16 17 18 package org.apache.commons.beanutils; 19 20 21 import junit.framework.Test; 22 import junit.framework.TestSuite; 23 24 25 33 34 public class WrapDynaBeanTestCase extends BasicDynaBeanTestCase { 35 36 37 39 40 42 43 48 public WrapDynaBeanTestCase(String name) { 49 50 super(name); 51 52 } 53 54 55 57 58 61 public void setUp() throws Exception { 62 63 bean = new WrapDynaBean(new TestBean()); 64 65 } 66 67 68 71 public static Test suite() { 72 73 return (new TestSuite(WrapDynaBeanTestCase.class)); 74 75 } 76 77 78 81 public void tearDown() { 82 83 bean = null; 84 85 } 86 87 88 89 91 92 96 public void testMappedContains() { 97 98 try { 99 assertTrue("Can see first key", 100 bean.contains("mappedProperty", "First Key")); 101 fail("Should have thrown UnsupportedOperationException"); 102 } catch (UnsupportedOperationException t) { 103 ; } catch (Throwable t) { 105 fail("Exception: " + t); 106 } 107 108 109 try { 110 assertTrue("Can not see unknown key", 111 !bean.contains("mappedProperty", "Unknown Key")); 112 fail("Should have thrown UnsupportedOperationException"); 113 } catch (UnsupportedOperationException t) { 114 ; } catch (Throwable t) { 116 fail("Exception: " + t); 117 } 118 119 } 120 121 122 126 public void testMappedRemove() { 127 128 try { 129 assertTrue("Can see first key", 130 bean.contains("mappedProperty", "First Key")); 131 bean.remove("mappedProperty", "First Key"); 132 fail("Should have thrown UnsupportedOperationException"); 133 } catch (UnsupportedOperationException t) { 136 ; } catch (Throwable t) { 138 fail("Exception: " + t); 139 } 140 141 try { 142 assertTrue("Can not see unknown key", 143 !bean.contains("mappedProperty", "Unknown Key")); 144 bean.remove("mappedProperty", "Unknown Key"); 145 fail("Should have thrown UnsupportedOperationException"); 146 } catch (UnsupportedOperationException t) { 149 ; } catch (Throwable t) { 151 fail("Exception: " + t); 152 } 153 154 } 155 156 157 161 public void testSerialization() { } 162 163 164 public void testGetInstance() { 165 AlphaBean alphaBean = new AlphaBean("Now On Air... John Peel"); 166 WrapDynaBean dynaBean = new WrapDynaBean(alphaBean); 167 Object wrappedInstance = dynaBean.getInstance(); 168 assertTrue("Object type is AlphaBean", wrappedInstance instanceof AlphaBean); 169 AlphaBean wrappedAlphaBean = (AlphaBean) wrappedInstance; 170 assertTrue("Same Object", wrappedAlphaBean == alphaBean); 171 } 172 173 174 public void testNewInstance() throws Exception { 175 WrapDynaClass dynaClass = WrapDynaClass.createDynaClass(AlphaBean.class); 176 Object createdInstance = dynaClass.newInstance(); 177 assertTrue("Object type is WrapDynaBean", createdInstance instanceof WrapDynaBean); 178 WrapDynaBean dynaBean = (WrapDynaBean) createdInstance; 179 assertTrue("Object type is AlphaBean", dynaBean.getInstance() instanceof AlphaBean); 180 } 181 182 } 183 | Popular Tags |