Polishing (Fixed tests)

This commit is contained in:
Oleg Zhurakousky
2017-10-24 14:51:28 -04:00
parent b5aa59e244
commit e45ebb3511

View File

@@ -16,6 +16,8 @@
package org.springframework.cloud.stream.binder;
import java.nio.BufferUnderflowException;
import org.junit.Assert;
import org.junit.Test;
@@ -112,19 +114,9 @@ public class MessageConverterTests {
assertThat(new String(embedded).substring(1)).isEqualTo("\u0001\u0003foo\u0000\u0000\u0000\u0005\"bar\"Hello");
}
@Test
public void testCanDecodeOldFormat() throws Exception {
byte[] bytes = "\u0002\u0003foo\u0003bar\u0003baz\u0004quxxHello".getBytes("UTF-8");
Message<byte[]> message = new GenericMessage<>(bytes);
MessageValues extracted = EmbeddedHeaderUtils.extractHeaders(message, false);
assertThat(new String((byte[]) extracted.getPayload())).isEqualTo("Hello");
assertThat(extracted.get("foo")).isEqualTo("bar");
assertThat(extracted.get("baz")).isEqualTo("quxx");
}
@Test
public void testBadDecode() throws Exception {
byte[] bytes = "\u0002\u0003foo\u0020bar\u0003baz\u0004quxxHello".getBytes("UTF-8");
byte[] bytes = new byte[] { (byte) 0xff, 99 };
Message<byte[]> message = new GenericMessage<>(bytes);
try {
EmbeddedHeaderUtils.extractHeaders(message, false);
@@ -132,10 +124,9 @@ public class MessageConverterTests {
}
catch (Exception e) {
String s = EmbeddedHeaderUtils.decodeExceptionMessage(message);
assertThat(e).isInstanceOf(StringIndexOutOfBoundsException.class);
assertThat(s).startsWith("Could not convert message: 0203666F6F");
assertThat(e).isInstanceOf(BufferUnderflowException.class);
assertThat(s).startsWith("Could not convert message: FF63");
}
}
}