protected void assertGetProperty(Object object, String property, Object expected) { Object value = InvokerHelper.getProperty(object, property); assertEquals("property: " + property + " of: " + object, expected, value); } }
public void testClassProperty() throws Exception { Class c = String.class; Object value = InvokerHelper.getProperty(c, "name"); assertEquals("class name property", c.getName(), value); }
public void testMapEntryProperty() throws Exception { HashMap map = new HashMap(); map.put("a", "x"); Object[] array = map.entrySet().toArray(); Object entry = array[0]; Object key = InvokerHelper.getProperty(entry, "key"); assertEquals("key property", "a", key); Object value = InvokerHelper.getProperty(entry, "value"); assertEquals("value property", "x", value); }
public void testStaticProperty() throws Exception { Object value = InvokerHelper.getProperty(System.class, "out"); assertEquals("static property out", System.out, value); }
public void testListCoercionProperty() throws Exception { DummyBean bean = new DummyBean(); List list = new ArrayList(); list.add(new Integer(10)); list.add(new Integer(20)); InvokerHelper.setProperty(bean, "point", list); assertEquals("Should have set a point", new Point(10, 20), bean.getPoint()); }
public void testListCoercionPropertyOnJFrame() throws Exception { if (HeadlessTestSupport.isHeadless()) return; try { JFrame bean = new JFrame(); List list = new ArrayList(); list.add(new Integer(10)); list.add(new Integer(20)); InvokerHelper.setProperty(bean, "location", list); assertEquals("Should have set a point", new Point(10, 20), bean.getLocation()); } catch (MissingMethodException e) { System.out.println("Failed with cause: " + e); e.printStackTrace(); fail("Should not have throw: " + e); } }