Switched to awaitility

Test now takes only half of the time
This commit is contained in:
ByteHamster 2019-11-12 19:50:15 +01:00
parent 8aaf4af6f8
commit c0f5046584
1 changed files with 165 additions and 134 deletions

View File

@ -4,21 +4,10 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.preference.PreferenceManager;
import androidx.annotation.StringRes;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import com.robotium.solo.Solo;
import com.robotium.solo.Timeout;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import com.google.android.material.snackbar.Snackbar;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.PreferenceActivity;
import de.danoeh.antennapod.core.preferences.UserPreferences;
@ -31,20 +20,35 @@ import de.danoeh.antennapod.fragment.EpisodesFragment;
import de.danoeh.antennapod.fragment.QueueFragment;
import de.danoeh.antennapod.fragment.SubscriptionFragment;
import de.test.antennapod.EspressoTestUtils;
import org.awaitility.Awaitility;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
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.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.withText;
import static de.test.antennapod.EspressoTestUtils.clickPreference;
import static junit.framework.TestCase.assertEquals;
import static de.test.antennapod.EspressoTestUtils.waitForView;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static junit.framework.TestCase.assertTrue;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.not;
@LargeTest
public class PreferencesTest {
private Solo solo;
private Resources res;
@Rule
@ -58,9 +62,6 @@ public class PreferencesTest {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mActivityRule.getActivity());
prefs.edit().putBoolean(UserPreferences.PREF_ENABLE_AUTODL, true).commit();
solo = new Solo(getInstrumentation(), mActivityRule.getActivity());
Timeout.setSmallTimeout(500);
Timeout.setLargeTimeout(1000);
res = mActivityRule.getActivity().getResources();
UserPreferences.init(mActivityRule.getActivity());
}
@ -77,7 +78,8 @@ public class PreferencesTest {
clickPreference(R.string.user_interface_label);
clickPreference(R.string.pref_set_theme_title);
onView(withText(otherTheme)).perform(click());
assertTrue(solo.waitForCondition(() -> UserPreferences.getTheme() != theme, Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getTheme() != theme);
}
@Test
@ -92,7 +94,8 @@ public class PreferencesTest {
clickPreference(R.string.user_interface_label);
clickPreference(R.string.pref_set_theme_title);
onView(withText(otherTheme)).perform(click());
assertTrue(solo.waitForCondition(() -> UserPreferences.getTheme() != theme, Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getTheme() != theme);
}
@Test
@ -100,9 +103,11 @@ public class PreferencesTest {
final boolean persistNotify = UserPreferences.isPersistNotify();
clickPreference(R.string.user_interface_label);
clickPreference(R.string.pref_persistNotify_title);
assertTrue(solo.waitForCondition(() -> persistNotify != UserPreferences.isPersistNotify(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> persistNotify != UserPreferences.isPersistNotify());
clickPreference(R.string.pref_persistNotify_title);
assertTrue(solo.waitForCondition(() -> persistNotify == UserPreferences.isPersistNotify(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> persistNotify == UserPreferences.isPersistNotify());
}
@Test
@ -110,7 +115,6 @@ public class PreferencesTest {
clickPreference(R.string.user_interface_label);
String[] buttons = res.getStringArray(R.array.compact_notification_buttons_options);
clickPreference(R.string.pref_compact_notification_buttons_title);
solo.waitForDialogToOpen(1000);
// First uncheck checkbox
onView(withText(buttons[2])).perform(click());
@ -120,12 +124,24 @@ public class PreferencesTest {
onView(withText(buttons[2])).perform(click());
// Make sure that the third checkbox is unchecked
assertTrue(!solo.isTextChecked(buttons[2]));
onView(withText(buttons[2])).check(matches(not(isChecked())));
String snackBarText = String.format(res.getString(
R.string.pref_compact_notification_buttons_dialog_error), 2);
Awaitility.await().ignoreExceptions().atMost(4000, MILLISECONDS)
.until(() -> {
onView(withText(snackBarText)).check(doesNotExist());
return true;
});
onView(withText(R.string.confirm_label)).perform(click());
solo.waitForDialogToClose(1000);
assertTrue(solo.waitForCondition(UserPreferences::showRewindOnCompactNotification, Timeout.getLargeTimeout()));
assertTrue(solo.waitForCondition(UserPreferences::showFastForwardOnCompactNotification, Timeout.getLargeTimeout()));
assertTrue(solo.waitForCondition(() -> !UserPreferences.showSkipOnCompactNotification(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(UserPreferences::showRewindOnCompactNotification);
Awaitility.await().atMost(1000, MILLISECONDS)
.until(UserPreferences::showFastForwardOnCompactNotification);
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> !UserPreferences.showSkipOnCompactNotification());
}
@Test
@ -139,9 +155,8 @@ public class PreferencesTest {
private void doTestEnqueueLocation(@StringRes int optionResId, EnqueueLocation expected) {
clickPreference(R.string.pref_enqueue_location_title);
onView(withText(optionResId)).perform(click());
assertTrue(solo.waitForCondition(
() -> expected == UserPreferences.getEnqueueLocation(),
Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> expected == UserPreferences.getEnqueueLocation());
}
@Test
@ -149,37 +164,45 @@ public class PreferencesTest {
onView(withText(R.string.playback_pref)).perform(click());
final boolean pauseOnHeadsetDisconnect = UserPreferences.isPauseOnHeadsetDisconnect();
onView(withText(R.string.pref_pauseOnHeadsetDisconnect_title)).perform(click());
assertTrue(solo.waitForCondition(() -> pauseOnHeadsetDisconnect != UserPreferences.isPauseOnHeadsetDisconnect(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> pauseOnHeadsetDisconnect != UserPreferences.isPauseOnHeadsetDisconnect());
onView(withText(R.string.pref_pauseOnHeadsetDisconnect_title)).perform(click());
assertTrue(solo.waitForCondition(() -> pauseOnHeadsetDisconnect == UserPreferences.isPauseOnHeadsetDisconnect(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> pauseOnHeadsetDisconnect == UserPreferences.isPauseOnHeadsetDisconnect());
}
@Test
public void testHeadPhonesReconnect() {
onView(withText(R.string.playback_pref)).perform(click());
if(UserPreferences.isPauseOnHeadsetDisconnect() == false) {
if (!UserPreferences.isPauseOnHeadsetDisconnect()) {
onView(withText(R.string.pref_pauseOnHeadsetDisconnect_title)).perform(click());
assertTrue(solo.waitForCondition(UserPreferences::isPauseOnHeadsetDisconnect, Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(UserPreferences::isPauseOnHeadsetDisconnect);
}
final boolean unpauseOnHeadsetReconnect = UserPreferences.isUnpauseOnHeadsetReconnect();
onView(withText(R.string.pref_unpauseOnHeadsetReconnect_title)).perform(click());
assertTrue(solo.waitForCondition(() -> unpauseOnHeadsetReconnect != UserPreferences.isUnpauseOnHeadsetReconnect(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> unpauseOnHeadsetReconnect != UserPreferences.isUnpauseOnHeadsetReconnect());
onView(withText(R.string.pref_unpauseOnHeadsetReconnect_title)).perform(click());
assertTrue(solo.waitForCondition(() -> unpauseOnHeadsetReconnect == UserPreferences.isUnpauseOnHeadsetReconnect(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> unpauseOnHeadsetReconnect == UserPreferences.isUnpauseOnHeadsetReconnect());
}
@Test
public void testBluetoothReconnect() {
onView(withText(R.string.playback_pref)).perform(click());
if(UserPreferences.isPauseOnHeadsetDisconnect() == false) {
if (!UserPreferences.isPauseOnHeadsetDisconnect()) {
onView(withText(R.string.pref_pauseOnHeadsetDisconnect_title)).perform(click());
assertTrue(solo.waitForCondition(UserPreferences::isPauseOnHeadsetDisconnect, Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(UserPreferences::isPauseOnHeadsetDisconnect);
}
final boolean unpauseOnBluetoothReconnect = UserPreferences.isUnpauseOnBluetoothReconnect();
onView(withText(R.string.pref_unpauseOnBluetoothReconnect_title)).perform(click());
assertTrue(solo.waitForCondition(() -> unpauseOnBluetoothReconnect != UserPreferences.isUnpauseOnBluetoothReconnect(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> unpauseOnBluetoothReconnect != UserPreferences.isUnpauseOnBluetoothReconnect());
onView(withText(R.string.pref_unpauseOnBluetoothReconnect_title)).perform(click());
assertTrue(solo.waitForCondition(() -> unpauseOnBluetoothReconnect == UserPreferences.isUnpauseOnBluetoothReconnect(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> unpauseOnBluetoothReconnect == UserPreferences.isUnpauseOnBluetoothReconnect());
}
@Test
@ -187,9 +210,11 @@ public class PreferencesTest {
clickPreference(R.string.playback_pref);
final boolean continuousPlayback = UserPreferences.isFollowQueue();
clickPreference(R.string.pref_followQueue_title);
assertTrue(solo.waitForCondition(() -> continuousPlayback != UserPreferences.isFollowQueue(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> continuousPlayback != UserPreferences.isFollowQueue());
clickPreference(R.string.pref_followQueue_title);
assertTrue(solo.waitForCondition(() -> continuousPlayback == UserPreferences.isFollowQueue(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> continuousPlayback == UserPreferences.isFollowQueue());
}
@Test
@ -197,9 +222,11 @@ public class PreferencesTest {
onView(withText(R.string.storage_pref)).perform(click());
final boolean autoDelete = UserPreferences.isAutoDelete();
onView(withText(R.string.pref_auto_delete_title)).perform(click());
assertTrue(solo.waitForCondition(() -> autoDelete != UserPreferences.isAutoDelete(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> autoDelete != UserPreferences.isAutoDelete());
onView(withText(R.string.pref_auto_delete_title)).perform(click());
assertTrue(solo.waitForCondition(() -> autoDelete == UserPreferences.isAutoDelete(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> autoDelete == UserPreferences.isAutoDelete());
}
@Test
@ -208,7 +235,7 @@ public class PreferencesTest {
clickPreference(R.string.media_player);
onView(withText(R.string.media_player_exoplayer)).perform(click());
clickPreference(R.string.pref_playback_speed_title);
solo.waitForDialogToOpen();
onView(isRoot()).perform(waitForView(withText("0.50"), 1000));
onView(withText("0.50")).check(matches(isDisplayed()));
onView(withText(R.string.cancel_label)).perform(click());
}
@ -218,9 +245,11 @@ public class PreferencesTest {
onView(withText(R.string.playback_pref)).perform(click());
final boolean pauseForFocusLoss = UserPreferences.shouldPauseForFocusLoss();
onView(withText(R.string.pref_pausePlaybackForFocusLoss_title)).perform(click());
assertTrue(solo.waitForCondition(() -> pauseForFocusLoss != UserPreferences.shouldPauseForFocusLoss(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> pauseForFocusLoss != UserPreferences.shouldPauseForFocusLoss());
onView(withText(R.string.pref_pausePlaybackForFocusLoss_title)).perform(click());
assertTrue(solo.waitForCondition(() -> pauseForFocusLoss == UserPreferences.shouldPauseForFocusLoss(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> pauseForFocusLoss == UserPreferences.shouldPauseForFocusLoss());
}
@Test
@ -228,7 +257,8 @@ public class PreferencesTest {
onView(withText(R.string.network_pref)).perform(click());
onView(withText(R.string.pref_autoUpdateIntervallOrTime_title)).perform(click());
onView(withText(R.string.pref_autoUpdateIntervallOrTime_Disable)).perform(click());
assertTrue(solo.waitForCondition(() -> UserPreferences.getUpdateInterval() == 0, 1000));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getUpdateInterval() == 0);
}
@Test
@ -236,45 +266,43 @@ public class PreferencesTest {
clickPreference(R.string.network_pref);
clickPreference(R.string.pref_autoUpdateIntervallOrTime_title);
onView(withText(R.string.pref_autoUpdateIntervallOrTime_Interval)).perform(click());
String search = "12 " + solo.getString(R.string.pref_update_interval_hours_plural);
String search = "12 " + res.getString(R.string.pref_update_interval_hours_plural);
onView(withText(search)).perform(click());
assertTrue(solo.waitForCondition(() -> UserPreferences.getUpdateInterval() ==
TimeUnit.HOURS.toMillis(12), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getUpdateInterval() == TimeUnit.HOURS.toMillis(12));
}
@Test
public void testSetSequentialDownload() {
clickPreference(R.string.network_pref);
clickPreference(R.string.pref_parallel_downloads_title);
solo.waitForDialogToOpen();
solo.clearEditText(0);
solo.enterText(0, "1");
onView(isRoot()).perform(waitForView(withClassName(endsWith("EditText")), 1000));
onView(withClassName(endsWith("EditText"))).perform(replaceText("1"));
onView(withText(android.R.string.ok)).perform(click());
assertTrue(solo.waitForCondition(() -> UserPreferences.getParallelDownloads() == 1, Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getParallelDownloads() == 1);
}
@Test
public void testSetParallelDownloads() {
clickPreference(R.string.network_pref);
clickPreference(R.string.pref_parallel_downloads_title);
solo.waitForDialogToOpen();
solo.clearEditText(0);
solo.enterText(0, "10");
onView(isRoot()).perform(waitForView(withClassName(endsWith("EditText")), 1000));
onView(withClassName(endsWith("EditText"))).perform(replaceText("10"));
onView(withText(android.R.string.ok)).perform(click());
assertTrue(solo.waitForCondition(() -> UserPreferences.getParallelDownloads() == 10, Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getParallelDownloads() == 10);
}
@Test
public void testSetParallelDownloadsInvalidInput() {
clickPreference(R.string.network_pref);
clickPreference(R.string.pref_parallel_downloads_title);
solo.waitForDialogToOpen();
solo.clearEditText(0);
solo.enterText(0, "0");
assertEquals("", solo.getEditText(0).getText().toString());
solo.clearEditText(0);
solo.enterText(0, "100");
assertEquals("", solo.getEditText(0).getText().toString());
onView(isRoot()).perform(waitForView(withClassName(endsWith("EditText")), 1000));
onView(withClassName(endsWith("EditText"))).perform(replaceText("0"));
onView(withClassName(endsWith("EditText"))).check(matches(withText("")));
onView(withClassName(endsWith("EditText"))).perform(replaceText("100"));
onView(withClassName(endsWith("EditText"))).check(matches(withText("")));
}
@Test
@ -282,13 +310,14 @@ public class PreferencesTest {
String[] entries = res.getStringArray(R.array.episode_cache_size_entries);
String[] values = res.getStringArray(R.array.episode_cache_size_values);
String entry = entries[entries.length / 2];
final int value = Integer.valueOf(values[values.length/2]);
final int value = Integer.parseInt(values[values.length / 2]);
clickPreference(R.string.network_pref);
clickPreference(R.string.pref_automatic_download_title);
clickPreference(R.string.pref_episode_cache_title);
solo.waitForDialogToOpen();
solo.clickOnText(entry);
assertTrue(solo.waitForCondition(() -> UserPreferences.getEpisodeCacheSize() == value, Timeout.getLargeTimeout()));
onView(isRoot()).perform(waitForView(withText(entry), 1000));
onView(withText(entry)).perform(click());
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getEpisodeCacheSize() == value);
}
@Test
@ -296,14 +325,14 @@ public class PreferencesTest {
String[] entries = res.getStringArray(R.array.episode_cache_size_entries);
String[] values = res.getStringArray(R.array.episode_cache_size_values);
String minEntry = entries[0];
final int minValue = Integer.valueOf(values[0]);
final int minValue = Integer.parseInt(values[0]);
clickPreference(R.string.network_pref);
clickPreference(R.string.pref_automatic_download_title);
clickPreference(R.string.pref_episode_cache_title);
solo.scrollUp();
onView(withText(minEntry)).perform(click());
assertTrue(solo.waitForCondition(() -> UserPreferences.getEpisodeCacheSize() == minValue, Timeout.getLargeTimeout()));
onView(withText(minEntry)).perform(scrollTo()).perform(click());
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getEpisodeCacheSize() == minValue);
}
@Test
@ -311,12 +340,13 @@ public class PreferencesTest {
String[] entries = res.getStringArray(R.array.episode_cache_size_entries);
String[] values = res.getStringArray(R.array.episode_cache_size_values);
String maxEntry = entries[entries.length - 1];
final int maxValue = Integer.valueOf(values[values.length-1]);
final int maxValue = Integer.parseInt(values[values.length - 1]);
onView(withText(R.string.network_pref)).perform(click());
onView(withText(R.string.pref_automatic_download_title)).perform(click());
onView(withText(R.string.pref_episode_cache_title)).perform(click());
onView(withText(maxEntry)).perform(click());
assertTrue(solo.waitForCondition(() -> UserPreferences.getEpisodeCacheSize() == maxValue, Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getEpisodeCacheSize() == maxValue);
}
@Test
@ -325,22 +355,27 @@ public class PreferencesTest {
clickPreference(R.string.network_pref);
clickPreference(R.string.pref_automatic_download_title);
clickPreference(R.string.pref_automatic_download_title);
assertTrue(solo.waitForCondition(() -> automaticDownload != UserPreferences.isEnableAutodownload(), Timeout.getLargeTimeout()));
if(UserPreferences.isEnableAutodownload() == false) {
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> automaticDownload != UserPreferences.isEnableAutodownload());
if (!UserPreferences.isEnableAutodownload()) {
clickPreference(R.string.pref_automatic_download_title);
}
assertTrue(solo.waitForCondition(() -> UserPreferences.isEnableAutodownload() == true, Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(UserPreferences::isEnableAutodownload);
final boolean enableAutodownloadOnBattery = UserPreferences.isEnableAutodownloadOnBattery();
onView(withText(R.string.pref_automatic_download_on_battery_title)).perform(click());
assertTrue(solo.waitForCondition(() -> enableAutodownloadOnBattery != UserPreferences.isEnableAutodownloadOnBattery(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> enableAutodownloadOnBattery != UserPreferences.isEnableAutodownloadOnBattery());
onView(withText(R.string.pref_automatic_download_on_battery_title)).perform(click());
assertTrue(solo.waitForCondition(() -> enableAutodownloadOnBattery == UserPreferences.isEnableAutodownloadOnBattery(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> enableAutodownloadOnBattery == UserPreferences.isEnableAutodownloadOnBattery());
final boolean enableWifiFilter = UserPreferences.isEnableAutodownloadWifiFilter();
onView(withText(R.string.pref_autodl_wifi_filter_title)).perform(click());
assertTrue(solo.waitForCondition(() -> enableWifiFilter != UserPreferences.isEnableAutodownloadWifiFilter(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> enableWifiFilter != UserPreferences.isEnableAutodownloadWifiFilter());
onView(withText(R.string.pref_autodl_wifi_filter_title)).perform(click());
assertTrue(solo.waitForCondition(() -> enableWifiFilter == UserPreferences.isEnableAutodownloadWifiFilter(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> enableWifiFilter == UserPreferences.isEnableAutodownloadWifiFilter());
}
@Test
@ -348,13 +383,10 @@ 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());
solo.waitForText(solo.getString(R.string.episode_cleanup_queue_removal));
onView(isRoot()).perform(waitForView(withText(R.string.episode_cleanup_queue_removal), 1000));
onView(withText(R.string.episode_cleanup_queue_removal)).perform(click());
assertTrue(solo.waitForCondition(() -> {
EpisodeCleanupAlgorithm alg = UserPreferences.getEpisodeCleanupAlgorithm();
return alg instanceof APQueueCleanupAlgorithm;
},
Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getEpisodeCleanupAlgorithm() instanceof APQueueCleanupAlgorithm);
}
@Test
@ -362,13 +394,10 @@ 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());
solo.waitForText(solo.getString(R.string.episode_cleanup_never));
onView(isRoot()).perform(waitForView(withText(R.string.episode_cleanup_never), 1000));
onView(withText(R.string.episode_cleanup_never)).perform(click());
assertTrue(solo.waitForCondition(() -> {
EpisodeCleanupAlgorithm alg = UserPreferences.getEpisodeCleanupAlgorithm();
return alg instanceof APNullCleanupAlgorithm;
},
Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getEpisodeCleanupAlgorithm() instanceof APNullCleanupAlgorithm);
}
@Test
@ -376,17 +405,17 @@ 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());
solo.waitForText(solo.getString(R.string.episode_cleanup_after_listening));
onView(isRoot()).perform(waitForView(withText(R.string.episode_cleanup_after_listening), 1000));
onView(withText(R.string.episode_cleanup_after_listening)).perform(click());
assertTrue(solo.waitForCondition(() -> {
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> {
EpisodeCleanupAlgorithm alg = UserPreferences.getEpisodeCleanupAlgorithm();
if (alg instanceof APCleanupAlgorithm) {
APCleanupAlgorithm cleanupAlg = (APCleanupAlgorithm) alg;
return cleanupAlg.getNumberOfHoursAfterPlayback() == 0;
}
return false;
},
Timeout.getLargeTimeout()));
});
}
@Test
@ -394,24 +423,24 @@ public class PreferencesTest {
clickPreference(R.string.network_pref);
clickPreference(R.string.pref_automatic_download_title);
clickPreference(R.string.pref_episode_cleanup_title);
solo.waitForDialogToOpen();
String search = res.getQuantityString(R.plurals.episode_cleanup_days_after_listening, 5, 5);
onView(isRoot()).perform(waitForView(withText(search), 1000));
onView(withText(search)).perform(click());
assertTrue(solo.waitForCondition(() -> {
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> {
EpisodeCleanupAlgorithm alg = UserPreferences.getEpisodeCleanupAlgorithm();
if (alg instanceof APCleanupAlgorithm) {
APCleanupAlgorithm cleanupAlg = (APCleanupAlgorithm) alg;
return cleanupAlg.getNumberOfHoursAfterPlayback() == 120; // 5 days
}
return false;
},
Timeout.getLargeTimeout()));
});
}
@Test
public void testRewindChange() {
int seconds = UserPreferences.getRewindSecs();
int deltas[] = res.getIntArray(R.array.seek_delta_values);
int[] deltas = res.getIntArray(R.array.seek_delta_values);
clickPreference(R.string.playback_pref);
clickPreference(R.string.pref_rewind);
@ -421,11 +450,11 @@ public class PreferencesTest {
// Find next value (wrapping around to next)
int newIndex = (currentIndex + 1) % deltas.length;
onView(withText(String.valueOf(deltas[newIndex]) + " seconds")).perform(click());
onView(withText(deltas[newIndex] + " seconds")).perform(click());
onView(withText("Confirm")).perform(click());
assertTrue(solo.waitForCondition(() -> UserPreferences.getRewindSecs() == deltas[newIndex],
Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getRewindSecs() == deltas[newIndex]);
}
@Test
@ -433,7 +462,7 @@ public class PreferencesTest {
clickPreference(R.string.playback_pref);
for (int i = 2; i > 0; i--) { // repeat twice to catch any error where fastforward is tracking rewind
int seconds = UserPreferences.getFastForwardSecs();
int deltas[] = res.getIntArray(R.array.seek_delta_values);
int[] deltas = res.getIntArray(R.array.seek_delta_values);
clickPreference(R.string.pref_fast_forward);
@ -446,9 +475,8 @@ public class PreferencesTest {
onView(withText(deltas[newIndex] + " seconds")).perform(click());
onView(withText("Confirm")).perform(click());
solo.waitForDialogToClose();
assertTrue(solo.waitForCondition(() -> UserPreferences.getFastForwardSecs() == deltas[newIndex],
Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getFastForwardSecs() == deltas[newIndex]);
}
}
@ -459,26 +487,26 @@ public class PreferencesTest {
onView(withText(R.string.back_button_go_to_page)).perform(click());
onView(withText(R.string.queue_label)).perform(click());
onView(withText(R.string.confirm_label)).perform(click());
assertTrue(solo.waitForCondition(() -> UserPreferences.getBackButtonBehavior() == UserPreferences.BackButtonBehavior.GO_TO_PAGE,
Timeout.getLargeTimeout()));
assertTrue(solo.waitForCondition(() -> UserPreferences.getBackButtonGoToPage().equals(QueueFragment.TAG),
Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getBackButtonBehavior() == UserPreferences.BackButtonBehavior.GO_TO_PAGE);
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getBackButtonGoToPage().equals(QueueFragment.TAG));
clickPreference(R.string.pref_back_button_behavior_title);
onView(withText(R.string.back_button_go_to_page)).perform(click());
onView(withText(R.string.episodes_label)).perform(click());
onView(withText(R.string.confirm_label)).perform(click());
assertTrue(solo.waitForCondition(() -> UserPreferences.getBackButtonBehavior() == UserPreferences.BackButtonBehavior.GO_TO_PAGE,
Timeout.getLargeTimeout()));
assertTrue(solo.waitForCondition(() -> UserPreferences.getBackButtonGoToPage().equals(EpisodesFragment.TAG),
Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getBackButtonBehavior() == UserPreferences.BackButtonBehavior.GO_TO_PAGE);
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getBackButtonGoToPage().equals(EpisodesFragment.TAG));
clickPreference(R.string.pref_back_button_behavior_title);
onView(withText(R.string.back_button_go_to_page)).perform(click());
onView(withText(R.string.subscriptions_label)).perform(click());
onView(withText(R.string.confirm_label)).perform(click());
assertTrue(solo.waitForCondition(() -> UserPreferences.getBackButtonBehavior() == UserPreferences.BackButtonBehavior.GO_TO_PAGE,
Timeout.getLargeTimeout()));
assertTrue(solo.waitForCondition(() -> UserPreferences.getBackButtonGoToPage().equals(SubscriptionFragment.TAG),
Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getBackButtonBehavior() == UserPreferences.BackButtonBehavior.GO_TO_PAGE);
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> UserPreferences.getBackButtonGoToPage().equals(SubscriptionFragment.TAG));
}
@Test
@ -486,12 +514,15 @@ public class PreferencesTest {
clickPreference(R.string.storage_pref);
if (!UserPreferences.shouldDeleteRemoveFromQueue()) {
clickPreference(R.string.pref_delete_removes_from_queue_title);
assertTrue(solo.waitForCondition(UserPreferences::shouldDeleteRemoveFromQueue, Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(UserPreferences::shouldDeleteRemoveFromQueue);
}
final boolean deleteRemovesFromQueue = UserPreferences.shouldDeleteRemoveFromQueue();
onView(withText(R.string.pref_delete_removes_from_queue_title)).perform(click());
assertTrue(solo.waitForCondition(() -> deleteRemovesFromQueue != UserPreferences.shouldDeleteRemoveFromQueue(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> deleteRemovesFromQueue != UserPreferences.shouldDeleteRemoveFromQueue());
onView(withText(R.string.pref_delete_removes_from_queue_title)).perform(click());
assertTrue(solo.waitForCondition(() -> deleteRemovesFromQueue == UserPreferences.shouldDeleteRemoveFromQueue(), Timeout.getLargeTimeout()));
Awaitility.await().atMost(1000, MILLISECONDS)
.until(() -> deleteRemovesFromQueue == UserPreferences.shouldDeleteRemoveFromQueue());
}
}