Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

[jmock-user] aNonNull unexpected behaviour

Jan Kodet

2008-06-04

Replies: Find Java Web Hosting

Author LoginPost Reply

I've probably misinterpreted something, but here goes....

Using the State pattern (see e.g.
http://exciton.cs.rice.edu/JavaResources/DesignPatterns/StatePat.htm) I want
to test the logic in my states. So I have two interfaces: State and Context.
Interface Context defines the method setState(State newState) and interface
State defines some event handling methods. The interfaces are then
implemented by the classes I want to test.

My test methods look something like (using version 2.4.0):

  @Test
  public void testOnEvent() {
    // Class under test
    StateOne stateOne = new StateOne(mockContext);

    context.checking(new Expectations() {
          {
            // We should transit to StateTwo
           
one(mockContext).setState(with(aNonNull(StateTwo.class)));
          }
    });

    stateOne.onEvent(new SomeEvent());
    context.assertIsSatisfied();
  }


To my delight, the test succeeds. My joy was somewhat dimmed when I noted
that I can put any state I like as argument to aNonNull(), as long as it
implements State. They all fullfill the expectation.

This was not what I'd expect. I hoped that "with(aNonNull(StateTwo.class))"
would ensure that I go to the right state, not just that the argument has
the correct interface.

I assume that I've got something wrong, but hope for any pointers to how I
should do my tests to ensure that I really go to StateTwo.

Cheers,

/JMK
--
Sent from the jMock - User mailing list archive at Nabble.com.


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

  http://xircles.codehaus.org/manage_email


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