foo.toString()返回
"[id: <id>, stuffIdontCareAbout: 0]"
我想测试id是否正确,但字符串中的其他所有内容都可以包含任何值。这就是我试过的:
expect(foo.toString()).andReturn(EasyMock.find("[id: 42,"));
但是这里抱怨的是:
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
那么,如何在返回值上使用EasyMock匹配器?
答案 0 :(得分:0)
这听起来不像是模拟。您似乎只想测试foo.toString()
的结果。
使用AssertJ(我推荐),意味着要做
assertThat(foo.toString()).startsWith("[id: 42,");