diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-10 18:32:35 (GMT) |
---|---|---|
committer | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-16 19:11:04 (GMT) |
commit | b2a8ac9a0387a9a5e75e31f7704e62ac077faba4 (patch) | |
tree | 633f0aa33043bef9db2f677d6b0874552562db75 /test/com | |
parent | 2180f81bd45045021d98c3a2e0649f10680596f9 (diff) | |
download | stroke-b2a8ac9a0387a9a5e75e31f7704e62ac077faba4.zip stroke-b2a8ac9a0387a9a5e75e31f7704e62ac077faba4.tar.bz2 |
Add the UserTune Element.
Adds UserTune Element, its parser and Serializer.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Tests added for UserTune Parser and UserTune Serializer.
Change-Id: I3330d8493c79c2305de426827b5018b68d5b8e1b
Diffstat (limited to 'test/com')
-rw-r--r-- | test/com/isode/stroke/parser/payloadparsers/UserTuneParserTest.java | 57 | ||||
-rw-r--r-- | test/com/isode/stroke/serializer/payloadserializers/UserTuneSerializerTest.java | 55 |
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 |