package org.zwobble.mammoth.tests.docx; import org.junit.Test; import org.zwobble.mammoth.internal.archives.Archives; import org.zwobble.mammoth.internal.archives.InMemoryArchive; import org.zwobble.mammoth.internal.archives.MutableArchive; import org.zwobble.mammoth.internal.docx.*; import org.zwobble.mammoth.internal.util.Streams; import java.io.IOException; import java.util.Optional; import static org.junit.Assert.assertEquals; import static org.zwobble.mammoth.internal.util.Maps.map; public class EmbeddedStyleMapTests { private static final String ORIGINAL_RELATIONSHIPS_XML = "" + "" + "" + ""; private static final String ORIGINAL_CONTENT_TYPES_XML = "" + "" + "" + ""; @Test public void embeddedStyleMapPreservesUnrelatedFiles() throws IOException { MutableArchive archive = normalDocx(); EmbeddedStyleMap.embedStyleMap(archive, "p => h1"); assertEquals("placeholder text", Streams.toString(Archives.getInputStream(archive, "placeholder"))); } @Test public void embeddedStyleMapCanBeReadAfterBeingEmbedded() throws IOException { MutableArchive archive = normalDocx(); EmbeddedStyleMap.embedStyleMap(archive, "p => h1"); assertEquals(Optional.of("p => h1"), EmbeddedStyleMap.readStyleMap(archive)); } private static MutableArchive normalDocx() { return InMemoryArchive.fromStrings(map( "placeholder", "placeholder text", "word/_rels/document.xml.rels", ORIGINAL_RELATIONSHIPS_XML, "[Content_Types].xml", ORIGINAL_CONTENT_TYPES_XML )); } }