Loading app/src/androidTest/java/it/niedermann/owncloud/notes/persistence/NotesDatabaseTest.java +62 −7 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ import it.niedermann.owncloud.notes.model.CloudNote; import it.niedermann.owncloud.notes.model.DBNote; import it.niedermann.owncloud.notes.model.LocalAccount; import it.niedermann.owncloud.notes.model.NavigationAdapter; import it.niedermann.owncloud.notes.persistence.NotesDatabase; import android.content.Context; import android.util.Log; Loading @@ -17,7 +18,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.List; Loading @@ -26,6 +29,7 @@ import java.util.TimeZone; import static org.junit.Assert.*; /** * WARNING: for all the test case written by order * you must run all the test case in the same time Loading Loading @@ -451,20 +455,71 @@ public class NotesDatabaseTest { } @Test public void setCategory() { // Unable to test with SSO public void test_12_getNoteFromCursor(){ // pass } @Test public void test_13_getTitleByCategoryId(){ } @Test public void updateNoteAndSync() { // Unable to test with SSO public void test_14_getCategoryIdsByTitle(){ } @Test public void updateNote() { // can not check // need remoteNote (note from server) public void test_15_getCategoryIdByTitle(){ try { // TODO: forName error Class c = Class.forName("NotesDatabase"); Log.i("gogogogo", c.getName()); Method method = Class.forName("NotesDatabase") .getDeclaredMethod("getCategoryIdByTitle", Long.class, String.class, Boolean.class); method.setAccessible(true); List<NavigationAdapter.NavigationItem> categories = db.getCategories(account.getId()); int count = 0; for (NavigationAdapter.NavigationItem categoryItem : categories) { Log.i("Test_15_getCategoryIdByTitle", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon)); count++; } Log.i("Test_15_getCategoryIdByTitle", "count " + count); int catID = (int)method.invoke(db, account.getId(), "Mike Chester Wang's Diary", false); assertEquals(catID, -1); catID = (int)method.invoke(db, account.getId(), "Mike Chester Wang's Diary", true); assertNotEquals(catID, -1); catID = (int)method.invoke(db, account.getId(), "hello", true); assertEquals(catID, -1); }catch (Exception e){ fail(Arrays.toString(e.getStackTrace())); Log.e("Test_15_getCategoryIdByTitle_Exception", Arrays.toString(e.getStackTrace())); } } // @Test // public void setCategory() { // // Unable to test with SSO // } // // @Test // public void updateNoteAndSync() { // // Unable to test with SSO // } // // @Test // public void updateNote() { // // can not check // // need remoteNote (note from server) // } public static String getCurDate() { TimeZone.setDefault(TimeZone.getTimeZone("GMT+8")); Loading app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java +6 −0 Original line number Diff line number Diff line Loading @@ -852,6 +852,8 @@ public class NotesDatabase extends AbstractNotesDatabase { @NonNull @WorkerThread private Integer getCategoryIdByTitle(long accountId, @NonNull String categoryTitle, boolean create) { // TODO: there is a bug // only validateAccountId BUT NOT use if (create) { if (getCategoryIdByTitle(accountId, categoryTitle, false) == -1) { if (addCategory(categoryTitle, accountId) == -1) { Loading Loading @@ -881,6 +883,8 @@ public class NotesDatabase extends AbstractNotesDatabase { @NonNull @WorkerThread private String getTitleByCategoryId(long accountId, int id) { // TODO: there is a bug // only validateAccountId BUT NOT use if (accountId != -1) validateAccountId(accountId); Cursor cursor = getReadableDatabase().query( Loading Loading @@ -925,6 +929,8 @@ public class NotesDatabase extends AbstractNotesDatabase { // TODO: test private List<Integer> getCategoryIdsByTitle(long accountId, @NonNull String title) { // TODO: there is a bug // only validateAccountId BUT NOT use validateAccountId(accountId); Cursor cursor = getReadableDatabase().query( table_category, Loading Loading
app/src/androidTest/java/it/niedermann/owncloud/notes/persistence/NotesDatabaseTest.java +62 −7 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ import it.niedermann.owncloud.notes.model.CloudNote; import it.niedermann.owncloud.notes.model.DBNote; import it.niedermann.owncloud.notes.model.LocalAccount; import it.niedermann.owncloud.notes.model.NavigationAdapter; import it.niedermann.owncloud.notes.persistence.NotesDatabase; import android.content.Context; import android.util.Log; Loading @@ -17,7 +18,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.List; Loading @@ -26,6 +29,7 @@ import java.util.TimeZone; import static org.junit.Assert.*; /** * WARNING: for all the test case written by order * you must run all the test case in the same time Loading Loading @@ -451,20 +455,71 @@ public class NotesDatabaseTest { } @Test public void setCategory() { // Unable to test with SSO public void test_12_getNoteFromCursor(){ // pass } @Test public void test_13_getTitleByCategoryId(){ } @Test public void updateNoteAndSync() { // Unable to test with SSO public void test_14_getCategoryIdsByTitle(){ } @Test public void updateNote() { // can not check // need remoteNote (note from server) public void test_15_getCategoryIdByTitle(){ try { // TODO: forName error Class c = Class.forName("NotesDatabase"); Log.i("gogogogo", c.getName()); Method method = Class.forName("NotesDatabase") .getDeclaredMethod("getCategoryIdByTitle", Long.class, String.class, Boolean.class); method.setAccessible(true); List<NavigationAdapter.NavigationItem> categories = db.getCategories(account.getId()); int count = 0; for (NavigationAdapter.NavigationItem categoryItem : categories) { Log.i("Test_15_getCategoryIdByTitle", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon)); count++; } Log.i("Test_15_getCategoryIdByTitle", "count " + count); int catID = (int)method.invoke(db, account.getId(), "Mike Chester Wang's Diary", false); assertEquals(catID, -1); catID = (int)method.invoke(db, account.getId(), "Mike Chester Wang's Diary", true); assertNotEquals(catID, -1); catID = (int)method.invoke(db, account.getId(), "hello", true); assertEquals(catID, -1); }catch (Exception e){ fail(Arrays.toString(e.getStackTrace())); Log.e("Test_15_getCategoryIdByTitle_Exception", Arrays.toString(e.getStackTrace())); } } // @Test // public void setCategory() { // // Unable to test with SSO // } // // @Test // public void updateNoteAndSync() { // // Unable to test with SSO // } // // @Test // public void updateNote() { // // can not check // // need remoteNote (note from server) // } public static String getCurDate() { TimeZone.setDefault(TimeZone.getTimeZone("GMT+8")); Loading
app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java +6 −0 Original line number Diff line number Diff line Loading @@ -852,6 +852,8 @@ public class NotesDatabase extends AbstractNotesDatabase { @NonNull @WorkerThread private Integer getCategoryIdByTitle(long accountId, @NonNull String categoryTitle, boolean create) { // TODO: there is a bug // only validateAccountId BUT NOT use if (create) { if (getCategoryIdByTitle(accountId, categoryTitle, false) == -1) { if (addCategory(categoryTitle, accountId) == -1) { Loading Loading @@ -881,6 +883,8 @@ public class NotesDatabase extends AbstractNotesDatabase { @NonNull @WorkerThread private String getTitleByCategoryId(long accountId, int id) { // TODO: there is a bug // only validateAccountId BUT NOT use if (accountId != -1) validateAccountId(accountId); Cursor cursor = getReadableDatabase().query( Loading Loading @@ -925,6 +929,8 @@ public class NotesDatabase extends AbstractNotesDatabase { // TODO: test private List<Integer> getCategoryIdsByTitle(long accountId, @NonNull String title) { // TODO: there is a bug // only validateAccountId BUT NOT use validateAccountId(accountId); Cursor cursor = getReadableDatabase().query( table_category, Loading