From 90b8655ee92822387ff08b74a3ae8f3856f1556e Mon Sep 17 00:00:00 2001 From: Herbert Reiter <46045854+damoasda@users.noreply.github.com> Date: Wed, 30 Dec 2020 10:59:43 +0100 Subject: [PATCH] Run ExternalMediaTest with Robolectric --- .../util/playback}/ExternalMediaTest.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) rename {app/src/androidTest/java/de/test/antennapod/entities => core/src/test/java/de/danoeh/antennapod/core/util/playback}/ExternalMediaTest.java (75%) diff --git a/app/src/androidTest/java/de/test/antennapod/entities/ExternalMediaTest.java b/core/src/test/java/de/danoeh/antennapod/core/util/playback/ExternalMediaTest.java similarity index 75% rename from app/src/androidTest/java/de/test/antennapod/entities/ExternalMediaTest.java rename to core/src/test/java/de/danoeh/antennapod/core/util/playback/ExternalMediaTest.java index 70df82fec..d5e63eeba 100644 --- a/app/src/androidTest/java/de/test/antennapod/entities/ExternalMediaTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/util/playback/ExternalMediaTest.java @@ -1,28 +1,31 @@ -package de.test.antennapod.entities; +package de.danoeh.antennapod.core.util.playback; import android.annotation.SuppressLint; +import android.content.Context; import android.content.SharedPreferences; import androidx.preference.PreferenceManager; import androidx.test.platform.app.InstrumentationRegistry; -import androidx.test.filters.SmallTest; import de.danoeh.antennapod.core.feed.MediaType; -import de.danoeh.antennapod.core.util.playback.ExternalMedia; import org.junit.After; import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; import static org.junit.Assert.assertEquals; /** * Tests for {@link ExternalMedia} entity. */ -@SmallTest +@RunWith(RobolectricTestRunner.class) public class ExternalMediaTest { private static final int NOT_SET = -1; + private static final int POSITION = 50; + private static final int LAST_PLAYED_TIME = 1650; @After - public void tearDown() throws Exception { + public void tearDown() { clearSharedPrefs(); } @@ -35,14 +38,12 @@ public class ExternalMediaTest { } private SharedPreferences getDefaultSharedPrefs() { - return PreferenceManager.getDefaultSharedPreferences(InstrumentationRegistry.getInstrumentation().getTargetContext()); + Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); + return PreferenceManager.getDefaultSharedPreferences(context); } @Test public void testSaveCurrentPositionUpdatesPreferences() { - final int POSITION = 50; - final int LAST_PLAYED_TIME = 1650; - assertEquals(NOT_SET, getDefaultSharedPrefs().getInt(ExternalMedia.PREF_POSITION, NOT_SET)); assertEquals(NOT_SET, getDefaultSharedPrefs().getLong(ExternalMedia.PREF_LAST_PLAYED_TIME, NOT_SET));