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();
+ }
+
}