add MarcWriter test

This commit is contained in:
Jörg Prante 2022-12-05 15:17:41 +01:00
parent 7a3ccf94a4
commit ddae3f750c
2 changed files with 23 additions and 1 deletions

View file

@ -1,5 +1,5 @@
group = org.xbib
name = marc
version = 2.9.9
version = 2.9.10
org.gradle.warning.mode = ALL

View file

@ -15,15 +15,37 @@
*/
package org.xbib.marc;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
import org.xbib.marc.transformer.value.MarcValueTransformers;
import org.xbib.marc.xml.MarcXchangeWriter;
import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.TreeMap;
public class MarcWriterTest {
@Test
public void testMarcWriter() throws Exception {
Map<String, Object> map = new TreeMap<>(Map.of("001", "123",
"100", Map.of("_", Map.of("a", "Hello World"))));
MarcRecord marcRecord = MarcRecord.from(map);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (MarcWriter writer = new MarcWriter(outputStream, StandardCharsets.UTF_8)) {
writer.startDocument();
writer.record(marcRecord);
writer.endDocument();
assertNull(writer.getException());
}
assertEquals("\u001D00000 0000000 000 \u001E100 \u001FaHello World\u001E001123\u001D\u001C",
outputStream.toString(StandardCharsets.UTF_8));
}
@Test
public void testUtf8MarcWriter() throws Exception {
for (String s : new String[]{