summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'test/com/isode')
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/UserTuneParserTest.java57
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/UserTuneSerializerTest.java55
2 files changed, 112 insertions, 0 deletions
diff --git a/test/com/isode/stroke/parser/payloadparsers/UserTuneParserTest.java b/test/com/isode/stroke/parser/payloadparsers/UserTuneParserTest.java
new file mode 100644
index 0000000..b136ea1
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/UserTuneParserTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.parser.payloadparsers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import org.junit.Test;
+import com.isode.stroke.elements.UserTune;
+import com.isode.stroke.parser.payloadparsers.UserTuneParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+
+public class UserTuneParserTest {
+
+ public UserTuneParserTest() {
+
+ }
+
+ @Test
+ public void testParse_with_all_variables() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<tune xmlns=\"http://jabber.org/protocol/tune\">" +
+ "<rating>5</rating><title>Minion</title><track>Yellow</track><artist>Ice</artist><URI>Fire</URI><source>Origin</source><length>226</length></tune>"));
+
+ UserTune payload = (UserTune)parser.getPayload();
+ assertEquals(Integer.valueOf(5), payload.getRating());
+ assertEquals("Minion", payload.getTitle());
+ assertEquals("Yellow", payload.getTrack());
+ assertEquals("Ice", payload.getArtist());
+ assertEquals("Fire", payload.getURI());
+ assertEquals("Origin", payload.getSource());
+ assertEquals(Integer.valueOf(226), payload.getLength());
+ }
+
+ @Test
+ public void testParse_with_some_variables() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<tune xmlns=\"http://jabber.org/protocol/tune\">" +
+ "<title>Minion</title><track>Yellow</track><source>Origin</source><length>226</length></tune>"));
+
+ UserTune payload = (UserTune)parser.getPayload();
+ assertNull(payload.getRating());
+ assertEquals("Minion", payload.getTitle());
+ assertEquals("Yellow", payload.getTrack());
+ assertNull(payload.getArtist());
+ assertNull(payload.getURI());
+ assertEquals("Origin", payload.getSource());
+ assertEquals(Integer.valueOf(226), payload.getLength());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/UserTuneSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/UserTuneSerializerTest.java
new file mode 100644
index 0000000..765ca5c
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/UserTuneSerializerTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.serializer.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.UserTuneSerializer;
+import com.isode.stroke.serializer.PayloadSerializerCollection;
+import com.isode.stroke.elements.UserTune;
+
+public class UserTuneSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public UserTuneSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize_withAllVariablesSet() {
+ PayloadSerializerCollection serializerCollection = new PayloadSerializerCollection();
+ UserTuneSerializer testling = new UserTuneSerializer(serializerCollection);
+ UserTune userTune = new UserTune();
+ userTune.setRating(5);
+ userTune.setTitle("Minion");
+ userTune.setTrack("Yellow");
+ userTune.setArtist("Ice");
+ userTune.setURI("Fire");
+ userTune.setSource("Origin");
+ userTune.setLength(226);
+ String expectedResult = "<tune xmlns=\"http://jabber.org/protocol/tune\">" +
+ "<rating>5</rating><title>Minion</title><track>Yellow</track><artist>Ice</artist><uri>Fire</uri><source>Origin</source><length>226</length></tune>";
+ assertEquals(expectedResult, testling.serialize(userTune));
+ }
+
+ @Test
+ public void testSerialize_withSomeVariablesSet() {
+ PayloadSerializerCollection serializerCollection = new PayloadSerializerCollection();
+ UserTuneSerializer testling = new UserTuneSerializer(serializerCollection);
+ UserTune userTune = new UserTune();
+ userTune.setTitle("Minion");
+ userTune.setTrack("Yellow");
+ userTune.setArtist("Ice");
+ userTune.setSource("Origin");
+ userTune.setLength(226);
+ String expectedResult = "<tune xmlns=\"http://jabber.org/protocol/tune\">" +
+ "<title>Minion</title><track>Yellow</track><artist>Ice</artist><source>Origin</source><length>226</length></tune>";
+ assertEquals(expectedResult, testling.serialize(userTune));
+ }
+} \ No newline at end of file