What is the most concise way of matching on argument type?

11 views
Skip to first unread message

SimonS

unread,
Feb 18, 2010, 8:11:55 PM2/18/10
to gmock-user
Hi ...

When mocking I generally don't want to set expectations about the
argument values going into collaborators. I was wondering what is
the most concise way to do it? Right now I have tests filled with
things like:

Foo foo = mock(Foo)
foo.bar(match{true},match{true},match{true}).returns("dog").stub()

Groovy's StubFor makes this much simpler, but falls down in other
regards. Is there any better way to do it than what I'm doing?

Wish list: make a 'stub' function that works like Groovy's method and
let me do:

Foo foo = stub(Foo)
foo.bar(String,String,Baz).returns("dog")

Cheers,

Simon.

Johnny Jian

unread,
Feb 19, 2010, 12:11:50 AM2/19/10
to gmock...@googlegroups.com
You can use the Hamcrest Matchers(http://code.google.com/p/hamcrest/) like:

import static org.hamcrest.Matchers.*
...
Foo foo = mock(Foo)
foo.bar(is(String), is(String), is(Baz)).returns('dog').stub()

Or just use the 'match' closure like:

Foo foo = mock(Foo)
foo.bar(match{it in String}, match{it in String}, match{it in Baz}).returns('dog').stub()

We planned to support the 'stub' method which is a bit like the 'mock' method in mockito, but will not support the Class parameters as you said. Please refer to https://groups.google.com/group/gmock-dev/browse_thread/thread/419fe236e8d824fd for more information.

Johnny


--
You received this message because you are subscribed to the Google Groups "gmock-user" group.
To post to this group, send email to gmock...@googlegroups.com.
To unsubscribe from this group, send email to gmock-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gmock-user?hl=en.


Reply all
Reply to author
Forward
0 new messages