Move tests to AssertJ

This commit is contained in:
Marius Bogoevici
2016-05-29 08:32:29 -04:00
committed by Soby Chacko
parent fbe9bbac7e
commit aef08a28a3
29 changed files with 780 additions and 946 deletions

View File

@@ -35,8 +35,7 @@ import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test that validates that {@link org.springframework.cloud.stream.test.binder.TestSupportBinder} applies
@@ -48,23 +47,23 @@ import static org.junit.Assert.assertThat;
@DirtiesContext
public class ExampleTest {
@Autowired
@Bindings(MyProcessor.class)
private Processor processor;
@Autowired
private BinderFactory<MessageChannel> binderFactory;
@Autowired
private MessageCollector messageCollector;
@Autowired
@Bindings(MyProcessor.class)
private Processor processor;
@Test
@SuppressWarnings("unchecked")
public void testWiring() {
Message<String> message = new GenericMessage<>("hello");
processor.input().send(message);
Message<String> received = (Message<String>) messageCollector.forChannel(processor.output()).poll();
assertThat(received.getPayload(), equalTo("hello world"));
this.processor.input().send(message);
Message<String> received = (Message<String>) this.messageCollector.forChannel(this.processor.output()).poll();
assertThat(received.getPayload()).isEqualTo("hello world");
}
@@ -72,9 +71,6 @@ public class ExampleTest {
@EnableBinding(Processor.class)
public static class MyProcessor {
@Autowired
private Processor channels;
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public String transform(String in) {
return in + " world";

View File

@@ -27,8 +27,8 @@ import org.junit.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;
import static org.junit.Assert.assertThat;
/**
* Tests for MessageQueueMatcher.
@@ -44,71 +44,64 @@ public class MessageQueueMatcherTest {
@Test
public void testTimeout() {
Message<?> msg = new GenericMessage<>("hello");
MessageQueueMatcher<?> matcher = MessageQueueMatcher.receivesMessageThat(is(msg)).within(2, TimeUnit.MILLISECONDS);
MessageQueueMatcher<?> matcher = MessageQueueMatcher.receivesMessageThat(is(msg)).within(2,
TimeUnit.MILLISECONDS);
boolean result = matcher.matches(queue);
assertThat(result, is(false));
matcher.describeMismatch(queue, description);
assertThat(description.toString(), is("timed out after 2 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));
queue.offer(msg);
boolean result = matcher.matches(queue);
assertThat(result, is(true));
this.queue.offer(msg);
boolean result = matcher.matches(this.queue);
assertThat(result).isTrue();
}
@Test
public void testMisMatch() {
public void testMismatch() {
Message<?> msg = new GenericMessage<>("hello");
Message<?> other = new GenericMessage<>("world");
MessageQueueMatcher<?> matcher = MessageQueueMatcher.receivesMessageThat(is(msg));
queue.offer(other);
boolean result = matcher.matches(queue);
assertThat(result, is(false));
matcher.describeMismatch(queue, description);
assertThat(description.toString(), is("received: <" + other + ">"));
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<Message<?>, String> headerExtractor = new MessageQueueMatcher.Extractor<Message<?>, String>("whose 'foo' header") {
MessageQueueMatcher.Extractor<Message<?>, String> headerExtractor = new MessageQueueMatcher.Extractor<Message<?>, 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);
queue.offer(msg);
boolean result = matcher.matches(queue);
assertThat(result, is(true));
this.queue.offer(msg);
boolean result = matcher.matches(this.queue);
assertThat(result);
matcher = new MessageQueueMatcher<>(is("wizz"), -1, null, headerExtractor);
queue.offer(msg);
result = matcher.matches(queue);
assertThat(result, is(false));
matcher.describeMismatch(queue, description);
assertThat(description.toString(), is("received: \"bar\""));
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));
description.appendDescriptionOf(matcher);
assertThat(description.toString(), is("Channel to receive a message that is <" + msg + ">"));
this.description.appendDescriptionOf(matcher);
assertThat(this.description.toString()).isEqualTo(("Channel to receive a message that is <" + msg + ">"));
}
}