, Message>("a message that ") {
- @Override
- public Message
apply(Message
m) {
- return m;
- }
- });
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public static
MessageQueueMatcher
receivesPayloadThat(
- Matcher
payloadMatcher) {
- return new MessageQueueMatcher(payloadMatcher, 5, TimeUnit.SECONDS,
- new Extractor, P>("a message whose payload ") {
- @Override
- public P apply(Message m) {
- return m.getPayload();
- }
- });
- }
-
- @Override
- public boolean matches(Object item) {
- @SuppressWarnings("unchecked")
- BlockingQueue> queue = (BlockingQueue>) item;
- Message> received = null;
- try {
- if (this.timeout > 0) {
- received = queue.poll(this.timeout, this.unit);
- }
- else if (this.timeout == 0) {
- received = queue.poll();
- }
- else {
- received = queue.take();
- }
- }
- catch (InterruptedException e) {
- return false;
- }
- T unwrapped = this.extractor.apply(received);
- this.actuallyReceived.put(queue, unwrapped);
- return this.delegate.matches(unwrapped);
- }
-
- @Override
- public void describeMismatch(Object item, Description description) {
- @SuppressWarnings("unchecked")
- BlockingQueue> queue = (BlockingQueue>) item;
- T value = this.actuallyReceived.get(queue);
- if (value != null) {
- description.appendText("received: ").appendValue(value);
- }
- else {
- description.appendText("timed out after " + this.timeout + " "
- + this.unit.name().toLowerCase());
- }
- }
-
- public MessageQueueMatcher within(long timeout, TimeUnit unit) {
- return new MessageQueueMatcher<>(this.delegate, timeout, unit, this.extractor);
- }
-
- public MessageQueueMatcher immediately() {
- return new MessageQueueMatcher<>(this.delegate, 0, null, this.extractor);
- }
-
- public MessageQueueMatcher indefinitely() {
- return new MessageQueueMatcher<>(this.delegate, -1, null, this.extractor);
- }
-
- @Override
- public void describeTo(Description description) {
- description.appendText("Channel to receive ").appendDescriptionOf(this.extractor)
- .appendDescriptionOf(this.delegate);
- }
-
- /**
- * A transformation to be applied to a received message before asserting, e.g.
- * to only inspect the payload.
- *
- * @param input type
- * @param return type
- */
- public static abstract class Extractor
- implements Function, SelfDescribing {
-
- private final String behaviorDescription;
-
- protected Extractor(String behaviorDescription) {
- this.behaviorDescription = behaviorDescription;
- }
-
- @Override
- public void describeTo(Description description) {
- description.appendText(this.behaviorDescription);
- }
-
- }
-
-}
diff --git a/core/spring-cloud-stream-test-support/src/main/resources/META-INF/spring.binders b/core/spring-cloud-stream-test-support/src/main/resources/META-INF/spring.binders
deleted file mode 100644
index f12cc2353..000000000
--- a/core/spring-cloud-stream-test-support/src/main/resources/META-INF/spring.binders
+++ /dev/null
@@ -1,2 +0,0 @@
-test:\
-org.springframework.cloud.stream.test.binder.TestSupportBinderConfiguration
diff --git a/core/spring-cloud-stream-test-support/src/main/resources/META-INF/spring.factories b/core/spring-cloud-stream-test-support/src/main/resources/META-INF/spring.factories
deleted file mode 100644
index 1bf7aa99f..000000000
--- a/core/spring-cloud-stream-test-support/src/main/resources/META-INF/spring.factories
+++ /dev/null
@@ -1,5 +0,0 @@
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration,\
-org.springframework.cloud.stream.test.binder.MessageCollectorAutoConfiguration
-org.springframework.boot.env.EnvironmentPostProcessor=\
- org.springframework.cloud.stream.test.binder.TestBinderEnvironmentPostProcessor
diff --git a/core/spring-cloud-stream-test-support/src/test/java/org/springframework/cloud/stream/test/matcher/MessageQueueMatcherTest.java b/core/spring-cloud-stream-test-support/src/test/java/org/springframework/cloud/stream/test/matcher/MessageQueueMatcherTest.java
deleted file mode 100644
index 5202f552a..000000000
--- a/core/spring-cloud-stream-test-support/src/test/java/org/springframework/cloud/stream/test/matcher/MessageQueueMatcherTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright 2015-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.stream.test.matcher;
-
-import java.util.Collections;
-import java.util.concurrent.BlockingDeque;
-import java.util.concurrent.LinkedBlockingDeque;
-import java.util.concurrent.TimeUnit;
-
-import org.hamcrest.StringDescription;
-import org.junit.jupiter.api.Test;
-
-import org.springframework.messaging.Message;
-import org.springframework.messaging.support.GenericMessage;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.Matchers.is;
-
-/**
- * Tests for MessageQueueMatcher.
- *
- * @author Eric Bottard
- */
-public class MessageQueueMatcherTest {
-
- private final BlockingDeque> queue = new LinkedBlockingDeque<>();
-
- private final StringDescription description = new StringDescription();
-
- @Test
- public void testTimeout() {
- Message> msg = new GenericMessage<>("hello");
- MessageQueueMatcher> matcher = MessageQueueMatcher.receivesMessageThat(is(msg))
- .within(2, TimeUnit.MILLISECONDS);
-
- boolean result = matcher.matches(this.queue);
- assertThat(result).isFalse();
- matcher.describeMismatch(this.queue, this.description);
- assertThat(this.description.toString())
- .isEqualTo("timed out after 2 milliseconds");
- }
-
- @Test
- public void testMatch() {
- Message> msg = new GenericMessage<>("hello");
- MessageQueueMatcher> matcher = MessageQueueMatcher.receivesMessageThat(is(msg));
- this.queue.offer(msg);
- boolean result = matcher.matches(this.queue);
- assertThat(result).isTrue();
- }
-
- @Test
- public void testMismatch() {
- Message> msg = new GenericMessage<>("hello");
- Message> other = new GenericMessage<>("world");
- MessageQueueMatcher> matcher = MessageQueueMatcher.receivesMessageThat(is(msg));
- this.queue.offer(other);
- boolean result = matcher.matches(this.queue);
- assertThat(result).isFalse();
- matcher.describeMismatch(this.queue, this.description);
- assertThat(this.description.toString()).isEqualTo(("received: <" + other + ">"));
- }
-
- @Test
- public void testExtractor() {
- Message> msg = new GenericMessage<>("hello",
- Collections.singletonMap("foo", (Object) "bar"));
-
- MessageQueueMatcher.Extractor, String> headerExtractor;
- headerExtractor = new MessageQueueMatcher.Extractor, String>(
- "whose 'foo' header") {
- @Override
- public String apply(Message> message) {
- return message.getHeaders().get("foo", String.class);
- }
- };
- MessageQueueMatcher> matcher = new MessageQueueMatcher<>(is("bar"), -1, null,
- headerExtractor);
- this.queue.offer(msg);
- boolean result = matcher.matches(this.queue);
- assertThat(result);
- matcher = new MessageQueueMatcher<>(is("wizz"), -1, null, headerExtractor);
- this.queue.offer(msg);
- result = matcher.matches(this.queue);
- assertThat(result).isFalse();
- matcher.describeMismatch(this.queue, this.description);
- assertThat(this.description.toString()).isEqualTo(("received: \"bar\""));
- }
-
- @Test
- public void testDescription() {
- Message> msg = new GenericMessage<>("hello");
- MessageQueueMatcher> matcher = MessageQueueMatcher.receivesMessageThat(is(msg));
- this.description.appendDescriptionOf(matcher);
- assertThat(this.description.toString())
- .isEqualTo(("Channel to receive a message that is <" + msg + ">"));
- }
-
-}