-1

My code looks like

Request1 req1 = EasyMock.anyObject(Request1.class);
Request2 req2 = EasyMock.anyObject(Request2.class);
Request3 req3 = EasyMock.anyObject(Request3.class);

@Mock Service service;
// ...
@Test
myTest() {
    Response resp = new Response();
    EasyMock.expect(service.lookup(req1, req2)).andReturn(resp);
    // ...
}

The "EasyMock.expect" line is failing with

2 matchers expected, 3 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

I'm giving two matchers though. Perhaps the problem is that andReturn is given a value, but of course I am trying to say "return resp no matter what input is given."

This seems different from the usual cause. FWIW andStubReturn gives same error (which I woule expect).

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
djechlin
  • 59,258
  • 35
  • 162
  • 290

1 Answers1

1

The problem was another line

Request3 req3 = EasyMock.anyObject(Request3.class);

that I was using in other tests, and whose instantiation I did not realize had side effects. It does.

djechlin
  • 59,258
  • 35
  • 162
  • 290
  • @SotiriosDelimanolis No, thank you for your opinion though. A question with this exact title would have saved me a half hour of debugging if it had existed an hour ago. – djechlin May 03 '16 at 21:41
  • I guess the real issue is that you're declaring your matcher at the instance level when you should declare them at the test method level. Can't find that in the doc though. – Tunaki May 03 '16 at 21:46