Java Mailing List Archive

Home » user.jmock »

[jmock-user] How to check object state inside a mock call

Dimitry Polivaev


Replies: Find Java Web Hosting

Author LoginPost Reply

I am trying to develop a class performing callbacks using JMock.
I have to check some properties of the calling object of the tested class RuleEngine during the callback.
After the call finishes its state is lost.

So I wrote the following:

public class RuleEngineTest {
Mockery context = new JUnit4Mockery();
Code code = context.mock(Code.class);
public void emptyRuleSetRunsCodeOnce() {
final RuleEngine ruleEngine = new RuleEngine();
context.checking(new Expectations() {{
will(new CheckingAction(){
protected void doChecks() {
// Do some state checks of ruleEngine object

public abstract class CheckingAction extends ReturnDefaultValueAction{

public Object invoke(Invocation invocation) throws Throwable {
return super.invoke(invocation);

abstract protected void doChecks();

// class to be developed. The internal state and the related methods come later.
public class RuleEngine {
public void run(Code code) {;

However writing the checking part as
will(new CheckingAction(){

does not seem to be right because I actually misuse Action interface to perform some checks and have some syntax overhead.

Is there a better way?

Kind regards, Dimitry

To unsubscribe from this list, please visit:

©2008 - Jax Systems, LLC, U.S.A.