diff --git a/app/src/androidTest/java/com/orgzly/android/espresso/MiscTest.java b/app/src/androidTest/java/com/orgzly/android/espresso/MiscTest.java index efecf1958..1076fc20a 100644 --- a/app/src/androidTest/java/com/orgzly/android/espresso/MiscTest.java +++ b/app/src/androidTest/java/com/orgzly/android/espresso/MiscTest.java @@ -66,17 +66,17 @@ public class MiscTest extends OrgzlyTest { public void testLftRgt() { testUtils.setupBook("booky", "Preface\n* Note 1\n** Note 2\n* Note 3\n"); - ActivityScenario.launch(MainActivity.class); - - NotePosition n1 = dataRepository.getLastNote("Note 1").getPosition(); - NotePosition n2 = dataRepository.getLastNote("Note 2").getPosition(); - NotePosition n3 = dataRepository.getLastNote("Note 3").getPosition(); - - assertTrue(n1.getLft() < n2.getLft()); - assertTrue(n2.getLft() < n2.getRgt()); - assertTrue(n2.getRgt() < n1.getRgt()); - assertTrue(n1.getRgt() < n3.getLft()); - assertTrue(n3.getLft() < n3.getRgt()); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + NotePosition n1 = dataRepository.getLastNote("Note 1").getPosition(); + NotePosition n2 = dataRepository.getLastNote("Note 2").getPosition(); + NotePosition n3 = dataRepository.getLastNote("Note 3").getPosition(); + + assertTrue(n1.getLft() < n2.getLft()); + assertTrue(n2.getLft() < n2.getRgt()); + assertTrue(n2.getRgt() < n1.getRgt()); + assertTrue(n1.getRgt() < n3.getLft()); + assertTrue(n3.getLft() < n3.getRgt()); + } } @Test @@ -94,35 +94,35 @@ public void testClearDatabaseWithFragmentsInBackStack() { "* Note #2.\n" + "** TODO Note #3.\n"); - ActivityScenario.launch(MainActivity.class); - - onView(withId(R.id.fragment_books_view_flipper)).check(matches(isDisplayed())); - - onBook(0).perform(click()); - onView(withText("Note B.")).perform(click()); - onView(withId(R.id.drawer_layout)).perform(open()); - onView(allOf(withText("book-two"), isDisplayed())).perform(click()); - onView(withText("Note #2.")).perform(click()); - onActionItemClick(R.id.activity_action_settings, R.string.settings); - clickSetting("prefs_screen_app", R.string.app); - clickSetting("pref_key_clear_database", R.string.clear_database); - onView(withText(R.string.ok)).perform(click()); - pressBack(); - pressBack(); - - onView(withId(R.id.fragment_books_view_flipper)).check(matches(isDisplayed())); - onView(withText(R.string.no_notebooks)).check(matches(isDisplayed())); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onView(withId(R.id.fragment_books_view_flipper)).check(matches(isDisplayed())); + + onBook(0).perform(click()); + onView(withText("Note B.")).perform(click()); + onView(withId(R.id.drawer_layout)).perform(open()); + onView(allOf(withText("book-two"), isDisplayed())).perform(click()); + onView(withText("Note #2.")).perform(click()); + onActionItemClick(R.id.activity_action_settings, R.string.settings); + clickSetting("prefs_screen_app", R.string.app); + clickSetting("pref_key_clear_database", R.string.clear_database); + onView(withText(R.string.ok)).perform(click()); + pressBack(); + pressBack(); + + onView(withId(R.id.fragment_books_view_flipper)).check(matches(isDisplayed())); + onView(withText(R.string.no_notebooks)).check(matches(isDisplayed())); + } } @Test public void testClickOnListViewItemOutOfView() { testUtils.setupBook("book-one", "Sample book used for tests\n* 1\n* 2\n* 3\n* 4\n* 5\n* 6\n* 7\n* 8\n* 9\n* 10\n* 11\n* 12\n* 13\n* 14\n* 15\n"); - ActivityScenario.launch(MainActivity.class); - - onBook(0).perform(click()); - onView(withId(R.id.fragment_book_view_flipper)).check(matches(isDisplayed())); - onNoteInBook(15, R.id.item_head_title_view) - .check(matches(allOf(withText("15"), isDisplayed()))); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onBook(0).perform(click()); + onView(withId(R.id.fragment_book_view_flipper)).check(matches(isDisplayed())); + onNoteInBook(15, R.id.item_head_title_view) + .check(matches(allOf(withText("15"), isDisplayed()))); + } } @Test @@ -136,41 +136,41 @@ public void testChangingNoteStatesToDone() { "*** DONE Note #5.\n" + "CLOSED: [2014-06-03 Tue 13:34]\n" + ""); - ActivityScenario.launch(MainActivity.class); - - onView(allOf(withText("book-name"), isDisplayed())).perform(click()); - - onNoteInBook(1, R.id.item_head_title_view).check(matches(allOf(withText("Note #1."), isDisplayed()))); - onNoteInBook(2, R.id.item_head_title_view).check(matches(allOf(withText("Note #2."), isDisplayed()))); - onNoteInBook(3, R.id.item_head_title_view).check(matches(allOf(withText("TODO Note #3."), isDisplayed()))); - onNoteInBook(4, R.id.item_head_title_view).check(matches(allOf(withText("Note #4."), isDisplayed()))); - onNoteInBook(5, R.id.item_head_title_view).check(matches(allOf(withText("DONE Note #5."), isDisplayed()))); - - onNoteInBook(1).perform(longClick()); - onNoteInBook(2).perform(click()); - onNoteInBook(3).perform(click()); - onView(withId(R.id.state)).perform(click()); - onView(withText("DONE")).perform(click()); - - onNoteInBook(1, R.id.item_head_title_view).check(matches(allOf(withText("DONE Note #1."), isDisplayed()))); - onNoteInBook(1, R.id.item_head_closed_text).check(matches(isDisplayed())); - onNoteInBook(1).check(matches(isHighlighted())); - - onNoteInBook(2, R.id.item_head_title_view).check(matches(allOf(withText("DONE Note #2."), isDisplayed()))); - onNoteInBook(2, R.id.item_head_closed_text).check(matches(isDisplayed())); - onNoteInBook(2).check(matches(isHighlighted())); - - onNoteInBook(3, R.id.item_head_title_view).check(matches(allOf(withText("DONE Note #3."), isDisplayed()))); - onNoteInBook(3, R.id.item_head_closed_text).check(matches(isDisplayed())); - onNoteInBook(3).check(matches(isHighlighted())); - - onNoteInBook(4, R.id.item_head_title_view).check(matches(allOf(withText("Note #4."), isDisplayed()))); - onNoteInBook(4, R.id.item_head_closed_text).check(matches(not(isDisplayed()))); - onNoteInBook(4).check(matches(not(isHighlighted()))); - - onNoteInBook(5, R.id.item_head_title_view).check(matches(allOf(withText("DONE Note #5."), isDisplayed()))); - onNoteInBook(5, R.id.item_head_closed_text).check(matches(isDisplayed())); - onNoteInBook(5).check(matches(not(isHighlighted()))); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onView(allOf(withText("book-name"), isDisplayed())).perform(click()); + + onNoteInBook(1, R.id.item_head_title_view).check(matches(allOf(withText("Note #1."), isDisplayed()))); + onNoteInBook(2, R.id.item_head_title_view).check(matches(allOf(withText("Note #2."), isDisplayed()))); + onNoteInBook(3, R.id.item_head_title_view).check(matches(allOf(withText("TODO Note #3."), isDisplayed()))); + onNoteInBook(4, R.id.item_head_title_view).check(matches(allOf(withText("Note #4."), isDisplayed()))); + onNoteInBook(5, R.id.item_head_title_view).check(matches(allOf(withText("DONE Note #5."), isDisplayed()))); + + onNoteInBook(1).perform(longClick()); + onNoteInBook(2).perform(click()); + onNoteInBook(3).perform(click()); + onView(withId(R.id.state)).perform(click()); + onView(withText("DONE")).perform(click()); + + onNoteInBook(1, R.id.item_head_title_view).check(matches(allOf(withText("DONE Note #1."), isDisplayed()))); + onNoteInBook(1, R.id.item_head_closed_text).check(matches(isDisplayed())); + onNoteInBook(1).check(matches(isHighlighted())); + + onNoteInBook(2, R.id.item_head_title_view).check(matches(allOf(withText("DONE Note #2."), isDisplayed()))); + onNoteInBook(2, R.id.item_head_closed_text).check(matches(isDisplayed())); + onNoteInBook(2).check(matches(isHighlighted())); + + onNoteInBook(3, R.id.item_head_title_view).check(matches(allOf(withText("DONE Note #3."), isDisplayed()))); + onNoteInBook(3, R.id.item_head_closed_text).check(matches(isDisplayed())); + onNoteInBook(3).check(matches(isHighlighted())); + + onNoteInBook(4, R.id.item_head_title_view).check(matches(allOf(withText("Note #4."), isDisplayed()))); + onNoteInBook(4, R.id.item_head_closed_text).check(matches(not(isDisplayed()))); + onNoteInBook(4).check(matches(not(isHighlighted()))); + + onNoteInBook(5, R.id.item_head_title_view).check(matches(allOf(withText("DONE Note #5."), isDisplayed()))); + onNoteInBook(5, R.id.item_head_closed_text).check(matches(isDisplayed())); + onNoteInBook(5).check(matches(not(isHighlighted()))); + } } @Test @@ -184,68 +184,69 @@ public void testSchedulingMultipleNotes() { "*** DONE Note #5.\n" + "CLOSED: [2014-06-03 Tue 13:34]\n" + ""); - ActivityScenario.launch(MainActivity.class); - - onView(allOf(withText("book-name"), isDisplayed())).perform(click()); - - onNoteInBook(1, R.id.item_head_scheduled_text).check(matches(not(isDisplayed()))); - onNoteInBook(2, R.id.item_head_scheduled_text).check(matches(not(isDisplayed()))); - onNoteInBook(3, R.id.item_head_scheduled_text).check(matches(not(isDisplayed()))); - onNoteInBook(4, R.id.item_head_scheduled_text).check(matches(not(isDisplayed()))); - onNoteInBook(5, R.id.item_head_scheduled_text).check(matches(not(isDisplayed()))); - - onNoteInBook(1).perform(longClick()); - onNoteInBook(2).perform(click()); - onNoteInBook(3).perform(click()); - onView(withId(R.id.schedule)).perform(click()); - onView(withId(R.id.date_picker_button)).perform(click()); - onView(withClassName(equalTo(DatePicker.class.getName()))).perform(setDate(2014, 4, 1)); - onView(withText(android.R.string.ok)).perform(click()); - onView(withId(R.id.time_picker_button)).perform(scroll(), click()); - onView(withClassName(equalTo(TimePicker.class.getName()))).perform(setTime(9, 15)); - onView(withText(android.R.string.ok)).perform(click()); - onView(withText(R.string.set)).perform(click()); - - onNoteInBook(1, R.id.item_head_scheduled_text).check(matches(allOf(isDisplayed(), withText(userDateTime("<2014-04-01 Tue 09:15>"))))); - onNoteInBook(2, R.id.item_head_scheduled_text).check(matches(allOf(isDisplayed(), withText(userDateTime("<2014-04-01 Tue 09:15>"))))); - onNoteInBook(3, R.id.item_head_scheduled_text).check(matches(allOf(isDisplayed(), withText(userDateTime("<2014-04-01 Tue 09:15>"))))); - onNoteInBook(4, R.id.item_head_scheduled_text).check(matches(not(isDisplayed()))); - onNoteInBook(5, R.id.item_head_scheduled_text).check(matches(not(isDisplayed()))); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onView(allOf(withText("book-name"), isDisplayed())).perform(click()); + + onNoteInBook(1, R.id.item_head_scheduled_text).check(matches(not(isDisplayed()))); + onNoteInBook(2, R.id.item_head_scheduled_text).check(matches(not(isDisplayed()))); + onNoteInBook(3, R.id.item_head_scheduled_text).check(matches(not(isDisplayed()))); + onNoteInBook(4, R.id.item_head_scheduled_text).check(matches(not(isDisplayed()))); + onNoteInBook(5, R.id.item_head_scheduled_text).check(matches(not(isDisplayed()))); + + onNoteInBook(1).perform(longClick()); + onNoteInBook(2).perform(click()); + onNoteInBook(3).perform(click()); + onView(withId(R.id.schedule)).perform(click()); + onView(withId(R.id.date_picker_button)).perform(click()); + onView(withClassName(equalTo(DatePicker.class.getName()))).perform(setDate(2014, 4, 1)); + onView(withText(android.R.string.ok)).perform(click()); + onView(withId(R.id.time_picker_button)).perform(scroll(), click()); + onView(withClassName(equalTo(TimePicker.class.getName()))).perform(setTime(9, 15)); + onView(withText(android.R.string.ok)).perform(click()); + onView(withText(R.string.set)).perform(click()); + + onNoteInBook(1, R.id.item_head_scheduled_text).check(matches(allOf(isDisplayed(), withText(userDateTime("<2014-04-01 Tue 09:15>"))))); + onNoteInBook(2, R.id.item_head_scheduled_text).check(matches(allOf(isDisplayed(), withText(userDateTime("<2014-04-01 Tue 09:15>"))))); + onNoteInBook(3, R.id.item_head_scheduled_text).check(matches(allOf(isDisplayed(), withText(userDateTime("<2014-04-01 Tue 09:15>"))))); + onNoteInBook(4, R.id.item_head_scheduled_text).check(matches(not(isDisplayed()))); + onNoteInBook(5, R.id.item_head_scheduled_text).check(matches(not(isDisplayed()))); + } } @Test public void testTrimmingTitleInNoteFragment() { testUtils.setupBook("book-one", "Sample book used for tests\n* 1\n* 2\n* 3\n"); - ActivityScenario.launch(MainActivity.class); - onBook(0).perform(click()); - onView(withId(R.id.fab)).perform(click()); - - onView(withId(R.id.title_edit)) - .perform(replaceTextCloseKeyboard(" Title with empty spaces all around ")); - onView(withId(R.id.done)).perform(click()); // Note done - onNoteInBook(4, R.id.item_head_title_view).check(matches(withText("Title with empty spaces all around"))); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onBook(0).perform(click()); + onView(withId(R.id.fab)).perform(click()); + + onView(withId(R.id.title_edit)) + .perform(replaceTextCloseKeyboard(" Title with empty spaces all around ")); + onView(withId(R.id.done)).perform(click()); // Note done + onNoteInBook(4, R.id.item_head_title_view).check(matches(withText("Title with empty spaces all around"))); + } } @Test public void testNewBookDialogShouldSurviveScreenRotation() { - ActivityScenario scenario = ActivityScenario.launch(MainActivity.class); + try (ActivityScenario scenario = ActivityScenario.launch(MainActivity.class)) { + scenario.onActivity(activity -> + activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)); - scenario.onActivity(activity -> - activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)); + onView(withId(R.id.fab)).perform(click()); + onView(withId(R.id.dialog_new_book_container)).check(matches(isDisplayed())); - onView(withId(R.id.fab)).perform(click()); - onView(withId(R.id.dialog_new_book_container)).check(matches(isDisplayed())); + scenario.onActivity(activity -> + activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)); - scenario.onActivity(activity -> - activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)); + onView(withId(R.id.dialog_new_book_container)).check(matches(isDisplayed())); + onView(withId(R.id.dialog_input)).perform(replaceTextCloseKeyboard("notebook")); + onView(withText(R.string.create)).perform(click()); - onView(withId(R.id.dialog_new_book_container)).check(matches(isDisplayed())); - onView(withId(R.id.dialog_input)).perform(replaceTextCloseKeyboard("notebook")); - onView(withText(R.string.create)).perform(click()); + onView(allOf(withText("notebook"), isDisplayed())).perform(click()); - onView(allOf(withText("notebook"), isDisplayed())).perform(click()); - - onView(withId(R.id.fragment_book_view_flipper)).check(matches(isDisplayed())); + onView(withId(R.id.fragment_book_view_flipper)).check(matches(isDisplayed())); + } } /** @@ -255,11 +256,11 @@ public void testNewBookDialogShouldSurviveScreenRotation() { @Test public void testBookTitleMustBeDisplayedWhenOpeningBookFromDrawer() { testUtils.setupBook("book-one", "Sample book used for tests\n* 1\n* 2\n* 3\n"); - ActivityScenario.launch(MainActivity.class); - - onView(withId(R.id.drawer_layout)).perform(open()); - onView(allOf(withText("book-one"), isDescendantOfA(withId(R.id.drawer_navigation_view)))).perform(click()); - onView(allOf(withText("book-one"), isDescendantOfA(withId(R.id.top_toolbar)))).check(matches(isDisplayed())); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onView(withId(R.id.drawer_layout)).perform(open()); + onView(allOf(withText("book-one"), isDescendantOfA(withId(R.id.drawer_navigation_view)))).perform(click()); + onView(allOf(withText("book-one"), isDescendantOfA(withId(R.id.top_toolbar)))).check(matches(isDisplayed())); + } } @Test @@ -269,21 +270,21 @@ public void testTimestampDialogTimeButtonValueWhenToggling() { "SCHEDULED: <2015-01-18 04:05 +6d>\n" + "* Note #2.\n" + ""); - ActivityScenario.launch(MainActivity.class); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onBook(0).perform(click()); - onBook(0).perform(click()); + onNoteInBook(1).perform(click()); - onNoteInBook(1).perform(click()); + Calendar cal = new GregorianCalendar(2015, 0, 18, 4, 5); + String s = DateFormat.getTimeFormat(context).format(cal.getTime()); - Calendar cal = new GregorianCalendar(2015, 0, 18, 4, 5); - String s = DateFormat.getTimeFormat(context).format(cal.getTime()); - - onView(withId(R.id.scheduled_button)).perform(click()); - onView(withId(R.id.time_picker_button)).check(matches(withText(containsString(s)))); - onView(withId(R.id.time_used_checkbox)).perform(scroll(), click()); - onView(withId(R.id.time_picker_button)).check(matches(withText(containsString(s)))); - onView(withId(R.id.time_used_checkbox)).perform(click()); - onView(withId(R.id.time_picker_button)).check(matches(withText(containsString(s)))); + onView(withId(R.id.scheduled_button)).perform(click()); + onView(withId(R.id.time_picker_button)).check(matches(withText(containsString(s)))); + onView(withId(R.id.time_used_checkbox)).perform(scroll(), click()); + onView(withId(R.id.time_picker_button)).check(matches(withText(containsString(s)))); + onView(withId(R.id.time_used_checkbox)).perform(click()); + onView(withId(R.id.time_picker_button)).check(matches(withText(containsString(s)))); + } } @Test @@ -294,11 +295,11 @@ public void testTimestampComplicated() { "SCHEDULED: <2015-01-18 04:05 .+6d>\n" + "* Note #2.\n" + ""); - ActivityScenario.launch(MainActivity.class); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onView(allOf(withText("book-name"), isDisplayed())).perform(click()); - onView(allOf(withText("book-name"), isDisplayed())).perform(click()); - - onNoteInBook(1, R.id.item_head_scheduled_text).check(matches(allOf(isDisplayed(), withText(userDateTime("<2015-01-18 Sun 04:05 .+6d>"))))); + onNoteInBook(1, R.id.item_head_scheduled_text).check(matches(allOf(isDisplayed(), withText(userDateTime("<2015-01-18 Sun 04:05 .+6d>"))))); + } } @Test @@ -308,41 +309,41 @@ public void testScheduledWithRepeaterToDoneFromBook() { "SCHEDULED: <2015-01-18 04:05 +6d>\n" + "* Note #2.\n" + ""); - ActivityScenario.launch(MainActivity.class); - - settingsSetDoneKeywords("DONE OLD"); - - onBook(0).perform(click()); - - onNoteInBook(1).perform(longClick()); - - /* TO DO -> DONE */ - onView(withId(R.id.state)).perform(click()); - onView(withText("DONE")).perform(click()); - onNoteInBook(1, R.id.item_head_title_view).check(matches(withText(startsWith("TODO")))); - onNoteInBook(1, R.id.item_head_closed_text).check(matches(not(isDisplayed()))); - onNoteInBook(1, R.id.item_head_scheduled_text).check(matches(withText(userDateTime("<2015-01-24 Sat 04:05 +6d>")))); - - /* DONE -> NOTE */ - onView(withId(R.id.state)).perform(click()); - onView(withText(R.string.clear)).perform(click()); - onNoteInBook(1, R.id.item_head_title_view).check(matches(withText(startsWith("Note")))); - onNoteInBook(1, R.id.item_head_closed_text).check(matches(not(isDisplayed()))); - onNoteInBook(1, R.id.item_head_scheduled_text).check(matches(withText(userDateTime("<2015-01-24 Sat 04:05 +6d>")))); - - /* NOTE -> DONE */ - onView(withId(R.id.state)).perform(click()); - onView(withText("DONE")).perform(click()); - onNoteInBook(1, R.id.item_head_title_view).check(matches(withText(startsWith("Note")))); - onNoteInBook(1, R.id.item_head_closed_text).check(matches(not(isDisplayed()))); - onNoteInBook(1, R.id.item_head_scheduled_text).check(matches(withText(userDateTime("<2015-01-30 Fri 04:05 +6d>")))); - - /* NOTE -> OLD */ - onView(withId(R.id.state)).perform(click()); - onView(withText("OLD")).perform(click()); - onNoteInBook(1, R.id.item_head_title_view).check(matches(withText(startsWith("Note")))); - onNoteInBook(1, R.id.item_head_closed_text).check(matches(not(isDisplayed()))); - onNoteInBook(1, R.id.item_head_scheduled_text).check(matches(withText(userDateTime("<2015-02-05 Thu 04:05 +6d>")))); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + settingsSetDoneKeywords("DONE OLD"); + + onBook(0).perform(click()); + + onNoteInBook(1).perform(longClick()); + + /* TO DO -> DONE */ + onView(withId(R.id.state)).perform(click()); + onView(withText("DONE")).perform(click()); + onNoteInBook(1, R.id.item_head_title_view).check(matches(withText(startsWith("TODO")))); + onNoteInBook(1, R.id.item_head_closed_text).check(matches(not(isDisplayed()))); + onNoteInBook(1, R.id.item_head_scheduled_text).check(matches(withText(userDateTime("<2015-01-24 Sat 04:05 +6d>")))); + + /* DONE -> NOTE */ + onView(withId(R.id.state)).perform(click()); + onView(withText(R.string.clear)).perform(click()); + onNoteInBook(1, R.id.item_head_title_view).check(matches(withText(startsWith("Note")))); + onNoteInBook(1, R.id.item_head_closed_text).check(matches(not(isDisplayed()))); + onNoteInBook(1, R.id.item_head_scheduled_text).check(matches(withText(userDateTime("<2015-01-24 Sat 04:05 +6d>")))); + + /* NOTE -> DONE */ + onView(withId(R.id.state)).perform(click()); + onView(withText("DONE")).perform(click()); + onNoteInBook(1, R.id.item_head_title_view).check(matches(withText(startsWith("Note")))); + onNoteInBook(1, R.id.item_head_closed_text).check(matches(not(isDisplayed()))); + onNoteInBook(1, R.id.item_head_scheduled_text).check(matches(withText(userDateTime("<2015-01-30 Fri 04:05 +6d>")))); + + /* NOTE -> OLD */ + onView(withId(R.id.state)).perform(click()); + onView(withText("OLD")).perform(click()); + onNoteInBook(1, R.id.item_head_title_view).check(matches(withText(startsWith("Note")))); + onNoteInBook(1, R.id.item_head_closed_text).check(matches(not(isDisplayed()))); + onNoteInBook(1, R.id.item_head_scheduled_text).check(matches(withText(userDateTime("<2015-02-05 Thu 04:05 +6d>")))); + } } @Test @@ -353,64 +354,64 @@ public void testScheduledWithRepeaterToDoneFromNoteFragment() { "SCHEDULED: <2015-01-18 04:05 +6d>\n" + "* Note #2.\n" + ""); - ActivityScenario.launch(MainActivity.class); - - settingsSetDoneKeywords("DONE OLD"); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + settingsSetDoneKeywords("DONE OLD"); - onView(allOf(withText("book-name"), isDisplayed())).perform(click()); + onView(allOf(withText("book-name"), isDisplayed())).perform(click()); - onNoteInBook(1).perform(click()); + onNoteInBook(1).perform(click()); - /* TO DO -> DONE */ - onView(withId(R.id.state_button)).perform(click()); - onView(withText("DONE")).perform(click()); + /* TO DO -> DONE */ + onView(withId(R.id.state_button)).perform(click()); + onView(withText("DONE")).perform(click()); - onView(withId(R.id.closed_button)).check(matches(not(isDisplayed()))); - onView(withId(R.id.scheduled_button)).check(matches(withText(userDateTime("<2015-01-24 Sat 04:05 +6d>")))); + onView(withId(R.id.closed_button)).check(matches(not(isDisplayed()))); + onView(withId(R.id.scheduled_button)).check(matches(withText(userDateTime("<2015-01-24 Sat 04:05 +6d>")))); - /* DONE -> NOTE */ - onView(withId(R.id.state_button)).perform(click()); - onView(withText(R.string.clear)).perform(click()); - onView(withId(R.id.closed_button)).check(matches(not(isDisplayed()))); - onView(withId(R.id.scheduled_button)).check(matches(withText(userDateTime("<2015-01-24 Sat 04:05 +6d>")))); + /* DONE -> NOTE */ + onView(withId(R.id.state_button)).perform(click()); + onView(withText(R.string.clear)).perform(click()); + onView(withId(R.id.closed_button)).check(matches(not(isDisplayed()))); + onView(withId(R.id.scheduled_button)).check(matches(withText(userDateTime("<2015-01-24 Sat 04:05 +6d>")))); - /* NOTE -> DONE */ - onView(withId(R.id.state_button)).perform(click()); - onView(withText("DONE")).perform(click()); - onView(withId(R.id.closed_button)).check(matches(not(isDisplayed()))); - onView(withId(R.id.scheduled_button)).check(matches(withText(userDateTime("<2015-01-30 Fri 04:05 +6d>")))); + /* NOTE -> DONE */ + onView(withId(R.id.state_button)).perform(click()); + onView(withText("DONE")).perform(click()); + onView(withId(R.id.closed_button)).check(matches(not(isDisplayed()))); + onView(withId(R.id.scheduled_button)).check(matches(withText(userDateTime("<2015-01-30 Fri 04:05 +6d>")))); - /* NOTE -> OLD */ - onView(withId(R.id.state_button)).perform(click()); - onView(withText("OLD")).perform(click()); - onView(withId(R.id.closed_button)).check(matches(not(isDisplayed()))); - onView(withId(R.id.scheduled_button)).check(matches(withText(userDateTime("<2015-02-05 Thu 04:05 +6d>")))); + /* NOTE -> OLD */ + onView(withId(R.id.state_button)).perform(click()); + onView(withText("OLD")).perform(click()); + onView(withId(R.id.closed_button)).check(matches(not(isDisplayed()))); + onView(withId(R.id.scheduled_button)).check(matches(withText(userDateTime("<2015-02-05 Thu 04:05 +6d>")))); + } } @Test public void testSettingStateToTodo() { testUtils.setupBook("booky", "* TODO Note 1\n* Note 2\n* Note 3\n* Note 4\n* TODO Note 5"); - ActivityScenario.launch(MainActivity.class); - - onView(allOf(withText("booky"), isDisplayed())).perform(click()); - - onNoteInBook(1, R.id.item_head_title_view).check(matches(allOf(withText("TODO Note 1"), isDisplayed()))); - onNoteInBook(2, R.id.item_head_title_view).check(matches(allOf(withText("Note 2"), isDisplayed()))); - onNoteInBook(3, R.id.item_head_title_view).check(matches(allOf(withText("Note 3"), isDisplayed()))); - onNoteInBook(4, R.id.item_head_title_view).check(matches(allOf(withText("Note 4"), isDisplayed()))); - onNoteInBook(5, R.id.item_head_title_view).check(matches(allOf(withText("TODO Note 5"), isDisplayed()))); - - onNoteInBook(1).perform(longClick()); - onNoteInBook(2).perform(click()); - onNoteInBook(3).perform(click()); - onView(withId(R.id.state)).perform(click()); - onView(withText("TODO")).perform(click()); - - onNoteInBook(1, R.id.item_head_title_view).check(matches(allOf(withText("TODO Note 1"), isDisplayed()))); - onNoteInBook(2, R.id.item_head_title_view).check(matches(allOf(withText("TODO Note 2"), isDisplayed()))); - onNoteInBook(3, R.id.item_head_title_view).check(matches(allOf(withText("TODO Note 3"), isDisplayed()))); - onNoteInBook(4, R.id.item_head_title_view).check(matches(allOf(withText("Note 4"), isDisplayed()))); - onNoteInBook(5, R.id.item_head_title_view).check(matches(allOf(withText("TODO Note 5"), isDisplayed()))); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onView(allOf(withText("booky"), isDisplayed())).perform(click()); + + onNoteInBook(1, R.id.item_head_title_view).check(matches(allOf(withText("TODO Note 1"), isDisplayed()))); + onNoteInBook(2, R.id.item_head_title_view).check(matches(allOf(withText("Note 2"), isDisplayed()))); + onNoteInBook(3, R.id.item_head_title_view).check(matches(allOf(withText("Note 3"), isDisplayed()))); + onNoteInBook(4, R.id.item_head_title_view).check(matches(allOf(withText("Note 4"), isDisplayed()))); + onNoteInBook(5, R.id.item_head_title_view).check(matches(allOf(withText("TODO Note 5"), isDisplayed()))); + + onNoteInBook(1).perform(longClick()); + onNoteInBook(2).perform(click()); + onNoteInBook(3).perform(click()); + onView(withId(R.id.state)).perform(click()); + onView(withText("TODO")).perform(click()); + + onNoteInBook(1, R.id.item_head_title_view).check(matches(allOf(withText("TODO Note 1"), isDisplayed()))); + onNoteInBook(2, R.id.item_head_title_view).check(matches(allOf(withText("TODO Note 2"), isDisplayed()))); + onNoteInBook(3, R.id.item_head_title_view).check(matches(allOf(withText("TODO Note 3"), isDisplayed()))); + onNoteInBook(4, R.id.item_head_title_view).check(matches(allOf(withText("Note 4"), isDisplayed()))); + onNoteInBook(5, R.id.item_head_title_view).check(matches(allOf(withText("TODO Note 5"), isDisplayed()))); + } } /** @@ -424,49 +425,49 @@ public void testMainActivityFragments() { testUtils.setupRepo(RepoType.DROPBOX, "dropbox:/orgzly"); testUtils.setupBook("book-one", "Preface\n\n* Note"); - ActivityScenario scenario = ActivityScenario.launch(MainActivity.class); - - scenario.onActivity(it -> activity = it); + try (ActivityScenario scenario = ActivityScenario.launch(MainActivity.class)) { + scenario.onActivity(it -> activity = it); - // Books - // fragmentTest(activity, true, withId(R.id.fragment_books_view_flipper)); + // Books + // fragmentTest(activity, true, withId(R.id.fragment_books_view_flipper)); - // Book - onBook(0).perform(click()); - fragmentTest(activity, true, withId(R.id.fragment_book_view_flipper)); + // Book + onBook(0).perform(click()); + fragmentTest(activity, true, withId(R.id.fragment_book_view_flipper)); - // Note - onView(withText("Note")).perform(click()); - fragmentTest(activity, false, withId(R.id.scroll_view)); - pressBack(); + // Note + onView(withText("Note")).perform(click()); + fragmentTest(activity, false, withId(R.id.scroll_view)); + pressBack(); - // Preface - onPreface().perform(click()); - fragmentTest(activity, false, withId(R.id.fragment_book_preface_container)); - pressBack(); - pressBack(); + // Preface + onPreface().perform(click()); + fragmentTest(activity, false, withId(R.id.fragment_book_preface_container)); + pressBack(); + pressBack(); - // Opened drawer - onView(withId(R.id.drawer_layout)).perform(open()); - fragmentTest(activity, true, withText(R.string.searches)); + // Opened drawer + onView(withId(R.id.drawer_layout)).perform(open()); + fragmentTest(activity, true, withText(R.string.searches)); - // Saved searches - onView(withId(R.id.drawer_layout)).perform(open()); - onView(withText(R.string.searches)).perform(click()); - fragmentTest(activity, true, withId(R.id.fragment_saved_searches_flipper)); + // Saved searches + onView(withId(R.id.drawer_layout)).perform(open()); + onView(withText(R.string.searches)).perform(click()); + fragmentTest(activity, true, withId(R.id.fragment_saved_searches_flipper)); - // Search - onSavedSearch(0).perform(click()); - fragmentTest(activity, false, withId(R.id.fragment_saved_search_flipper)); + // Search + onSavedSearch(0).perform(click()); + fragmentTest(activity, false, withId(R.id.fragment_saved_search_flipper)); - // Search results - onView(withId(R.id.drawer_layout)).perform(open()); - onView(withText("Scheduled")).perform(click()); - fragmentTest(activity, true, withId(R.id.fragment_query_search_view_flipper)); + // Search results + onView(withId(R.id.drawer_layout)).perform(open()); + onView(withText("Scheduled")).perform(click()); + fragmentTest(activity, true, withId(R.id.fragment_query_search_view_flipper)); - // Agenda - searchForText("t.tag3 ad.3"); - fragmentTest(activity, true, withId(R.id.fragment_query_agenda_view_flipper)); + // Agenda + searchForText("t.tag3 ad.3"); + fragmentTest(activity, true, withId(R.id.fragment_query_agenda_view_flipper)); + } } @Test @@ -477,21 +478,21 @@ public void testReposActivityFragments() { testUtils.setupRepo(RepoType.DROPBOX, "dropbox:/orgzly"); testUtils.setupBook("book-one", "Preface\n\n* Note"); - ActivityScenario scenario = ActivityScenario.launch(ReposActivity.class); - - scenario.onActivity(it -> activity = it); + try (ActivityScenario scenario = ActivityScenario.launch(ReposActivity.class)) { + scenario.onActivity(it -> activity = it); - // List of repos - fragmentTest(activity, false, withId(R.id.activity_repos_flipper)); + // List of repos + fragmentTest(activity, false, withId(R.id.activity_repos_flipper)); - // Directory repo - onListItem(1).perform(click()); - fragmentTest(activity, false, withId(R.id.activity_repo_directory_container)); - pressBack(); + // Directory repo + onListItem(1).perform(click()); + fragmentTest(activity, false, withId(R.id.activity_repo_directory_container)); + pressBack(); - // Dropbox repo - onListItem(0).perform(click()); - fragmentTest(activity, false, withId(R.id.activity_repo_dropbox_container)); + // Dropbox repo + onListItem(0).perform(click()); + fragmentTest(activity, false, withId(R.id.activity_repo_dropbox_container)); + } } private void fragmentTest(Activity activity, boolean hasSearchMenuItem, Matcher matcher) { @@ -522,65 +523,66 @@ private void fragmentTest(Activity activity, boolean hasSearchMenuItem, Matcher< @Test public void testBookTitleFromInBufferSettingsDisplayed() { testUtils.setupBook("book-name", "#+TITLE: Notebook Title\n* TODO Note #1.\n"); - ActivityScenario.launch(MainActivity.class); - - /* Books fragment. */ - onBook(0, R.id.item_book_title).check(matches(withText("Notebook Title"))); - onBook(0, R.id.item_book_subtitle).check(matches(withText("book-name"))); - - /* Books in drawer. */ - onView(withId(R.id.drawer_layout)).perform(open()); - onView(allOf(withText("Notebook Title"), isDescendantOfA(withId(R.id.drawer_navigation_view)))).check(matches(isDisplayed())); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + /* Books fragment. */ + onBook(0, R.id.item_book_title).check(matches(withText("Notebook Title"))); + onBook(0, R.id.item_book_subtitle).check(matches(withText("book-name"))); + + /* Books in drawer. */ + onView(withId(R.id.drawer_layout)).perform(open()); + onView(allOf(withText("Notebook Title"), isDescendantOfA(withId(R.id.drawer_navigation_view)))).check(matches(isDisplayed())); + } } @Test public void testBookTitleSettingIsPartOfPreface() { testUtils.setupBook("book-name", "#+TITLE: Notebook Title\n* TODO Note #1.\n"); - ActivityScenario.launch(MainActivity.class); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onView(allOf(withText("Notebook Title"), isDisplayed())).perform(click()); + onNoteInBook(0, R.id.item_preface_text_view) + .check(matches(withText(containsString("#+TITLE: Notebook Title")))); - onView(allOf(withText("Notebook Title"), isDisplayed())).perform(click()); - onNoteInBook(0, R.id.item_preface_text_view) - .check(matches(withText(containsString("#+TITLE: Notebook Title")))); + } } @Test public void testBookTitleChangeOnPrefaceEdit() { testUtils.setupBook("book-name", "* TODO Note #1.\n"); - ActivityScenario.launch(MainActivity.class); - - onBook(0, R.id.item_book_title).check(matches(withText("book-name"))); - - /* Set #+TITLE */ - onView(allOf(withText("book-name"), isDisplayed())).perform(click()); - onActionItemClick(R.id.books_options_menu_book_preface, R.string.edit_book_preface); - onView(withId(R.id.fragment_book_preface_content)).perform(click()); - onView(withId(R.id.fragment_book_preface_content_edit)) - .perform(replaceTextCloseKeyboard("#+TITLE: Notebook Title")); - onView(withId(R.id.done)).perform(click()); // Preface done - pressBack(); - - onBook(0, R.id.item_book_title).check(matches(withText("Notebook Title"))); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onBook(0, R.id.item_book_title).check(matches(withText("book-name"))); + + /* Set #+TITLE */ + onView(allOf(withText("book-name"), isDisplayed())).perform(click()); + onActionItemClick(R.id.books_options_menu_book_preface, R.string.edit_book_preface); + onView(withId(R.id.fragment_book_preface_content)).perform(click()); + onView(withId(R.id.fragment_book_preface_content_edit)) + .perform(replaceTextCloseKeyboard("#+TITLE: Notebook Title")); + onView(withId(R.id.done)).perform(click()); // Preface done + pressBack(); + + onBook(0, R.id.item_book_title).check(matches(withText("Notebook Title"))); + } } @Test public void testBookTitleRemoving() { testUtils.setupBook("book-name", "#+TITLE: Notebook Title\n* TODO Note #1.\n"); - ActivityScenario.launch(MainActivity.class); - - onBook(0, R.id.item_book_title).check(matches(withText("Notebook Title"))); - onBook(0, R.id.item_book_subtitle).check(matches(withText("book-name"))); - - onBook(0).perform(click()); - onPreface().perform(click()); - onView(withId(R.id.fragment_book_preface_content)).perform(click()); - onView(withId(R.id.fragment_book_preface_content_edit)).perform(replaceTextCloseKeyboard("#+TTL: Notebook Title")); - onView(withId(R.id.done)).perform(click()); // Preface done - onNoteInBook(0, R.id.item_preface_text_view) - .check(matches(withText(containsString("#+TTL: Notebook Title")))); - pressBack(); - - onBook(0, R.id.item_book_title).check(matches(withText("book-name"))); - onBook(0, R.id.item_book_subtitle).check(matches(not(isDisplayed()))); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onBook(0, R.id.item_book_title).check(matches(withText("Notebook Title"))); + onBook(0, R.id.item_book_subtitle).check(matches(withText("book-name"))); + + onBook(0).perform(click()); + onPreface().perform(click()); + onView(withId(R.id.fragment_book_preface_content)).perform(click()); + onView(withId(R.id.fragment_book_preface_content_edit)).perform(replaceTextCloseKeyboard("#+TTL: Notebook Title")); + onView(withId(R.id.done)).perform(click()); // Preface done + onNoteInBook(0, R.id.item_preface_text_view) + .check(matches(withText(containsString("#+TTL: Notebook Title")))); + pressBack(); + + onBook(0, R.id.item_book_title).check(matches(withText("book-name"))); + onBook(0, R.id.item_book_subtitle).check(matches(not(isDisplayed()))); + } } @Test @@ -600,137 +602,137 @@ public void testBookReparseOnStateConfigChange() { "**** Note #9.\n" + "** Note #10.\n" + ""); - ActivityScenario.launch(MainActivity.class); - - onBook(0).perform(click()); - onNoteInBook(8, R.id.item_head_title_view) - .check(matches(withText(startsWith("ANTIVIVISECTIONISTS ")))) - .perform(click()); - onView(withId(R.id.title_view)).check(matches(withText("ANTIVIVISECTIONISTS Note #8."))); - settingsSetTodoKeywords("TODO ANTIVIVISECTIONISTS"); - /* Must go to books and back, or the click below will not work for some reason. */ - pressBack(); // Leave book - onView(allOf(withText("book-name"), isDisplayed())).perform(click()); - onNoteInBook(8).perform(click()); - onView(withId(R.id.title_view)).check(matches(withText("Note #8."))); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onBook(0).perform(click()); + onNoteInBook(8, R.id.item_head_title_view) + .check(matches(withText(startsWith("ANTIVIVISECTIONISTS ")))) + .perform(click()); + onView(withId(R.id.title_view)).check(matches(withText("ANTIVIVISECTIONISTS Note #8."))); + settingsSetTodoKeywords("TODO ANTIVIVISECTIONISTS"); + /* Must go to books and back, or the click below will not work for some reason. */ + pressBack(); // Leave book + onView(allOf(withText("book-name"), isDisplayed())).perform(click()); + onNoteInBook(8).perform(click()); + onView(withId(R.id.title_view)).check(matches(withText("Note #8."))); + } } @Test public void testCabStaysOpenWhenSelectingTheSameBookFromDrawer() { testUtils.setupBook("booky", "* TODO Note 1\n* Note 2\n* Note 3\n* Note 4\n* TODO Note 5"); - ActivityScenario.launch(MainActivity.class); - - onBook(0).perform(click()); - onNoteInBook(3).perform(longClick()); - onActionItemClick(R.id.move, R.string.move); - onView(withId(R.id.drawer_layout)).perform(open()); - onView(allOf(withText("booky"), isDescendantOfA(withId(R.id.drawer_navigation_view)))).perform(click()); - onView(withId(R.id.notes_action_move_left)).check(matches(isDisplayed())); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onBook(0).perform(click()); + onNoteInBook(3).perform(longClick()); + onActionItemClick(R.id.move, R.string.move); + onView(withId(R.id.drawer_layout)).perform(open()); + onView(allOf(withText("booky"), isDescendantOfA(withId(R.id.drawer_navigation_view)))).perform(click()); + onView(withId(R.id.notes_action_move_left)).check(matches(isDisplayed())); + } } @Test public void testNewlyCreatedBookShouldNotHaveEncodingsDisplayed() { - ActivityScenario.launch(MainActivity.class); - - onView(withId(R.id.fab)).perform(click()); - onView(withId(R.id.dialog_input)).perform(replaceTextCloseKeyboard("booky")); - onView(withText(R.string.create)).perform(click()); - onBook(0, R.id.item_book_encoding_used_container).check(matches(not(isDisplayed()))); - onBook(0, R.id.item_book_encoding_detected_container).check(matches(not(isDisplayed()))); - onBook(0, R.id.item_book_encoding_selected_container).check(matches(not(isDisplayed()))); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onView(withId(R.id.fab)).perform(click()); + onView(withId(R.id.dialog_input)).perform(replaceTextCloseKeyboard("booky")); + onView(withText(R.string.create)).perform(click()); + onBook(0, R.id.item_book_encoding_used_container).check(matches(not(isDisplayed()))); + onBook(0, R.id.item_book_encoding_detected_container).check(matches(not(isDisplayed()))); + onBook(0, R.id.item_book_encoding_selected_container).check(matches(not(isDisplayed()))); + } } @Test public void testSelectingNoteThenOpeningAnotherBook() { testUtils.setupBook("booky-one", "* TODO Note 1\n* Note 2\n* Note 3\n* Note 4\n* TODO Note 5"); testUtils.setupBook("booky-two", "* TODO Note A\n* Note B\n* Note C"); - ActivityScenario.launch(MainActivity.class); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onBook(0).perform(click()); + onNoteInBook(1).perform(longClick()); - onBook(0).perform(click()); - onNoteInBook(1).perform(longClick()); + onView(withId(R.id.toggle_state)).check(matches(isDisplayed())); - onView(withId(R.id.toggle_state)).check(matches(isDisplayed())); + onView(withId(R.id.drawer_layout)).perform(open()); + onView(allOf(withText("booky-two"), isDescendantOfA(withId(R.id.drawer_navigation_view)))).perform(click()); + onView(withId(R.id.fragment_book_view_flipper)).check(matches(isDisplayed())); - onView(withId(R.id.drawer_layout)).perform(open()); - onView(allOf(withText("booky-two"), isDescendantOfA(withId(R.id.drawer_navigation_view)))).perform(click()); - onView(withId(R.id.fragment_book_view_flipper)).check(matches(isDisplayed())); - - onView(withId(R.id.toggle_state)).check(doesNotExist()); + onView(withId(R.id.toggle_state)).check(doesNotExist()); + } } @Test public void testOpenBookAlreadyInBackStack() { testUtils.setupBook("booky-one", "* TODO Note 1\n* Note 2\n* Note 3\n* Note 4\n* TODO Note 5"); testUtils.setupBook("booky-two", "* TODO Note A\n* Note B\n* Note C"); - ActivityScenario.launch(MainActivity.class); - - onBook(0).perform(click()); - onView(withId(R.id.fragment_book_view_flipper)).check(matches(isDisplayed())); - onNoteInBook(1).perform(click()); - onView(withId(R.id.scroll_view)).check(matches(isDisplayed())); - onView(withId(R.id.drawer_layout)).perform(open()); - onView(allOf(withText("booky-one"), isDescendantOfA(withId(R.id.drawer_navigation_view)))).perform(click()); - onView(withId(R.id.fragment_book_view_flipper)).check(matches(isDisplayed())); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onBook(0).perform(click()); + onView(withId(R.id.fragment_book_view_flipper)).check(matches(isDisplayed())); + onNoteInBook(1).perform(click()); + onView(withId(R.id.scroll_view)).check(matches(isDisplayed())); + onView(withId(R.id.drawer_layout)).perform(open()); + onView(allOf(withText("booky-one"), isDescendantOfA(withId(R.id.drawer_navigation_view)))).perform(click()); + onView(withId(R.id.fragment_book_view_flipper)).check(matches(isDisplayed())); + } } @Test(expected = IllegalStateException.class) public void testCheckboxInTitle() { testUtils.setupBook("book-name", "* - [ ] Checkbox"); - ActivityScenario.launch(MainActivity.class); - - onBook(0).perform(click()); - onNoteInBook(1, R.id.item_head_title_view).perform(clickClickableSpan("[ ]")); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onBook(0).perform(click()); + onNoteInBook(1, R.id.item_head_title_view).perform(clickClickableSpan("[ ]")); + } } @Test public void testCheckboxWithFoldedDrawerBeforeIt() { testUtils.setupBook("book-name", ":DRAWER:\ndrawer\n:END:\n\n- [ ] Item"); - ActivityScenario.launch(MainActivity.class); - - onBook(0).perform(click()); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onBook(0).perform(click()); - onView(withId(R.id.item_preface_text_view)).perform(clickClickableSpan("[ ]")); + onView(withId(R.id.item_preface_text_view)).perform(clickClickableSpan("[ ]")); - onView(allOf(withId(R.id.item_preface_text_view), withText(containsString("- [X] Item")))) - .check(matches(isDisplayed())); + onView(allOf(withId(R.id.item_preface_text_view), withText(containsString("- [X] Item")))) + .check(matches(isDisplayed())); + } } @Test public void testClickingCheckboxInNoteDetails() { testUtils.setupBook("book-name", "* Title\n\n- [ ] Item"); - ActivityScenario.launch(MainActivity.class); - - onBook(0).perform(click()); - onNoteInBook(1).perform(click()); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onBook(0).perform(click()); + onNoteInBook(1).perform(click()); - onView(withId(R.id.content_view)).perform(clickClickableSpan("[ ]")); + onView(withId(R.id.content_view)).perform(clickClickableSpan("[ ]")); - onView(allOf(withId(R.id.content_view), withText(containsString("- [X] Item")))) - .check(matches(isDisplayed())); + onView(allOf(withId(R.id.content_view), withText(containsString("- [X] Item")))) + .check(matches(isDisplayed())); + } } @Test public void testDrawerWithFoldedDrawerBeforeIt() { testUtils.setupBook("book-name", ":DRAWER1:\ndrawer1\n:END:\n\n:DRAWER2:\ndrawer2\n:END:"); - ActivityScenario.launch(MainActivity.class); - - onBook(0).perform(click()); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onBook(0).perform(click()); - onView(withId(R.id.item_preface_text_view)).perform(clickClickableSpan("DRAWER2")); - onView(withId(R.id.item_preface_text_view)).perform(clickClickableSpan("DRAWER1")); + onView(withId(R.id.item_preface_text_view)).perform(clickClickableSpan("DRAWER2")); + onView(withId(R.id.item_preface_text_view)).perform(clickClickableSpan("DRAWER1")); + } } @Test public void testActiveDrawerItemForSearchQuery() { testUtils.setupBook("booky-one", "* TODO Note 1\n* Note 2\n* Note 3\n* Note 4\n* TODO Note 5"); - ActivityScenario.launch(MainActivity.class); - - onBook(0).perform(click()); + try (ActivityScenario ignored = ActivityScenario.launch(MainActivity.class)) { + onBook(0).perform(click()); - searchForText("note"); + searchForText("note"); - onView(withId(R.id.drawer_layout)).perform(open()); - onView(allOf(withText("booky-one"), isDescendantOfA(withId(R.id.drawer_navigation_view)))) - .check(matches(not(isChecked()))); + onView(withId(R.id.drawer_layout)).perform(open()); + onView(allOf(withText("booky-one"), isDescendantOfA(withId(R.id.drawer_navigation_view)))) + .check(matches(not(isChecked()))); + } } }