From: Martin Kempf Date: Sun, 1 Apr 2012 09:50:43 +0000 (+0200) Subject: testMarkAllAsRead, testFetchUnreadCommits X-Git-Tag: mobopsys-upload^0 X-Git-Url: https://git.codelabs.ch/?p=gitter-test.git;a=commitdiff_plain testMarkAllAsRead, testFetchUnreadCommits tests implemented for the new CommitDbAdapter methods markAllAsRead and fetchUnreadCommits --- diff --git a/src/ch/codelabs/gitter/test/CommitDbAdapterTest.java b/src/ch/codelabs/gitter/test/CommitDbAdapterTest.java index a2e5e96..78ec0bd 100644 --- a/src/ch/codelabs/gitter/test/CommitDbAdapterTest.java +++ b/src/ch/codelabs/gitter/test/CommitDbAdapterTest.java @@ -103,4 +103,82 @@ public class CommitDbAdapterTest extends AndroidTestCase { i.close(); commitDbAdapter.close(); } + + public void testFetchUnreadCommits() { + final String testHash1 = "c669e1928dec2a9251a819ca40f32beed9e280ec"; + final String testMail = "doe@example.com"; + final String testDate = "Thu Mar 22 21:04:37 CET 2012"; + final CommitDbAdapter commitDbAdapter = new CommitDbAdapter( + getContext()); + commitDbAdapter.open(); + commitDbAdapter.clearDatabase(); + + Commit commit = new Commit(); + commit.mTitle = "Update TODO"; + commit.mCommitId = testHash1; + commit.mAuthor = "John Doe"; + commit.mDate = testDate; + commit.mEmail = testMail; + commit.mDiffLink = "http://1.com/abc"; + commit.mContent = "testdata"; + + Commit commit2 = new Commit(); + commit2.mTitle = "Update TODO"; + commit2.mCommitId = testHash1; + commit2.mAuthor = "John Doe"; + commit2.mDate = testDate; + commit2.mEmail = testMail; + commit2.mDiffLink = "http://1.com/abc"; + commit2.mContent = "testdata"; + + long id = commitDbAdapter.insertCommit(commit); + id = commitDbAdapter.insertCommit(commit2); + commitDbAdapter.setReadStatus(id, true); + + final Cursor c = commitDbAdapter.fetchUnreadCommits(); + assertTrue(c.getCount() == 1); // first commit is unread + c.close(); + commitDbAdapter.close(); + } + + public void testMarkAllAsRead() { + final String testHash1 = "c669e1928dec2a9251a819ca40f32beed9e280ec"; + final String testMail = "doe@example.com"; + final String testDate = "Thu Mar 22 21:04:37 CET 2012"; + final CommitDbAdapter commitDbAdapter = new CommitDbAdapter( + getContext()); + commitDbAdapter.open(); + commitDbAdapter.clearDatabase(); + + Commit commit = new Commit(); + commit.mTitle = "Update TODO"; + commit.mCommitId = testHash1; + commit.mAuthor = "John Doe"; + commit.mDate = testDate; + commit.mEmail = testMail; + commit.mDiffLink = "http://1.com/abc"; + commit.mContent = "testdata"; + + Commit commit2 = new Commit(); + commit2.mTitle = "Update TODO"; + commit2.mCommitId = testHash1; + commit2.mAuthor = "John Doe"; + commit2.mDate = testDate; + commit2.mEmail = testMail; + commit2.mDiffLink = "http://1.com/abc"; + commit2.mContent = "testdata"; + + long id = commitDbAdapter.insertCommit(commit); + id = commitDbAdapter.insertCommit(commit2); + commitDbAdapter.setReadStatus(id, true); + + int markedAsRead = commitDbAdapter.markAllAsRead(); + + final Cursor c = commitDbAdapter.fetchUnreadCommits(); + assertTrue(c.getCount() == 0); // no unread commits anymore + assertTrue(markedAsRead == 1); + c.close(); + commitDbAdapter.close(); + } + }