Permalink
Browse files

tests for isNew and all.

  • Loading branch information...
1 parent e7e5e7c commit e87f65f9d9be9039ec60f5358c4193c2f5a311cf @mattelacchiato committed Oct 26, 2010
Showing with 37 additions and 0 deletions.
  1. +37 −0 src/de/splitstudio/androidb/TableTest.java
@@ -51,9 +51,46 @@ public void testConstructor_tableWithNewId_callOnUpgrade() {
assertEquals(0, getTablesInMetadataCount(tableName));
}
+ public void test_isNew_withId_false() {
+ Table table = new TableExample(db);
+ table._id = 1L;
+ assertEquals(false, table.isNew());
+ }
+
+ public void test_isNew_withoutId_true() {
+ Table table = new TableExample(db);
+ assertEquals(true, table.isNew());
+ }
+
+ public void test_isNew_withZeroId_true() {
+ Table table = new TableExample(db);
+ table._id = 0L;
+ assertEquals(true, table.isNew());
+ }
+
+ public void test_all_emptyTable_emptyCursor() {
+ Table table = new TableExample(db);
+ Cursor c = table.all();
+ assertEquals(0, c.getCount());
+ }
+
+ public void test_all_threeRows_threeRows() {
+ Table table = new TableExample(db);
+
+ table.insert();
+ table._id = null;
+ table.insert();
+ table._id = null;
+ table.insert();
+
+ Cursor c = table.all();
+ assertEquals(3, c.getCount());
+ }
+
private int getTablesInMetadataCount(final String table) {
String sql = String.format("SELECT name FROM sqlite_master WHERE type='table' and name='%s'", table);
Cursor c = db.rawQuery(sql, null);
return c.getCount();
}
+
}

0 comments on commit e87f65f

Please sign in to comment.