The error I was getting:
java.lang.IllegalStateException: 2 matchers expected, 1 recorded.
   at org.easymock.internal.ExpectedInvocation.createMissingMatchers(ExpectedInvocation.java:41)
   at org.easymock.internal.ExpectedInvocation.(ExpectedInvocation.java:33)
   at org.easymock.internal.ExpectedInvocation.(ExpectedInvocation.java:26)
   at org.easymock.internal.RecordState.invoke(RecordState.java:63)
   at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:24)
   at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:45)
   at $Proxy88.handleRequest(Unknown Source)  
First off, to find the offending test I build a test suite and reduced the tests run to isolate the tests where the error occurred until I had found the one causing the problem.
The code looked like this:
       JdbcOperations jdbcOperationsMock = createMock(JdbcOperations.class);
       // Expect query to use supplied alternative schema
       expect(
               jdbcOperationsMock.query(
                       eq("SELECT ARTICLE_SKU, ARTICLE_NAME FROM alt_schema_subs.tomtomtbarticle;"),
                       isA(RowMapper.class))
               )
               .andReturn(isA(List.class));
Which seems to be ok. The only problem was that I was using a argument matcher on a return value (see documentation). The solution was to supply a normal return value:
  expect(
    jdbcOperationsMock.query(
      eq("SELECT ARTICLE_SKU, ARTICLE_NAME FROM alt_schema_subs.tomtomtbarticle;"),
      isA(RowMapper.class))
    )
    .andReturn(new ArrayList<Object>());
And now the tests succeed.
Hope this was helpful. I intent to update the blog with more day-to-day problems in hope some people might find it on google.
 

No comments:
Post a Comment