fix PreferencesTest to actually check the condition was met.

This commit is contained in:
Tom Hennen 2015-10-02 16:26:42 -04:00
parent af5579a30e
commit f3e56a2385
1 changed files with 37 additions and 198 deletions

View File

@ -14,6 +14,7 @@ import org.apache.commons.io.IOUtils;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.PreferenceActivity; import de.danoeh.antennapod.activity.PreferenceActivity;
@ -59,12 +60,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
solo.clickOnText(solo.getString(R.string.pref_set_theme_title)); solo.clickOnText(solo.getString(R.string.pref_set_theme_title));
solo.waitForDialogToOpen(); solo.waitForDialogToOpen();
solo.clickOnText(solo.getString(otherTheme)); solo.clickOnText(solo.getString(otherTheme));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> UserPreferences.getTheme() != theme, Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return UserPreferences.getTheme() != theme;
}
}, Timeout.getLargeTimeout());
} }
public void testSwitchThemeBack() { public void testSwitchThemeBack() {
@ -78,140 +74,67 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
solo.clickOnText(solo.getString(R.string.pref_set_theme_title)); solo.clickOnText(solo.getString(R.string.pref_set_theme_title));
solo.waitForDialogToOpen(1000); solo.waitForDialogToOpen(1000);
solo.clickOnText(solo.getString(otherTheme)); solo.clickOnText(solo.getString(otherTheme));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> UserPreferences.getTheme() != theme, Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return UserPreferences.getTheme() != theme;
}
}, Timeout.getLargeTimeout());
} }
public void testExpandNotification() { public void testExpandNotification() {
final int priority = UserPreferences.getNotifyPriority(); final int priority = UserPreferences.getNotifyPriority();
solo.clickOnText(solo.getString(R.string.pref_expandNotify_title)); solo.clickOnText(solo.getString(R.string.pref_expandNotify_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> priority != UserPreferences.getNotifyPriority(), Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return priority != UserPreferences.getNotifyPriority();
}
}, Timeout.getLargeTimeout());
solo.clickOnText(solo.getString(R.string.pref_expandNotify_title)); solo.clickOnText(solo.getString(R.string.pref_expandNotify_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> priority == UserPreferences.getNotifyPriority(), Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return priority == UserPreferences.getNotifyPriority();
}
}, Timeout.getLargeTimeout());
} }
public void testEnablePersistentPlaybackControls() { public void testEnablePersistentPlaybackControls() {
final boolean persistNotify = UserPreferences.isPersistNotify(); final boolean persistNotify = UserPreferences.isPersistNotify();
solo.clickOnText(solo.getString(R.string.pref_persistNotify_title)); solo.clickOnText(solo.getString(R.string.pref_persistNotify_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> persistNotify != UserPreferences.isPersistNotify(), Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return persistNotify != UserPreferences.isPersistNotify();
}
}, Timeout.getLargeTimeout());
solo.clickOnText(solo.getString(R.string.pref_persistNotify_title)); solo.clickOnText(solo.getString(R.string.pref_persistNotify_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> persistNotify == UserPreferences.isPersistNotify(), Timeout.getLargeTimeout()));
@Override public boolean isSatisfied() {
return persistNotify == UserPreferences.isPersistNotify();
}
}, Timeout.getLargeTimeout());
} }
public void testEnqueueAtFront() { public void testEnqueueAtFront() {
final boolean enqueueAtFront = UserPreferences.enqueueAtFront(); final boolean enqueueAtFront = UserPreferences.enqueueAtFront();
solo.clickOnText(solo.getString(R.string.pref_queueAddToFront_title)); solo.clickOnText(solo.getString(R.string.pref_queueAddToFront_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> enqueueAtFront != UserPreferences.enqueueAtFront(), Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return enqueueAtFront != UserPreferences.enqueueAtFront();
}
}, Timeout.getLargeTimeout());
solo.clickOnText(solo.getString(R.string.pref_queueAddToFront_title)); solo.clickOnText(solo.getString(R.string.pref_queueAddToFront_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> enqueueAtFront == UserPreferences.enqueueAtFront(), Timeout.getLargeTimeout()));
@Override public boolean isSatisfied() {
return enqueueAtFront == UserPreferences.enqueueAtFront();
}
}, Timeout.getLargeTimeout());
} }
public void testHeadPhonesDisconnect() { public void testHeadPhonesDisconnect() {
final boolean pauseOnHeadsetDisconnect = UserPreferences.isPauseOnHeadsetDisconnect(); final boolean pauseOnHeadsetDisconnect = UserPreferences.isPauseOnHeadsetDisconnect();
solo.clickOnText(solo.getString(R.string.pref_pauseOnHeadsetDisconnect_title)); solo.clickOnText(solo.getString(R.string.pref_pauseOnHeadsetDisconnect_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> pauseOnHeadsetDisconnect != UserPreferences.isPauseOnHeadsetDisconnect(), Timeout.getLargeTimeout()));
@Override public boolean isSatisfied() {
return pauseOnHeadsetDisconnect != UserPreferences.isPauseOnHeadsetDisconnect();
}
}, Timeout.getLargeTimeout());
solo.clickOnText(solo.getString(R.string.pref_pauseOnHeadsetDisconnect_title)); solo.clickOnText(solo.getString(R.string.pref_pauseOnHeadsetDisconnect_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> pauseOnHeadsetDisconnect == UserPreferences.isPauseOnHeadsetDisconnect(), Timeout.getLargeTimeout()));
@Override public boolean isSatisfied() {
return pauseOnHeadsetDisconnect == UserPreferences.isPauseOnHeadsetDisconnect();
}
}, Timeout.getLargeTimeout());
} }
public void testHeadPhonesReconnect() { public void testHeadPhonesReconnect() {
if(UserPreferences.isPauseOnHeadsetDisconnect() == false) { if(UserPreferences.isPauseOnHeadsetDisconnect() == false) {
solo.clickOnText(solo.getString(R.string.pref_pauseOnHeadsetDisconnect_title)); solo.clickOnText(solo.getString(R.string.pref_pauseOnHeadsetDisconnect_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> UserPreferences.isPauseOnHeadsetDisconnect(), Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return UserPreferences.isPauseOnHeadsetDisconnect();
}
}, Timeout.getLargeTimeout());
} }
final boolean unpauseOnHeadsetReconnect = UserPreferences.isUnpauseOnHeadsetReconnect(); final boolean unpauseOnHeadsetReconnect = UserPreferences.isUnpauseOnHeadsetReconnect();
solo.clickOnText(solo.getString(R.string.pref_unpauseOnHeadsetReconnect_title)); solo.clickOnText(solo.getString(R.string.pref_unpauseOnHeadsetReconnect_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> unpauseOnHeadsetReconnect != UserPreferences.isUnpauseOnHeadsetReconnect(), Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return unpauseOnHeadsetReconnect != UserPreferences.isUnpauseOnHeadsetReconnect();
}
}, Timeout.getLargeTimeout());
solo.clickOnText(solo.getString(R.string.pref_unpauseOnHeadsetReconnect_title)); solo.clickOnText(solo.getString(R.string.pref_unpauseOnHeadsetReconnect_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> unpauseOnHeadsetReconnect == UserPreferences.isUnpauseOnHeadsetReconnect(), Timeout.getLargeTimeout()));
@Override public boolean isSatisfied() {
return unpauseOnHeadsetReconnect == UserPreferences.isUnpauseOnHeadsetReconnect();
}
}, Timeout.getLargeTimeout());
} }
public void testContinuousPlayback() { public void testContinuousPlayback() {
final boolean continuousPlayback = UserPreferences.isFollowQueue(); final boolean continuousPlayback = UserPreferences.isFollowQueue();
solo.clickOnText(solo.getString(R.string.pref_followQueue_title)); solo.clickOnText(solo.getString(R.string.pref_followQueue_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> continuousPlayback != UserPreferences.isFollowQueue(), Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return continuousPlayback != UserPreferences.isFollowQueue();
}
}, Timeout.getLargeTimeout());
solo.clickOnText(solo.getString(R.string.pref_followQueue_title)); solo.clickOnText(solo.getString(R.string.pref_followQueue_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> continuousPlayback == UserPreferences.isFollowQueue(), Timeout.getLargeTimeout()));
@Override public boolean isSatisfied() {
return continuousPlayback == UserPreferences.isFollowQueue();
}
}, Timeout.getLargeTimeout());
} }
public void testAutoDelete() { public void testAutoDelete() {
final boolean autoDelete = UserPreferences.isAutoDelete(); final boolean autoDelete = UserPreferences.isAutoDelete();
solo.clickOnText(solo.getString(R.string.pref_auto_delete_title)); solo.clickOnText(solo.getString(R.string.pref_auto_delete_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> autoDelete != UserPreferences.isAutoDelete(), Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return autoDelete != UserPreferences.isAutoDelete();
}
}, Timeout.getLargeTimeout());
solo.clickOnText(solo.getString(R.string.pref_auto_delete_title)); solo.clickOnText(solo.getString(R.string.pref_auto_delete_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> autoDelete == UserPreferences.isAutoDelete(), Timeout.getLargeTimeout()));
@Override public boolean isSatisfied() {
return autoDelete == UserPreferences.isAutoDelete();
}
}, Timeout.getLargeTimeout());
} }
public void testPlaybackSpeeds() { public void testPlaybackSpeeds() {
@ -225,31 +148,16 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
public void testPauseForInterruptions() { public void testPauseForInterruptions() {
final boolean pauseForFocusLoss = UserPreferences.shouldPauseForFocusLoss(); final boolean pauseForFocusLoss = UserPreferences.shouldPauseForFocusLoss();
solo.clickOnText(solo.getString(R.string.pref_pausePlaybackForFocusLoss_title)); solo.clickOnText(solo.getString(R.string.pref_pausePlaybackForFocusLoss_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> pauseForFocusLoss != UserPreferences.shouldPauseForFocusLoss(), Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return pauseForFocusLoss != UserPreferences.shouldPauseForFocusLoss();
}
}, Timeout.getLargeTimeout());
solo.clickOnText(solo.getString(R.string.pref_pausePlaybackForFocusLoss_title)); solo.clickOnText(solo.getString(R.string.pref_pausePlaybackForFocusLoss_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> pauseForFocusLoss == UserPreferences.shouldPauseForFocusLoss(), Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return pauseForFocusLoss == UserPreferences.shouldPauseForFocusLoss();
}
}, Timeout.getLargeTimeout());
} }
public void testDisableUpdateInterval() { public void testDisableUpdateInterval() {
solo.clickOnText(solo.getString(R.string.pref_autoUpdateIntervallOrTime_sum)); solo.clickOnText(solo.getString(R.string.pref_autoUpdateIntervallOrTime_sum));
solo.waitForDialogToOpen(); solo.waitForDialogToOpen();
solo.clickOnText(solo.getString(R.string.pref_autoUpdateIntervallOrTime_Disable)); solo.clickOnText(solo.getString(R.string.pref_autoUpdateIntervallOrTime_Disable));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> UserPreferences.getUpdateInterval() == 0, 1000));
@Override
public boolean isSatisfied() {
return UserPreferences.getUpdateInterval() == 0;
}
}, 1000);
} }
public void testSetUpdateInterval() { public void testSetUpdateInterval() {
@ -260,30 +168,16 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
String search = "12 " + solo.getString(R.string.pref_update_interval_hours_plural); String search = "12 " + solo.getString(R.string.pref_update_interval_hours_plural);
solo.clickOnText(search); solo.clickOnText(search);
solo.waitForDialogToClose(); solo.waitForDialogToClose();
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> UserPreferences.getUpdateInterval() ==
@Override TimeUnit.HOURS.toMillis(12), Timeout.getLargeTimeout()));
public boolean isSatisfied() {
return UserPreferences.getUpdateInterval() == 12;
}
}, Timeout.getLargeTimeout());
} }
public void testMobileUpdates() { public void testMobileUpdates() {
final boolean mobileUpdates = UserPreferences.isAllowMobileUpdate(); final boolean mobileUpdates = UserPreferences.isAllowMobileUpdate();
solo.clickOnText(solo.getString(R.string.pref_mobileUpdate_title)); solo.clickOnText(solo.getString(R.string.pref_mobileUpdate_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> mobileUpdates != UserPreferences.isAllowMobileUpdate(), Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return mobileUpdates != UserPreferences.isAllowMobileUpdate();
}
}, Timeout.getLargeTimeout());
solo.clickOnText(solo.getString(R.string.pref_mobileUpdate_title)); solo.clickOnText(solo.getString(R.string.pref_mobileUpdate_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> mobileUpdates == UserPreferences.isAllowMobileUpdate(), Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return mobileUpdates == UserPreferences.isAllowMobileUpdate();
}
}, Timeout.getLargeTimeout());
} }
public void testSetSequentialDownload() { public void testSetSequentialDownload() {
@ -292,12 +186,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
solo.clearEditText(0); solo.clearEditText(0);
solo.enterText(0, "1"); solo.enterText(0, "1");
solo.clickOnText(solo.getString(android.R.string.ok)); solo.clickOnText(solo.getString(android.R.string.ok));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> UserPreferences.getParallelDownloads() == 1, Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return UserPreferences.getParallelDownloads() == 1;
}
}, Timeout.getLargeTimeout());
} }
public void testSetParallelDownloads() { public void testSetParallelDownloads() {
@ -306,12 +195,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
solo.clearEditText(0); solo.clearEditText(0);
solo.enterText(0, "10"); solo.enterText(0, "10");
solo.clickOnText(solo.getString(android.R.string.ok)); solo.clickOnText(solo.getString(android.R.string.ok));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> UserPreferences.getParallelDownloads() == 10, Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return UserPreferences.getParallelDownloads() == 10;
}
}, Timeout.getLargeTimeout());
} }
public void testSetParallelDownloadsInvalidInput() { public void testSetParallelDownloadsInvalidInput() {
@ -333,12 +217,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
solo.clickOnText(solo.getString(R.string.pref_episode_cache_title)); solo.clickOnText(solo.getString(R.string.pref_episode_cache_title));
solo.waitForDialogToOpen(); solo.waitForDialogToOpen();
solo.clickOnText(entry); solo.clickOnText(entry);
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> UserPreferences.getEpisodeCacheSize() == value, Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return UserPreferences.getEpisodeCacheSize() == value;
}
}, Timeout.getLargeTimeout());
} }
public void testSetEpisodeCacheMin() { public void testSetEpisodeCacheMin() {
@ -350,12 +229,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
solo.waitForDialogToOpen(1000); solo.waitForDialogToOpen(1000);
solo.scrollUp(); solo.scrollUp();
solo.clickOnText(minEntry); solo.clickOnText(minEntry);
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> UserPreferences.getEpisodeCacheSize() == minValue, Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return UserPreferences.getEpisodeCacheSize() == minValue;
}
}, Timeout.getLargeTimeout());
} }
@ -367,12 +241,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
solo.clickOnText(solo.getString(R.string.pref_episode_cache_title)); solo.clickOnText(solo.getString(R.string.pref_episode_cache_title));
solo.waitForDialogToOpen(); solo.waitForDialogToOpen();
solo.clickOnText(maxEntry); solo.clickOnText(maxEntry);
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> UserPreferences.getEpisodeCacheSize() == maxValue, Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return UserPreferences.getEpisodeCacheSize() == maxValue;
}
}, Timeout.getLargeTimeout());
} }
public void testAutomaticDownload() { public void testAutomaticDownload() {
@ -380,50 +249,20 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
solo.clickOnText(solo.getString(R.string.pref_automatic_download_title)); solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
solo.waitForText(solo.getString(R.string.pref_automatic_download_title)); solo.waitForText(solo.getString(R.string.pref_automatic_download_title));
solo.clickOnText(solo.getString(R.string.pref_automatic_download_title)); solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> automaticDownload != UserPreferences.isEnableAutodownload(), Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return automaticDownload != UserPreferences.isEnableAutodownload();
}
}, Timeout.getLargeTimeout());
if(UserPreferences.isEnableAutodownload() == false) { if(UserPreferences.isEnableAutodownload() == false) {
solo.clickOnText(solo.getString(R.string.pref_automatic_download_title)); solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
} }
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> UserPreferences.isEnableAutodownload() == true, Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return UserPreferences.isEnableAutodownload() == true;
}
}, Timeout.getLargeTimeout());
final boolean enableAutodownloadOnBattery = UserPreferences.isEnableAutodownloadOnBattery(); final boolean enableAutodownloadOnBattery = UserPreferences.isEnableAutodownloadOnBattery();
solo.clickOnText(solo.getString(R.string.pref_automatic_download_on_battery_title)); solo.clickOnText(solo.getString(R.string.pref_automatic_download_on_battery_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> enableAutodownloadOnBattery != UserPreferences.isEnableAutodownloadOnBattery(), Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return enableAutodownloadOnBattery != UserPreferences.isEnableAutodownloadOnBattery();
}
}, Timeout.getLargeTimeout());
solo.clickOnText(solo.getString(R.string.pref_automatic_download_on_battery_title)); solo.clickOnText(solo.getString(R.string.pref_automatic_download_on_battery_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> enableAutodownloadOnBattery == UserPreferences.isEnableAutodownloadOnBattery(), Timeout.getLargeTimeout()));
@Override
public boolean isSatisfied() {
return enableAutodownloadOnBattery == UserPreferences.isEnableAutodownloadOnBattery();
}
}, Timeout.getLargeTimeout());
final boolean enableWifiFilter = UserPreferences.isEnableAutodownloadWifiFilter(); final boolean enableWifiFilter = UserPreferences.isEnableAutodownloadWifiFilter();
solo.clickOnText(solo.getString(R.string.pref_autodl_wifi_filter_title)); solo.clickOnText(solo.getString(R.string.pref_autodl_wifi_filter_title));
solo.waitForCondition(new Condition() { assertTrue(solo.waitForCondition(() -> enableWifiFilter != UserPreferences.isEnableAutodownloadWifiFilter(), Timeout.getLargeTimeout()));
@Override solo.clickOnText(solo.getString(R.string.pref_autodl_wifi_filter_title));
public boolean isSatisfied() { assertTrue(solo.waitForCondition(() -> enableWifiFilter == UserPreferences.isEnableAutodownloadWifiFilter(), Timeout.getLargeTimeout()));
return enableWifiFilter != UserPreferences.isEnableAutodownloadWifiFilter();
}
}, Timeout.getLargeTimeout());
solo.clickOnText(solo.getString(R.string.pref_automatic_download_on_battery_title));
solo.waitForCondition(new Condition() {
@Override
public boolean isSatisfied() {
return enableWifiFilter == UserPreferences.isEnableAutodownloadWifiFilter();
}
}, Timeout.getLargeTimeout());
} }
} }