Merge pull request #3656 from ByteHamster/fix-tests3

More test fixes
This commit is contained in:
H. Lehmann 2019-11-28 22:59:54 +01:00 committed by GitHub
commit 90f578aa48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 22 deletions

View File

@ -38,12 +38,12 @@ import static de.test.antennapod.NthMatcher.nth;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
* test cases for starting and ending playback from the MainActivity and AudioPlayerActivity
* Test cases for starting and ending playback from the MainActivity and AudioPlayerActivity.
*/
public abstract class PlaybackTest {
@ -317,10 +317,7 @@ public abstract class PlaybackTest {
// assert item no longer in queue (needs to wait till skip is asynchronously processed)
Awaitility.await()
.atMost(1000, MILLISECONDS)
.untilAsserted(() -> {
assertThat("Ensure smart mark as play will lead to the item removed from the queue",
DBReader.getQueue(), not(hasItems(feedItem)));
});
assertThat(DBReader.getFeedItem(feedItem.getId()).isPlayed(), is(true));
.until(() -> !DBReader.getQueue().contains(feedItem));
assertTrue(DBReader.getFeedItem(feedItem.getId()).isPlayed());
}
}

View File

@ -2,11 +2,9 @@ package de.test.antennapod.ui;
import android.content.Intent;
import androidx.test.InstrumentationRegistry;
import androidx.test.espresso.ViewInteraction;
import androidx.test.espresso.contrib.DrawerActions;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.runner.AndroidJUnit4;
import android.view.View;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.activity.PreferenceActivity;
@ -17,7 +15,6 @@ import de.danoeh.antennapod.fragment.EpisodesFragment;
import de.danoeh.antennapod.fragment.PlaybackHistoryFragment;
import de.danoeh.antennapod.fragment.QueueFragment;
import de.test.antennapod.EspressoTestUtils;
import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@ -29,10 +26,12 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static androidx.test.espresso.Espresso.onData;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.longClick;
import static androidx.test.espresso.action.ViewActions.scrollTo;
import static androidx.test.espresso.action.ViewActions.swipeUp;
import static androidx.test.espresso.intent.Intents.intended;
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent;
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
@ -46,7 +45,7 @@ import static org.hamcrest.Matchers.allOf;
import static org.junit.Assert.assertEquals;
/**
* User interface tests for MainActivity drawer
* User interface tests for MainActivity drawer.
*/
@RunWith(AndroidJUnit4.class)
public class NavigationDrawerTest {
@ -54,7 +53,7 @@ public class NavigationDrawerTest {
private UITestUtils uiTestUtils;
@Rule
public IntentsTestRule<MainActivity> mActivityRule = new IntentsTestRule<>(MainActivity.class, false, false);
public IntentsTestRule<MainActivity> activityRule = new IntentsTestRule<>(MainActivity.class, false, false);
@Before
public void setUp() throws IOException {
@ -80,8 +79,8 @@ public class NavigationDrawerTest {
public void testClickNavDrawer() throws Exception {
uiTestUtils.addLocalFeedData(false);
UserPreferences.setHiddenDrawerItems(new ArrayList<>());
mActivityRule.launchActivity(new Intent());
MainActivity activity = mActivityRule.getActivity();
activityRule.launchActivity(new Intent());
MainActivity activity = activityRule.getActivity();
// queue
openNavDrawer();
@ -115,6 +114,7 @@ public class NavigationDrawerTest {
// add podcast
openNavDrawer();
onView(withId(R.id.nav_list)).perform(swipeUp());
onDrawerItem(withText(R.string.add_feed_label)).perform(click());
onView(isRoot()).perform(waitForView(withId(R.id.txtvFeedurl), 1000));
assertEquals(activity.getString(R.string.add_feed_label), activity.getSupportActionBar().getTitle());
@ -131,7 +131,7 @@ public class NavigationDrawerTest {
@Test
public void testGoToPreferences() {
mActivityRule.launchActivity(new Intent());
activityRule.launchActivity(new Intent());
openNavDrawer();
onView(withText(R.string.settings_label)).perform(click());
intended(hasComponent(PreferenceActivity.class.getName()));
@ -140,7 +140,7 @@ public class NavigationDrawerTest {
@Test
public void testDrawerPreferencesHideSomeElements() {
UserPreferences.setHiddenDrawerItems(new ArrayList<>());
mActivityRule.launchActivity(new Intent());
activityRule.launchActivity(new Intent());
openNavDrawer();
onDrawerItem(withText(R.string.queue_label)).perform(longClick());
onView(withText(R.string.episodes_label)).perform(click());
@ -157,7 +157,7 @@ public class NavigationDrawerTest {
public void testDrawerPreferencesUnhideSomeElements() {
List<String> hidden = Arrays.asList(PlaybackHistoryFragment.TAG, DownloadsFragment.TAG);
UserPreferences.setHiddenDrawerItems(hidden);
mActivityRule.launchActivity(new Intent());
activityRule.launchActivity(new Intent());
openNavDrawer();
onView(first(withText(R.string.queue_label))).perform(longClick());
@ -175,14 +175,20 @@ public class NavigationDrawerTest {
@Test
public void testDrawerPreferencesHideAllElements() {
UserPreferences.setHiddenDrawerItems(new ArrayList<>());
mActivityRule.launchActivity(new Intent());
String[] titles = mActivityRule.getActivity().getResources().getStringArray(R.array.nav_drawer_titles);
activityRule.launchActivity(new Intent());
String[] titles = activityRule.getActivity().getResources().getStringArray(R.array.nav_drawer_titles);
openNavDrawer();
onView(first(withText(R.string.queue_label))).perform(longClick());
for (String title : titles) {
for (int i = 0; i < titles.length; i++) {
String title = titles[i];
onView(first(withText(title))).perform(click());
if (i == 3) {
onView(withId(R.id.select_dialog_listview)).perform(swipeUp());
}
}
onView(withText(R.string.confirm_label)).perform(click());
List<String> hidden = UserPreferences.getHiddenDrawerItems();
@ -195,7 +201,7 @@ public class NavigationDrawerTest {
@Test
public void testDrawerPreferencesHideCurrentElement() {
UserPreferences.setHiddenDrawerItems(new ArrayList<>());
mActivityRule.launchActivity(new Intent());
activityRule.launchActivity(new Intent());
openNavDrawer();
onView(withText(R.string.downloads_label)).perform(click());
openNavDrawer();

View File

@ -32,12 +32,14 @@ import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.replaceText;
import static androidx.test.espresso.action.ViewActions.scrollTo;
import static androidx.test.espresso.action.ViewActions.swipeUp;
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isChecked;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static de.test.antennapod.EspressoTestUtils.clickPreference;
import static de.test.antennapod.EspressoTestUtils.waitForView;
@ -394,7 +396,7 @@ public class PreferencesTest {
onView(withText(R.string.network_pref)).perform(click());
onView(withText(R.string.pref_automatic_download_title)).perform(click());
onView(withText(R.string.pref_episode_cleanup_title)).perform(click());
onView(isRoot()).perform(waitForView(withText(R.string.episode_cleanup_never), 1000));
onView(withId(R.id.select_dialog_listview)).perform(swipeUp());
onView(withText(R.string.episode_cleanup_never)).perform(click());
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getEpisodeCleanupAlgorithm() instanceof APNullCleanupAlgorithm);