More test cleanup
This commit is contained in:
parent
9dc0297c7f
commit
2e0c8d1bab
|
@ -12,6 +12,9 @@ import android.support.test.espresso.util.HumanReadables;
|
|||
import android.support.test.espresso.util.TreeIterables;
|
||||
import android.view.View;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||
import de.danoeh.antennapod.dialog.RatingDialog;
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -74,7 +77,7 @@ public class EspressoTestUtils {
|
|||
/**
|
||||
* Clear all app databases
|
||||
*/
|
||||
public static void clearAppData() {
|
||||
public static void clearPreferences() {
|
||||
File root = InstrumentationRegistry.getTargetContext().getFilesDir().getParentFile();
|
||||
String[] sharedPreferencesFileNames = new File(root, "shared_prefs").list();
|
||||
for (String fileName : sharedPreferencesFileNames) {
|
||||
|
@ -84,6 +87,24 @@ public class EspressoTestUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static void makeNotFirstRun() {
|
||||
InstrumentationRegistry.getTargetContext().getSharedPreferences(MainActivity.PREF_NAME, Context.MODE_PRIVATE)
|
||||
.edit()
|
||||
.putBoolean(MainActivity.PREF_IS_FIRST_LAUNCH, false)
|
||||
.commit();
|
||||
|
||||
RatingDialog.init(InstrumentationRegistry.getTargetContext());
|
||||
RatingDialog.saveRated();
|
||||
}
|
||||
|
||||
public static void clearDatabase() {
|
||||
PodDBAdapter.init(InstrumentationRegistry.getTargetContext());
|
||||
PodDBAdapter.deleteDatabase();
|
||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||
adapter.open();
|
||||
adapter.close();
|
||||
}
|
||||
|
||||
public static void clickPreference(@StringRes int title) {
|
||||
onView(withId(R.id.list)).perform(
|
||||
RecyclerViewActions.actionOnItem(hasDescendant(withText(title)),
|
||||
|
|
|
@ -63,15 +63,11 @@ public class PlaybackServiceMediaPlayerTest {
|
|||
@Before
|
||||
public void setUp() throws Exception {
|
||||
assertionError = null;
|
||||
EspressoTestUtils.clearAppData();
|
||||
final Context context = InstrumentationRegistry.getTargetContext();
|
||||
EspressoTestUtils.clearPreferences();
|
||||
EspressoTestUtils.makeNotFirstRun();
|
||||
EspressoTestUtils.clearDatabase();
|
||||
|
||||
// create new database
|
||||
PodDBAdapter.init(context);
|
||||
PodDBAdapter.deleteDatabase();
|
||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||
adapter.open();
|
||||
adapter.close();
|
||||
final Context context = InstrumentationRegistry.getTargetContext();
|
||||
|
||||
httpServer = new HTTPBin();
|
||||
httpServer.start();
|
||||
|
|
|
@ -43,45 +43,28 @@ public class MainActivityTest {
|
|||
|
||||
private Solo solo;
|
||||
private UITestUtils uiTestUtils;
|
||||
private SharedPreferences prefs;
|
||||
|
||||
@Rule
|
||||
public IntentsTestRule<MainActivity> mActivityRule = new IntentsTestRule<>(MainActivity.class, false, false);
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
// override first launch preference
|
||||
// do this BEFORE calling getActivity()!
|
||||
EspressoTestUtils.clearAppData();
|
||||
prefs = InstrumentationRegistry.getContext()
|
||||
.getSharedPreferences(MainActivity.PREF_NAME, Context.MODE_PRIVATE);
|
||||
prefs.edit().putBoolean(MainActivity.PREF_IS_FIRST_LAUNCH, false).commit();
|
||||
EspressoTestUtils.clearPreferences();
|
||||
EspressoTestUtils.makeNotFirstRun();
|
||||
EspressoTestUtils.clearDatabase();
|
||||
|
||||
mActivityRule.launchActivity(new Intent());
|
||||
|
||||
Context context = mActivityRule.getActivity();
|
||||
uiTestUtils = new UITestUtils(context);
|
||||
uiTestUtils = new UITestUtils(InstrumentationRegistry.getTargetContext());
|
||||
uiTestUtils.setup();
|
||||
|
||||
// create new database
|
||||
PodDBAdapter.init(context);
|
||||
PodDBAdapter.deleteDatabase();
|
||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||
adapter.open();
|
||||
adapter.close();
|
||||
|
||||
RatingDialog.init(context);
|
||||
RatingDialog.saveRated();
|
||||
|
||||
solo = new Solo(getInstrumentation(), mActivityRule.getActivity());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
uiTestUtils.tearDown();
|
||||
solo.finishOpenedActivities();
|
||||
PodDBAdapter.deleteDatabase();
|
||||
prefs.edit().clear().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -89,13 +72,10 @@ public class MainActivityTest {
|
|||
uiTestUtils.addHostedFeedData();
|
||||
final Feed feed = uiTestUtils.hostedFeeds.get(0);
|
||||
openNavDrawer();
|
||||
solo.clickOnText(solo.getString(R.string.add_feed_label));
|
||||
onView(withText(R.string.add_feed_label)).perform(click());
|
||||
solo.enterText(1, feed.getDownload_url());
|
||||
solo.clickOnButton(solo.getString(R.string.confirm_label));
|
||||
solo.waitForActivity(OnlineFeedViewActivity.class);
|
||||
solo.waitForView(R.id.butSubscribe);
|
||||
assertEquals(solo.getString(R.string.subscribe_label), solo.getButton(0).getText().toString());
|
||||
solo.clickOnButton(0);
|
||||
onView(withText(R.string.confirm_label)).perform(click());
|
||||
onView(withText(R.string.subscribe_label)).perform(click());
|
||||
assertTrue(solo.waitForText(solo.getString(R.string.open_podcast), 0, Timeout.getLargeTimeout(), false));
|
||||
}
|
||||
|
||||
|
@ -115,7 +95,6 @@ public class MainActivityTest {
|
|||
onView(withText(R.string.confirm_label)).perform(click());
|
||||
|
||||
solo.goBackToActivity(MainActivity.class.getSimpleName());
|
||||
solo.goBack(); // Close nav drawer
|
||||
solo.goBack();
|
||||
assertEquals(solo.getString(R.string.subscriptions_label), getActionbarTitle());
|
||||
}
|
||||
|
@ -128,7 +107,6 @@ public class MainActivityTest {
|
|||
clickPreference(R.string.pref_back_button_behavior_title);
|
||||
onView(withText(R.string.back_button_open_drawer)).perform(click());
|
||||
solo.goBackToActivity(MainActivity.class.getSimpleName());
|
||||
solo.goBack(); // Close nav drawer
|
||||
solo.goBack();
|
||||
assertTrue(((MainActivity)solo.getCurrentActivity()).isDrawerOpen());
|
||||
}
|
||||
|
@ -141,7 +119,6 @@ public class MainActivityTest {
|
|||
clickPreference(R.string.pref_back_button_behavior_title);
|
||||
onView(withText(R.string.back_button_double_tap)).perform(click());
|
||||
solo.goBackToActivity(MainActivity.class.getSimpleName());
|
||||
solo.goBack(); // Close nav drawer
|
||||
solo.goBack();
|
||||
solo.goBack();
|
||||
assertThat(mActivityRule.getActivityResult(), hasResultCode(Activity.RESULT_CANCELED));
|
||||
|
@ -155,7 +132,6 @@ public class MainActivityTest {
|
|||
clickPreference(R.string.pref_back_button_behavior_title);
|
||||
onView(withText(R.string.back_button_show_prompt)).perform(click());
|
||||
solo.goBackToActivity(MainActivity.class.getSimpleName());
|
||||
solo.goBack(); // Close nav drawer
|
||||
solo.goBack();
|
||||
onView(withText(R.string.yes)).perform(click());
|
||||
Thread.sleep(100);
|
||||
|
@ -170,7 +146,6 @@ public class MainActivityTest {
|
|||
clickPreference(R.string.pref_back_button_behavior_title);
|
||||
onView(withText(R.string.back_button_default)).perform(click());
|
||||
solo.goBackToActivity(MainActivity.class.getSimpleName());
|
||||
solo.goBack(); // Close nav drawer
|
||||
solo.goBack();
|
||||
assertThat(mActivityRule.getActivityResult(), hasResultCode(Activity.RESULT_CANCELED));
|
||||
}
|
||||
|
|
|
@ -64,20 +64,9 @@ public class NavigationDrawerTest {
|
|||
uiTestUtils = new UITestUtils(InstrumentationRegistry.getTargetContext());
|
||||
uiTestUtils.setup();
|
||||
|
||||
EspressoTestUtils.clearAppData();
|
||||
|
||||
Context context = InstrumentationRegistry.getTargetContext();
|
||||
SharedPreferences prefs = context.getSharedPreferences(MainActivity.PREF_NAME, Context.MODE_PRIVATE);
|
||||
prefs.edit().putBoolean(MainActivity.PREF_IS_FIRST_LAUNCH, false).commit();
|
||||
|
||||
RatingDialog.init(context);
|
||||
RatingDialog.saveRated();
|
||||
|
||||
PodDBAdapter.init(context);
|
||||
PodDBAdapter.deleteDatabase();
|
||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||
adapter.open();
|
||||
adapter.close();
|
||||
EspressoTestUtils.clearPreferences();
|
||||
EspressoTestUtils.makeNotFirstRun();
|
||||
EspressoTestUtils.clearDatabase();
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
|
@ -52,12 +52,11 @@ public class PlaybackSonicTest {
|
|||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
EspressoTestUtils.clearAppData();
|
||||
EspressoTestUtils.clearPreferences();
|
||||
EspressoTestUtils.makeNotFirstRun();
|
||||
EspressoTestUtils.clearDatabase();
|
||||
context = InstrumentationRegistry.getTargetContext();
|
||||
|
||||
PodDBAdapter.init(context);
|
||||
PodDBAdapter.deleteDatabase();
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
prefs.edit()
|
||||
.clear()
|
||||
|
@ -71,11 +70,6 @@ public class PlaybackSonicTest {
|
|||
|
||||
uiTestUtils = new UITestUtils(context);
|
||||
uiTestUtils.setup();
|
||||
|
||||
// create database
|
||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||
adapter.open();
|
||||
adapter.close();
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
|
@ -49,7 +49,7 @@ public class PreferencesTest {
|
|||
|
||||
@Before
|
||||
public void setUp() {
|
||||
EspressoTestUtils.clearAppData();
|
||||
EspressoTestUtils.clearPreferences();
|
||||
mActivityRule.launchActivity(new Intent());
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mActivityRule.getActivity());
|
||||
prefs.edit().putBoolean(UserPreferences.PREF_ENABLE_AUTODL, true).commit();
|
||||
|
|
Loading…
Reference in New Issue