foo.toString() returns
"[id: <id>, stuffIdontCareAbout: 0]"
I want to test that the id is correct, but everything else in the string can have any value. This is what I tried:
expect(foo.toString()).andReturn(EasyMock.find("[id: 42,"));
but here's how it complained:
java.lang.IllegalStateException: 0 matchers expected, 1 recorded.
This exception usually occurs when matchers are mixed with raw values when recording a method:
foo(5, eq(6)); // wrong
You need to use no matcher at all or a matcher for every single param:
foo(eq(5), eq(6)); // right
foo(5, 6); // also right
So, how do I use an EasyMock matcher on a return value?
This doesn't sound like a mock. It seems you only want to test the result of foo.toString()
.
Using AssertJ (which I recommend), would mean doing
assertThat(foo.toString()).startsWith("[id: 42,");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.