|
| 1 | +package org.dodgybits.android.shuffle.test; |
| 2 | + |
| 3 | +import java.io.StringReader; |
| 4 | + |
| 5 | + |
| 6 | +import org.dodgybits.shuffle.android.core.model.Id; |
| 7 | +import org.dodgybits.shuffle.android.core.model.Project; |
| 8 | +import org.dodgybits.shuffle.android.synchronisation.tracks.parsing.IContextLookup; |
| 9 | +import org.dodgybits.shuffle.android.synchronisation.tracks.parsing.ProjectParser; |
| 10 | +import org.xmlpull.v1.XmlPullParser; |
| 11 | +import org.xmlpull.v1.XmlPullParserException; |
| 12 | + |
| 13 | +import android.util.Xml; |
| 14 | +import junit.framework.Assert; |
| 15 | +import junit.framework.TestCase; |
| 16 | + |
| 17 | +public class ProjectParserTests extends TestCase { |
| 18 | + public ProjectParser CreateSUT() { |
| 19 | + return new ProjectParser(new IContextLookup() { |
| 20 | + |
| 21 | + @Override |
| 22 | + public Id findContextIdByTracksId(Id tracksId) { |
| 23 | + // TODO Auto-generated method stub |
| 24 | + return Id.create(1234); |
| 25 | + } |
| 26 | + }, null); |
| 27 | + } |
| 28 | + public void testProjectParserBasicParsingTest() { |
| 29 | + XmlPullParser xmlParser = Xml.newPullParser(); |
| 30 | + |
| 31 | + try { |
| 32 | + xmlParser.setInput(new StringReader("<project>"+ |
| 33 | + "<completed-at type=\"datetime\" nil=\"true\"/>"+ |
| 34 | + "<created-at type=\"datetime\">2010-01-09T21:21:13+01:00</created-at>"+ |
| 35 | + "<default-context-id type=\"integer\" nil=\"true\"/>"+ |
| 36 | + "<default-tags nil=\"true\"/>"+ |
| 37 | + "<description nil=\"true\"/>"+ |
| 38 | + "<id type=\"integer\">4532</id>"+ |
| 39 | + "<name>Homework</name>"+ |
| 40 | + "<position type=\"integer\">1</position>"+ |
| 41 | + "<state>active</state>"+ |
| 42 | + "<updated-at type=\"datetime\">2010-02-03T10:37:19+01:00</updated-at>"+ |
| 43 | + "</project>")); |
| 44 | + } catch (XmlPullParserException e) { |
| 45 | + // TODO Auto-generated catch block |
| 46 | + e.printStackTrace(); |
| 47 | + } |
| 48 | + ProjectParser parser = CreateSUT(); |
| 49 | + Project project = parser.parseSingle(xmlParser).getResult(); |
| 50 | + Assert.assertEquals("Homework", project.getName()); |
| 51 | + Assert.assertEquals(Id.create(4532), project.getTracksId()); |
| 52 | + Assert.assertEquals(1265189839000l, project.getModifiedDate()); |
| 53 | + assertEquals(Id.NONE, project.getDefaultContextId()); |
| 54 | + assertEquals(false, project.isArchived()); |
| 55 | + |
| 56 | + |
| 57 | + } |
| 58 | + public void testProjectParserBasicParsingTestWithDefaultContext() { |
| 59 | + XmlPullParser xmlParser = Xml.newPullParser(); |
| 60 | + |
| 61 | + try { |
| 62 | + xmlParser.setInput(new StringReader("<project>"+ |
| 63 | + "<completed-at type=\"datetime\" nil=\"true\"/>"+ |
| 64 | + "<created-at type=\"datetime\">2010-01-09T21:21:13+01:00</created-at>"+ |
| 65 | + "<default-context-id type=\"integer\">2222</default-context-id>"+ |
| 66 | + "<default-tags nil=\"true\"/>"+ |
| 67 | + "<description nil=\"true\"/>"+ |
| 68 | + "<id type=\"integer\">4532</id>"+ |
| 69 | + "<name>Homework</name>"+ |
| 70 | + "<position type=\"integer\">1</position>"+ |
| 71 | + "<state>active</state>"+ |
| 72 | + "<updated-at type=\"datetime\">2010-02-03T10:37:19+01:00</updated-at>"+ |
| 73 | + "</project>")); |
| 74 | + } catch (XmlPullParserException e) { |
| 75 | + // TODO Auto-generated catch block |
| 76 | + e.printStackTrace(); |
| 77 | + } |
| 78 | + ProjectParser parser = CreateSUT(); |
| 79 | + Project project = parser.parseSingle(xmlParser).getResult(); |
| 80 | + Assert.assertEquals("Homework", project.getName()); |
| 81 | + Assert.assertEquals(Id.create(4532), project.getTracksId()); |
| 82 | + Assert.assertEquals(1265189839000l, project.getModifiedDate()); |
| 83 | + assertEquals(Id.create(1234), project.getDefaultContextId()); |
| 84 | + assertEquals(false, project.isArchived()); |
| 85 | + |
| 86 | + |
| 87 | + } |
| 88 | +} |
0 commit comments