diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/test/OutputDestination.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/test/OutputDestination.java index 3f2281b25..74c5e55aa 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/test/OutputDestination.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/test/OutputDestination.java @@ -24,6 +24,7 @@ import java.util.concurrent.LinkedTransferQueue; import java.util.concurrent.TimeUnit; import org.springframework.messaging.Message; +import org.springframework.util.StringUtils; /** * Implementation of binder endpoint that represents the target destination (e.g., @@ -47,6 +48,30 @@ public class OutputDestination extends AbstractDestination { } return null; } + + /** + * Will clear all output destinations. + * + * @since 3.0.6 + */ + public void clear() { + this.messageQueues.clear(); + } + + /** + * Will clear output destination with specified name. + * + * @param destinationName the name of the output destination to be cleared. + * @return true if attempt to clear specific destination is successful otherwise false. + * @since 3.0.6 + */ + public boolean clear(String destinationName) { + if (StringUtils.hasText(destinationName) && this.messageQueues.containsKey(destinationName)) { + this.messageQueues.clear(); + return true; + } + return false; + } /** * Allows to access {@link Message}s received by this {@link OutputDestination}. * @param timeout how long to wait before giving up