/** * Exception scenario - target method is called with invalid arguments. */ @Test public void testInvalidArgumentsForExistingMethod() throws Exception { delegator.setTargetMethod("setName"); delegator.afterPropertiesSet(); try { delegator.invokeDelegateMethodWithArgument(new Object()); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { // expected } }
/** * Regular use - calling methods directly and via delegator leads to same * results */ @Test public void testDelegationWithArgument() throws Exception { delegator.setTargetMethod("setName"); final String NEW_FOO_NAME = "newFooName"; delegator.afterPropertiesSet(); delegator.invokeDelegateMethodWithArgument(NEW_FOO_NAME); assertEquals(NEW_FOO_NAME, foo.getName()); // using the arguments setter should work equally well foo.setName("foo"); assertTrue(!foo.getName().equals(NEW_FOO_NAME)); delegator.setArguments(new Object[] { NEW_FOO_NAME }); delegator.afterPropertiesSet(); delegator.invokeDelegateMethod(); assertEquals(NEW_FOO_NAME, foo.getName()); }