Loading app/src/androidTest/java/it/niedermann/owncloud/notes/persistence/NotesDatabaseTest.java +19 −6 Original line number Diff line number Diff line Loading @@ -531,9 +531,18 @@ public class NotesDatabaseTest { @Test public void test_14_getCategoryIdsByTitle() { try { // long noteID = db.addNote(account.getId(), new CloudNote(1, Calendar.getInstance(), // "woc", getCurDate() + " woc nmd testing", // true, "aha", null)); long noteID = db.addNote(account.getId(), new CloudNote(1, Calendar.getInstance(), "hello1", getCurDate() + " Mike you look so cool.", true, "Diary", null)); long noteID2 = db.addNote(account.getId(), new CloudNote(1, Calendar.getInstance(), "hello2", getCurDate() + " I'm so cool.", true, "Mike's Diary", null)); long noteID3 = db.addNote(account.getId(), new CloudNote(1, Calendar.getInstance(), "hello3", getCurDate() + " Why Mike so cool.", true, "Andy's Diary", null)); long noteID4 = db.addNote(account.getId(), new CloudNote(1, Calendar.getInstance(), "hello4", getCurDate() + " no person cooler than Mike.", true, "Peter's Diary", null)); Method method_ids_by_title = NotesDatabase.class.getDeclaredMethod("getCategoryIdsByTitle", long.class, String.class); method_ids_by_title.setAccessible(true); Loading @@ -544,7 +553,7 @@ public class NotesDatabaseTest { List<NavigationAdapter.NavigationItem> categories = db.getCategories(account.getId()); Log.i("Test_14_getCategoryIdsByTitle", "size: " + categories.size()); // Log.i("Test_14_getCategoryIdsByTitle", "item: "+ categories.get(0).label); String pattern = "Dia"; String pattern = "Diary"; List<Integer> matchList = new ArrayList<>(); for (NavigationAdapter.NavigationItem categoryItem : categories) { String catTitle = categoryItem.label; Loading @@ -564,9 +573,13 @@ public class NotesDatabaseTest { Collections.sort(testList); Log.i("Test_14_getCategoryIdsByTitle", matchList.toString()); Log.i("Test_14_getCategoryIdsByTitle", testList.toString()); assertEquals(matchList.toString(), testList.toString()); // db.deleteNote(noteID, DBStatus.VOID); db.deleteNote(noteID, DBStatus.VOID); db.deleteNote(noteID2, DBStatus.VOID); db.deleteNote(noteID3, DBStatus.VOID); db.deleteNote(noteID4, DBStatus.VOID); assertEquals(matchList.toString(), testList.toString()); } catch (Exception e) { fail(Arrays.toString(e.getStackTrace())); Log.e("Test_14_getCategoryIdsByTitle", Arrays.toString(e.getStackTrace())); Loading app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java +2 −2 Original line number Diff line number Diff line Loading @@ -379,6 +379,7 @@ public class NotesDatabase extends AbstractNotesDatabase { // TODO: test @NonNull @WorkerThread // the categories without note will not be returned public List<NavigationAdapter.NavigationItem> getCategories(long accountId) { validateAccountId(accountId); String category_title = String.format("%s.%s", table_category, key_title); Loading @@ -387,8 +388,6 @@ public class NotesDatabase extends AbstractNotesDatabase { String category_accountId = String.format("%s.%s", table_category, key_account_id); // Weird problem: If I use ? instead of concat directly, there is no result in the join table // TODO: Find a way to use ? instead of concat. // TODO: a bug here // when no notes and have cat, inner join will not return this cat String rawQuery = "SELECT " + category_title + ", COUNT(*) FROM " + table_category + " INNER JOIN " + table_notes + " ON " + category_id + " = " + note_title + " WHERE " + category_accountId + " = " + accountId + " GROUP BY " + category_id; Loading Loading @@ -923,6 +922,7 @@ public class NotesDatabase extends AbstractNotesDatabase { } // TODO: test // TODO: not fuzzy search by testing bug? private List<Integer> getCategoryIdsByTitle(long accountId, @NonNull String title) { validateAccountId(accountId); Cursor cursor = getReadableDatabase().query( Loading Loading
app/src/androidTest/java/it/niedermann/owncloud/notes/persistence/NotesDatabaseTest.java +19 −6 Original line number Diff line number Diff line Loading @@ -531,9 +531,18 @@ public class NotesDatabaseTest { @Test public void test_14_getCategoryIdsByTitle() { try { // long noteID = db.addNote(account.getId(), new CloudNote(1, Calendar.getInstance(), // "woc", getCurDate() + " woc nmd testing", // true, "aha", null)); long noteID = db.addNote(account.getId(), new CloudNote(1, Calendar.getInstance(), "hello1", getCurDate() + " Mike you look so cool.", true, "Diary", null)); long noteID2 = db.addNote(account.getId(), new CloudNote(1, Calendar.getInstance(), "hello2", getCurDate() + " I'm so cool.", true, "Mike's Diary", null)); long noteID3 = db.addNote(account.getId(), new CloudNote(1, Calendar.getInstance(), "hello3", getCurDate() + " Why Mike so cool.", true, "Andy's Diary", null)); long noteID4 = db.addNote(account.getId(), new CloudNote(1, Calendar.getInstance(), "hello4", getCurDate() + " no person cooler than Mike.", true, "Peter's Diary", null)); Method method_ids_by_title = NotesDatabase.class.getDeclaredMethod("getCategoryIdsByTitle", long.class, String.class); method_ids_by_title.setAccessible(true); Loading @@ -544,7 +553,7 @@ public class NotesDatabaseTest { List<NavigationAdapter.NavigationItem> categories = db.getCategories(account.getId()); Log.i("Test_14_getCategoryIdsByTitle", "size: " + categories.size()); // Log.i("Test_14_getCategoryIdsByTitle", "item: "+ categories.get(0).label); String pattern = "Dia"; String pattern = "Diary"; List<Integer> matchList = new ArrayList<>(); for (NavigationAdapter.NavigationItem categoryItem : categories) { String catTitle = categoryItem.label; Loading @@ -564,9 +573,13 @@ public class NotesDatabaseTest { Collections.sort(testList); Log.i("Test_14_getCategoryIdsByTitle", matchList.toString()); Log.i("Test_14_getCategoryIdsByTitle", testList.toString()); assertEquals(matchList.toString(), testList.toString()); // db.deleteNote(noteID, DBStatus.VOID); db.deleteNote(noteID, DBStatus.VOID); db.deleteNote(noteID2, DBStatus.VOID); db.deleteNote(noteID3, DBStatus.VOID); db.deleteNote(noteID4, DBStatus.VOID); assertEquals(matchList.toString(), testList.toString()); } catch (Exception e) { fail(Arrays.toString(e.getStackTrace())); Log.e("Test_14_getCategoryIdsByTitle", Arrays.toString(e.getStackTrace())); Loading
app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java +2 −2 Original line number Diff line number Diff line Loading @@ -379,6 +379,7 @@ public class NotesDatabase extends AbstractNotesDatabase { // TODO: test @NonNull @WorkerThread // the categories without note will not be returned public List<NavigationAdapter.NavigationItem> getCategories(long accountId) { validateAccountId(accountId); String category_title = String.format("%s.%s", table_category, key_title); Loading @@ -387,8 +388,6 @@ public class NotesDatabase extends AbstractNotesDatabase { String category_accountId = String.format("%s.%s", table_category, key_account_id); // Weird problem: If I use ? instead of concat directly, there is no result in the join table // TODO: Find a way to use ? instead of concat. // TODO: a bug here // when no notes and have cat, inner join will not return this cat String rawQuery = "SELECT " + category_title + ", COUNT(*) FROM " + table_category + " INNER JOIN " + table_notes + " ON " + category_id + " = " + note_title + " WHERE " + category_accountId + " = " + accountId + " GROUP BY " + category_id; Loading Loading @@ -923,6 +922,7 @@ public class NotesDatabase extends AbstractNotesDatabase { } // TODO: test // TODO: not fuzzy search by testing bug? private List<Integer> getCategoryIdsByTitle(long accountId, @NonNull String title) { validateAccountId(accountId); Cursor cursor = getReadableDatabase().query( Loading