SaveTimestampReceiver implements IMessageReceiver { @Override public void receive(final IMessageProcessor processor) throws MessageReceiveException, AsynchronousOperationException { try { processor.getContext().setValue(timeContextField, systemTime.currentTimeMillis()); } catch (ChangeValueException | InvalidArgumentException e) { throw new MessageReceiveException("Could not save current time in message context.", e); } } SaveTimestampReceiver(final IFieldName fieldName); @Override void receive(final IMessageProcessor processor);  }
@Test public void Should_saveTimeInMessageContext() throws Exception { IMessageProcessor mp = mock(IMessageProcessor.class); when(mp.getContext()).thenReturn(mock(IObject.class)); new SaveTimestampReceiver(timeFieldMock).receive(mp); verify(mp.getContext()).setValue(timeFieldMock, timeMock.currentTimeMillis()); }
@Test(expected = MessageReceiveException.class) public void Should_wrapExceptions() throws Exception { IMessageProcessor mp = mock(IMessageProcessor.class); IObject context = mock(IObject.class); when(mp.getContext()).thenReturn(context); doThrow(ChangeValueException.class).when(context).setValue(any(), any()); new SaveTimestampReceiver(timeFieldMock).receive(mp); }