Steps.java
@Then("a payload is sent to the destination") public void aPayloadIsSentToTheDestination() throws Exception { PayloadIsSentChecker aPayloadIsSent = new PayloadIsSentChecker(acceptanceTestAmqpClient, Destination.EXAMPLE); await().atMost(FIVE_SECONDS).until(aPayloadIsSent); }PayloadIsSentChecker.java
public PayloadIsSentChecker(AcceptanceTestAmqpClient acceptanceTestAmqpClient, Destination destination) { this.acceptanceTestAmqpClient = acceptanceTestAmqpClient; this.destination = destination; } @Override public Boolean call() throws Exception { Message message = acceptanceTestAmqpClient.lastMessageFromAcceptanceOutbound(destination); if (message == null) { return false; } return true; }However, if we bypass the callable interface entirely and use a groovy closure, with a mixin [AwaitilitySupport] from awaitility instead, we get
def thePayloadArrivesAt(Destination destination) { await().atMost(FIVE_SECONDS).until { assertThat(acceptanceTestAmqpClient.lastEventFromAcceptanceOutbound(destination), notNullValue()) } }And voila, a significant reduction in boiler plate code.