DBZ-759 Add Test to ensure correct serialization of byte arrays

Needed to make RecordWriter public to have access in tests.
This commit is contained in:
Andreas Bergmeier 2018-06-22 11:23:48 +02:00 committed by Gunnar Morling
parent 71abca2afb
commit 82bac78ba8
2 changed files with 43 additions and 1 deletions

View File

@ -119,7 +119,7 @@ public static String asDetailedString(SourceRecord record) {
return new RecordWriter().detailed(true).append(record).toString();
}
protected static class RecordWriter {
public static class RecordWriter {
private final StringBuilder sb = new StringBuilder();
private boolean detailed = false;

View File

@ -0,0 +1,42 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.data;
import io.debezium.data.SchemaUtil.RecordWriter;
import io.debezium.doc.FixFor;
import java.nio.ByteBuffer;
import org.junit.Test;
import static org.fest.assertions.Assertions.assertThat;
/**
* Test for {@link SchemaUtil.RecordWriter}.
*
* @author Andreas Bergmeier
*
*/
public class RecordWriterTest {
@Test
@FixFor("DBZ-759")
public void correctlySerializesByteArray() {
final RecordWriter recordWriter = new RecordWriter();
recordWriter.append(new byte[]{1, 3, 5, 7});
assertThat(recordWriter.toString()).isEqualTo("\"[1, 3, 5, 7]\"");
}
@Test
@FixFor("DBZ-759")
public void correctlySerializesByteBuffer() {
final RecordWriter recordWriter = new RecordWriter();
final ByteBuffer buffer = ByteBuffer.allocate(3);
buffer.put(new byte[]{11, 13, 17});
recordWriter.append(buffer);
assertThat(recordWriter.toString()).isEqualTo("\"[11, 13, 17]\"");
}
}