Assert the last commit in the database
[gitter-test.git] / src / ch / codelabs / gitter / test / CommitDbAdapterTest.java
1 /*
2  * Copyright (C) 2012 Martin Kempf <mkempf@hsr.ch>
3  * Copyright (C) 2012 Reto Buerki <reet@codelabs.ch>
4  * Copyright (C) 2012 Adrian-Ken Rueegsegger <ken@codelabs.ch>
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation; either version 2 of the License, or (at your
9  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * for more details.
15  */
16
17 package ch.codelabs.gitter.test;
18
19 import android.database.Cursor;
20 import android.test.AndroidTestCase;
21
22 import ch.codelabs.gitter.CommitDbAdapter;
23
24 public class CommitDbAdapterTest extends AndroidTestCase {
25
26         /*
27          * Register tests.
28          */
29         public CommitDbAdapterTest() {
30                 super();
31         }
32
33         /*
34          * Insert commit into database.
35          */
36         public void testInsertCommit() {
37                 final CommitDbAdapter commitDbAdapter = new
38                                 CommitDbAdapter(getContext());
39                 commitDbAdapter.open();
40
41                 final long id = commitDbAdapter.insertCommit("Update TODO",
42                                 "John Doe doe@example.com", "http://1.com/abc", "testdata");
43
44                 final Cursor c = commitDbAdapter.fetchAllCommits();
45                 assertTrue(c.getCount() > 0);
46
47                 c.moveToLast();
48                 assertEquals("Update TODO", c.getString
49                                 (c.getColumnIndexOrThrow(CommitDbAdapter.KEY_TITLE)));
50                 assertEquals("John Doe doe@example.com", c.getString
51                                 (c.getColumnIndexOrThrow(CommitDbAdapter.KEY_AUTHOR)));
52                 assertEquals("http://1.com/abc", c.getString
53                                 (c.getColumnIndexOrThrow(CommitDbAdapter.KEY_DIFFLINK)));
54                 assertEquals("testdata", c.getString
55                                 (c.getColumnIndexOrThrow(CommitDbAdapter.KEY_CONTENT)));
56
57                 commitDbAdapter.deleteCommit(id);
58                 c.close();
59                 commitDbAdapter.close();
60         }
61 }