testMarkAllAsRead, testFetchUnreadCommits master mobopsys-upload v1.0
authorMartin Kempf <mkempf@hsr.ch>
Sun, 1 Apr 2012 09:50:43 +0000 (11:50 +0200)
committerMartin Kempf <mkempf@hsr.ch>
Sun, 1 Apr 2012 09:50:43 +0000 (11:50 +0200)
tests implemented for the new CommitDbAdapter methods markAllAsRead and fetchUnreadCommits

src/ch/codelabs/gitter/test/CommitDbAdapterTest.java

index a2e5e96..78ec0bd 100644 (file)
@@ -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();
+       }
+
 }