aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/utils
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/cgeo/geocaching/utils')
-rw-r--r--tests/src/cgeo/geocaching/utils/CryptUtilsTest.java6
-rw-r--r--tests/src/cgeo/geocaching/utils/UncertainPropertyTest.java19
-rw-r--r--tests/src/cgeo/geocaching/utils/XmlUtilsTest.java48
3 files changed, 73 insertions, 0 deletions
diff --git a/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java b/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java
index e727747..9a74167 100644
--- a/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java
@@ -23,4 +23,10 @@ public class CryptUtilsTest extends TestCase {
public static void testIssue1902() {
assertEquals("ƖƖlƖƖƖƖ", CryptUtils.rot13("ƖƖyƖƖƖƖ"));
}
+
+ public static void testMd5() {
+ assertEquals("d41d8cd98f00b204e9800998ecf8427e", CryptUtils.md5(""));
+ // expected value taken from debugger. should assure every developer uses UTF-8
+ assertEquals("a7f4e3ec08f09be2ef7ecb4eea5f8981", CryptUtils.md5("äöü"));
+ }
}
diff --git a/tests/src/cgeo/geocaching/utils/UncertainPropertyTest.java b/tests/src/cgeo/geocaching/utils/UncertainPropertyTest.java
new file mode 100644
index 0000000..74aa680
--- /dev/null
+++ b/tests/src/cgeo/geocaching/utils/UncertainPropertyTest.java
@@ -0,0 +1,19 @@
+package cgeo.geocaching.utils;
+
+import junit.framework.TestCase;
+
+public class UncertainPropertyTest extends TestCase {
+
+ public static void testHigherCertaintyWins() throws Exception {
+ final UncertainProperty<String> prop1 = new UncertainProperty<String>("prop1", 10);
+ final UncertainProperty<String> prop2 = new UncertainProperty<String>("prop2", 20);
+ assertEquals(prop2, UncertainProperty.getMergedProperty(prop1, prop2));
+ }
+
+ public static void testAvoidNull() throws Exception {
+ final UncertainProperty<String> prop1 = new UncertainProperty<String>("prop1", 10);
+ final UncertainProperty<String> prop2 = new UncertainProperty<String>(null, 20);
+ assertEquals(prop1, UncertainProperty.getMergedProperty(prop1, prop2));
+ assertEquals(prop1, UncertainProperty.getMergedProperty(prop2, prop1));
+ }
+}
diff --git a/tests/src/cgeo/geocaching/utils/XmlUtilsTest.java b/tests/src/cgeo/geocaching/utils/XmlUtilsTest.java
new file mode 100644
index 0000000..a089ee0
--- /dev/null
+++ b/tests/src/cgeo/geocaching/utils/XmlUtilsTest.java
@@ -0,0 +1,48 @@
+package cgeo.geocaching.utils;
+
+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("<tag>text</tag>");
+ }
+
+ public void testSimpleTextWithPrefix() throws Exception {
+ XmlUtils.simpleText(xml, "prefix", "tag", "text");
+ assertXmlEquals("<n0:tag xmlns:n0=\"prefix\">text</n0:tag>");
+ }
+
+ private void assertXmlEquals(final String expected) throws IOException {
+ xml.endDocument();
+ xml.flush();
+ assertEquals("<?xml version='1.0' encoding='UTF-8' ?>" + expected, stringWriter.toString());
+ }
+
+ public void testMultipleTexts() throws Exception {
+ XmlUtils.multipleTexts(xml, "", "tag1", "text1", "tag2", "text2");
+ assertXmlEquals("<tag1>text1</tag1><tag2>text2</tag2>");
+ }
+
+}