Initial import of gitter Android test project
[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                 CommitDbAdapter commitDbAdapter = new CommitDbAdapter(getContext());
38                 commitDbAdapter.open();
39
40                 long id = commitDbAdapter.insertCommit("Update TODO",
41                                 "John Doe doe@example.com", "http://1.com/abc", "testdata");
42
43                 Cursor c = commitDbAdapter.fetchAllCommits();
44                 assertTrue(c.getCount() > 0);
45
46                 c.moveToFirst();
47                 assertEquals("Update TODO", c.getString
48                                 (c.getColumnIndexOrThrow(CommitDbAdapter.KEY_TITLE)));
49                 assertEquals("John Doe doe@example.com", c.getString
50                                 (c.getColumnIndexOrThrow(CommitDbAdapter.KEY_AUTHOR)));
51                 assertEquals("http://1.com/abc", c.getString
52                                 (c.getColumnIndexOrThrow(CommitDbAdapter.KEY_DIFFLINK)));
53                 assertEquals("testdata", c.getString
54                                 (c.getColumnIndexOrThrow(CommitDbAdapter.KEY_CONTENT)));
55
56                 commitDbAdapter.deleteCommit(id);
57                 c.close();
58                 commitDbAdapter.close();
59         }
60 }