More Matchers recorded than the expected - Easymock fails from Maven and not from Eclipse

У меня странная проблема с Easymock 3.0 и JUnit 4.8.2. The problem only occurs when executing the tests from Maven and not from Eclipse.

This is the unit test (very simple):

...
protected ValueExtractorRetriever mockedRetriever;
...

@Before
public void before() {
    mockedRetriever = createStrictMock(ValueExtractorRetriever.class);
}

@After
public void after() {
    reset(mockedRetriever);
}

@Test
public void testNullValueExtractor() { 
    expect(mockedRetriever.retrieve("PROP")).andReturn(null).once();
    replay(mockedRetriever);

    ValueExtractor retriever = mockedRetriever.retrieve("PROP");
    assertNull(retriever);

    assertTrue(true);
}

And I get:

java.lang.IllegalStateException: 1 matchers expected, 2 recorded.

The weird thing is that I'm not even using an argument matcher. And that is the only method of the test! and to make it even worst it works from Eclipse and fails from Maven!

I found a few links which didn't provide me with an answer:

If I change the unit test and add one more method (which does use an argument matcher):

@Test
public void testIsBeforeDateOk() {
    expect(mockedRetriever.retrieve((String)anyObject())).andReturn(new PofExtractor()).anyTimes();
    replay(this.mockedRetriever);

    FilterBuilder fb = new FilterBuilder();
    assertNotNull(fb);

    CriteriaFilter cf = new CriteriaFilter();
    assertNotNull(cf);
    cf.getValues().add("2010-12-29T14:45:23");
    cf.setType(CriteriaType.DATE);
    cf.setClause(Clause.IS_BEFORE_THE_DATE);

    CriteriaQueryClause clause = CriteriaQueryClause.fromValue(cf.getClause());
    assertNotNull(clause);
    assertEquals(CriteriaQueryClause.IS_BEFORE_THE_DATE, clause);

    clause.buildFilter(fb, cf, mockedRetriever);
    assertNotNull(fb);

    Filter[] filters = fb.getFilters();
    assertNotNull(filters);
    assertEquals(filters.length, 1);

    verify(mockedRetriever);

    logger.info("OK");
}

this last method passes the test but not the other one. How is this possible!?!?!

Regards, Нико

Дополнительные ссылки:

"bartling.blogspot.com/2009/11/using-argument-matchers-in-easymock-and.html"

"www.springone2gx.com/blog/scott_leberknight/2008 /09/the_n_matchers_expected_m_recorded_problem_in_easymock"[12165 visible"stackoverflow.com/questions/4605997/3-matchers-expected-4-recorded"

6
задан Community 23 May 2017 в 12:25
поделиться