I have a strange problem with Easymock 3.0 and JUnit 4.8.2. The problem only occurs when running tests from Maven, and not from Eclipse.
This is 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 responder, 2 recorded, expected.
It is strange that I do not even use argument matching. And this is the only test method! and to make it worse, it works from Eclipse and does not work with Maven!
I found some links that did not give me an answer:
If I change the unit test and add another method (which uses an argument match):
@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, not the other. How is this possible!?!?!
Regards, Nico
Other links:
"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"
"stackoverflow.com/questions/4605997/3-matchers-expected-4-recorded"
source share