package com.ankurm.awaitility; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.springframework.stereotype.Component; /** * Stands in for "the side effect of an asynchronous operation" — a row written by a * background thread that a test (or another part of the application) has no handle to wait on * directly. {@link AsyncGreetingService#sendConfirmation(String)} writes here; nothing returns a * {@code Future} for it to block on, which is the whole reason the test for it needs Awaitility * rather than a blocking {@code get()}. */ @Component public class Mailbox { private final ConcurrentMap sent = new ConcurrentHashMap<>(); void record(String orderId, String message) { sent.put(orderId, message); } /** Returns {@code null} if nothing has been recorded for this order yet. */ public String confirmationFor(String orderId) { return sent.get(orderId); } public int size() { return sent.size(); } }