I'm using EasyMock 3.4 and have a unit test I'm getting an error on that's pretty bizarre.
The stack trace is:
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
at org.easymock.internal.ExpectedInvocation.createMissingMatchers(ExpectedInvocation.java:51)
And my unit test is below as follows:
@Test
public void testAddOrUpdateGuestMessageScenario(){
final Session mockSession = EasyMock.createMock(Session.class);
final Query mockQuery = EasyMock.createMock(Query.class);
final Transaction mockTransaction = EasyMock.createMock(Transaction.class);
final GuestMessageScenarioBO guestMessageScenarioBOMock = EasyMock.createMock(GuestMessageScenarioBO.class);
final MessageCampaignBO messageCampaignBOMock = EasyMock.createMock(MessageCampaignBO.class);
final InboundMessageSimulatorBO inboundMessageSimulatorBOMock = EasyMock.createMock(InboundMessageSimulatorBO.class);
EasyMock.expect(guestMessageScenarioBOMock.getInboundMessageSimulatorBO()).andReturn(inboundMessageSimulatorBOMock).anyTimes();
EasyMock.expect(inboundMessageSimulatorBOMock.getMessageCampaignBO()).andReturn(messageCampaignBOMock);
EasyMock.expect(inboundMessageSimulatorBOMock.getCreateDate()).andReturn(null);
EasyMock.expect(messageCampaignBOMock.getMessageCampaignRecordId()).andReturn(1234L);
EasyMock.expect(mockSession.get(MessageCampaignBO.class, 1234L)).andReturn(messageCampaignBOMock);
guestMessageScenarioBOMock.setCreateDate(EasyMock.isA(Timestamp.class));
guestMessageScenarioBOMock.setUpdateDate(EasyMock.isA(Timestamp.class));
inboundMessageSimulatorBOMock.setMessageCampaignBO(messageCampaignBOMock);
inboundMessageSimulatorBOMock.setCreateDate(EasyMock.isA(Timestamp.class));
inboundMessageSimulatorBOMock.setUpdateDate(EasyMock.isA(Timestamp.class));
inboundMessageSimulatorBOMock.setGuestBusinessRuleUsageIndicator(true);
EasyMock.expect(mockSession.createQuery(EasyMock.isA(String.class))).andReturn(mockQuery);
EasyMock.expect(mockSessionFactory.openSession()).andReturn(mockSession).anyTimes();
mockSession.close();
EasyMock.expectLastCall();
EasyMock.expect(mockSession.beginTransaction()).andReturn(mockTransaction);
mockSession.saveOrUpdate(EasyMock.isA(GuestMessageScenarioBO.class));
mockTransaction.commit();
EasyMock.replay(mockSessionFactory, mockSession, mockQuery,mockTransaction, guestMessageScenarioBOMock, inboundMessageSimulatorBOMock, messageCampaignBOMock);
guestMessageScenarioDAO.addOrUpdateGuestMessageScenario(guestMessageScenarioBOMock);
}
The line that it's complaining about is:
EasyMock.expect(guestMessageScenarioBOMock.getInboundMessageSimulatorBO()).andReturn(inboundMessageSimulatorBOMock).anyTimes();
I understand that in EasyMock, you cannot mix matchers with actual values/objects in method calls or else it throws an error, but it's pretty clear looking at that code there is simply no matchers being used period, never mind mixed with anything as that method on guestMessageScenarioBOMock doesn't even take any parameters.
Any idea what it's complaining about?
Aucun commentaire:
Enregistrer un commentaire