jMock: expects() With Multiple Arguments
Wednesday, February 23, 2005 @ 16.09 CST

I didn't find a clear example of this today, so here's a note:

In jMock, if you expect a method to be called with a single argument, you do it like this:

mock.expects(once()).method("methodName").with(eq("argValue"));

But if you expect a method to be called with a specific argument list, it's this:

Mock mockGraphics = mock(java.awt.Graphics.class, "mockGraphics");
Constraint[] drawArcArgs = {
    eq(278),
    eq(181),
    eq(50),
    eq(50),
    eq(18),
    eq(360)
};
mockGraphics.expects(once()).method("drawArc").with(drawArcArgs);

The arguments should appear in the array in the order you expect them.

When I think about it, it's obvious, but when I wasn't thinking about it in the correct way, I wanted an example. Maybe someone else will want one, too.

All the news