package cgeo.geocaching.utils; import static org.assertj.core.api.Assertions.assertThat; import cgeo.org.kxml2.io.KXmlSerializer; import org.apache.commons.lang3.CharEncoding; import org.xmlpull.v1.XmlSerializer; import java.io.IOException; import java.io.StringWriter; import junit.framework.TestCase; public class XmlUtilsTest extends TestCase { private XmlSerializer xml; private StringWriter stringWriter; @Override protected void setUp() throws Exception { super.setUp(); stringWriter = new StringWriter(); xml = new KXmlSerializer(); xml.setOutput(stringWriter); xml.startDocument(CharEncoding.UTF_8, null); } public void testSimpleText() throws Exception { XmlUtils.simpleText(xml, "", "tag", "text"); assertXmlEquals("text"); } public void testSimpleTextWithPrefix() throws Exception { XmlUtils.simpleText(xml, "prefix", "tag", "text"); assertXmlEquals("text"); } private void assertXmlEquals(final String expected) throws IOException { xml.endDocument(); xml.flush(); assertThat(stringWriter.toString()).isEqualTo("" + expected); } public void testMultipleTexts() throws Exception { XmlUtils.multipleTexts(xml, "", "tag1", "text1", "tag2", "text2"); assertXmlEquals("text1text2"); } }