jMock

Add action to save the parameters in the call

Details

  • Type: New Feature New Feature
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 2.4.0
  • Fix Version/s: None
  • Component/s: JMock 2.x.x Library
  • Labels:
    None
  • Number of attachments :
    0

Description

The need to save the parameters that were used in a call for later use is a common thing. An example would be mocking an object that accepts event listeners that it needs to make calls on to do the test. Currently to handle something like this requires creating a custom action. It would be nice to have supported directly in JMock.

Here is what I came up with off the top of my head:

Add a method to Expectations: static Action saveParametersIn( Collection< Object > ).

This method creates a SaveParameterAction pointing to the given collection where it saves the parameters as its action. The SaveParameterAction should also have a default constructor that just uses a default collection and has methods to get the parameters from the underlying collection and would probably implement Iterable<Object>.

So you could do:

final Collection<Object> parameters = new ArrayList< Object >();

context.checking( new Expectations() {{
one( foo ).method( ... ); will( saveParametersIn( parameters ) );
}} );

Or you could also do:

final SaveParameterAction saveParameters = new SaveParameterAction();

context.checking( new Expectations() {{
one( foo ).method( ... ); will( saveParameters );
}} );

If you want to save parameters and return a value you would have to use doAll to do both actions.

Think about it. Perhaps you can come up with a better idea, but the need to save the parameters for later use is a common need.

Activity

There are no comments yet on this issue.

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated: