RequestMessageProcessor implements MessageProcessor { @Override public void process(IncomeMessage message) { String token = message.command().as(String.class); if (this.requestManager.confirm(token)) { message.reply("Confirmation OK!"); } else { message.reply("[e]Invalid token[/e]"); } } RequestMessageProcessor(RequestManager requestManager); @Override void process(IncomeMessage message);  }
@Test public void testValidToken() { IncomeMessage message = IncomeMessageMock.message(validToken, m -> m.withCommand("confirm", validToken)); Spec.given(new RequestMessageProcessor(requestManager)) .when(process(message)) .expect(the(message), to(receive(m -> m.reply("Confirmation OK!")))); }
@Test public void testInvalidToken() { IncomeMessage message = IncomeMessageMock.message(invalidToken, m -> m.withCommand("confirm", invalidToken)); Spec.given(new RequestMessageProcessor(requestManager)) .when(process(message)) .expect(the(message), to(receive(m -> m.reply("[e]Invalid token[/e]")))); }