@Test public void testGetReturnsNullForGetterMethod() throws Exception { Method getX = ModelMethodBindingBean.class.getDeclaredMethod("getX"); getX.setAccessible(true); ModelMethodBindingBean bean = new ModelMethodBindingBean(); MethodBinding binding = new MethodBinding(bean, getX, CommandSpec.create()); assertNull(binding.get()); assertEquals("actual value returned by getX() method", 7, bean.publicGetX()); }
@Test public void testSetInvokesMethod_ForSetterMethod() throws Exception { Method setX = ModelMethodBindingBean.class.getDeclaredMethod("setX", int.class); setX.setAccessible(true); ModelMethodBindingBean value = new ModelMethodBindingBean(); MethodBinding binding = new MethodBinding(value, setX, CommandSpec.create()); binding.set(987); assertEquals(987, value.publicGetX()); assertEquals(987, binding.get()); }
@Test public void testGetDoesNotInvokeMethod() throws Exception { Method getX = ModelMethodBindingBean.class.getDeclaredMethod("getX"); MethodBinding binding = new MethodBinding(new ModelMethodBindingBean(), getX, CommandSpec.create()); binding.get(); // no IllegalAccessException }
@Test public void testGetReturnsLastSetValue_ForSetterMethod() throws Exception { Method setX = ModelMethodBindingBean.class.getDeclaredMethod("setX", int.class); setX.setAccessible(true); ModelMethodBindingBean bean = new ModelMethodBindingBean(); MethodBinding binding = new MethodBinding(bean, setX, CommandSpec.create()); assertNull("initial", binding.get()); assertEquals(7, bean.publicGetX()); binding.set(41); assertEquals(41, bean.publicGetX()); assertEquals(41, binding.get()); }
@Test public void testGetDoesNotInvokeMethod() throws Exception { Method getX = ModelMethodBindingBean.class.getDeclaredMethod("getX"); MethodBinding binding = new MethodBinding(new ModelMethodBindingBean(), getX, CommandSpec.create()); binding.get(); // no IllegalAccessException }
@Test public void testSetInvokesMethod_ForSetterMethod() throws Exception { Method setX = ModelMethodBindingBean.class.getDeclaredMethod("setX", int.class); setX.setAccessible(true); ModelMethodBindingBean value = new ModelMethodBindingBean(); MethodBinding binding = new MethodBinding(value, setX, CommandSpec.create()); binding.set(987); assertEquals(987, value.publicGetX()); assertEquals(987, binding.get()); }
@Test public void testGetReturnsNullForGetterMethod() throws Exception { Method getX = ModelMethodBindingBean.class.getDeclaredMethod("getX"); getX.setAccessible(true); ModelMethodBindingBean bean = new ModelMethodBindingBean(); MethodBinding binding = new MethodBinding(bean, getX, CommandSpec.create()); assertNull(binding.get()); assertEquals("actual value returned by getX() method", 7, bean.publicGetX()); }
@Test public void testGetReturnsLastSetValue_ForSetterMethod() throws Exception { Method setX = ModelMethodBindingBean.class.getDeclaredMethod("setX", int.class); setX.setAccessible(true); ModelMethodBindingBean bean = new ModelMethodBindingBean(); MethodBinding binding = new MethodBinding(bean, setX, CommandSpec.create()); assertNull("initial", binding.get()); assertEquals(7, bean.publicGetX()); binding.set(41); assertEquals(41, bean.publicGetX()); assertEquals(41, binding.get()); }