DatabaseEventLogger extends EventLogger { @Override void recordEvent(EventManager manager, Event event) { if (event != null) { DatabaseEvent dbEvent = new DatabaseEvent(); dbEvent.setEventName(event.getEventName()); dbEvent.setDescription(event.getDescription()); dbEvent.setMessageID(event.getMessageID()); dbEvent.setTransactionID(event.getTransactionID()); dbEvent.setServiceType(event.getServiceType()); dbEvent.setInitiatorHcid(event.getInitiatorHcid()); dbEvent.setRespondingHcid(event.getRespondingHcid()); dbEvent.setEventTime(getFormattedEventTime()); databaseEventLoggerDao.insertEvent(dbEvent); } } DatabaseEventLogger(DatabaseEventLoggerDao databaseEventLoggerDao);  DatabaseEventLogger(); Date getFormattedEventTime();  }
@Test public void testUpdateWithMock() { final DatabaseEventLoggerDao mockDatabaseEventLoggerDao = context.mock(DatabaseEventLoggerDao.class); final Event mockEvent = context.mock(Event.class); context.checking(new Expectations() { { oneOf(mockEvent).getEventName(); will(Expectations.returnValue("eventname")); oneOf(mockEvent).getDescription(); will(Expectations.returnValue("description")); oneOf(mockEvent).getMessageID(); will(Expectations.returnValue("messageid")); oneOf(mockEvent).getTransactionID(); will(Expectations.returnValue("transactionid")); oneOf(mockEvent).getServiceType(); will(Expectations.returnValue("serviceType")); oneOf(mockEvent).getInitiatorHcid(); will(Expectations.returnValue("hcid")); oneOf(mockEvent).getRespondingHcid(); will(Expectations.returnValue("hcid")); } }); DatabaseEventLogger testDatabaseEventLogger = new DatabaseEventLogger(mockDatabaseEventLoggerDao); context.checking(new Expectations() { { oneOf(mockDatabaseEventLoggerDao).insertEvent(with(any(DatabaseEvent.class))); will(Expectations.returnValue(true)); } }); testDatabaseEventLogger.recordEvent(null, mockEvent); }