« Return to Thread: Using Custom Actions

Re: Using Custom Actions

by Nat Pryce :: Rate this Message:

Reply to Author | View in Thread

You can only specify one will statement per expectation. If you want  
to do more than one thing, use the doAll action.

That said, what you've written should work or JMock should report the  
error clearly. (I prefer the former). Can you raise a JIRA issue to  
remind us to implement it?

--Nat

--
www.natpryce.com

On 15 Apr 2009, at 12:45, Andy Bell <andy.bell@...> wrote:

> Hi
>
> I'm trying to write a custom action, using the example at this page:
> http://www.jmock.org/custom-actions.html
>
> I'm setting my expectations as follows:
>
> checking(new Expectations() {
>            {
>
> one(mockValidationServer).invokeValidation(with(equal("Validate")),
> with(a(Object[].class)));
>                will(setResponseValues());
>                will(returnValue(true));
>            }
>        });
>
> and I have a factory method setResponseValues as follows:
>
> private static <T> Action setResponseValues() {
>        return new SetSuccessResponse<T>(999);
>    }
>
> (999 being just a bit of test data while I'm trying to make this  
> work);
>
> My SetSuccessResponse class is as follows:
>
> public class SetSuccessResponse<T> implements Action {
>
>    private int responseValue;
>
>    public SetSuccessResponse(int value) {
>        responseValue = value;
>    }
>
>    public Object invoke(Invocation invocation) throws Throwable {
>        Object [] params = (Object [] )invocation.getParameter(1);
>        params[2] = responseValue;
>        return null;
>    }
>
>    public void describeTo(Description description) {
>            description.appendText("Test...");
>    }
> }
>
> The constructor of the class is called OK and the test passes BUT I  
> don't think
> the invoke method of SetSuccessResponse is ever called. If I set a  
> breakpoint in
> it the invoke method and debug the test, the code never stops at the  
> breakpoint
> nor is the responseValue ever passed into the params array.
>
> Any ideas?
>
> AndyB
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 « Return to Thread: Using Custom Actions