diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2024-03-29 17:45:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-29 17:45:14 +0100 |
commit | 6f3a9b16764a57e43994ccbeeada5224dee93f44 (patch) | |
tree | 24bd2a3ed120dd61b009e5a2b5b9a1c550579997 /core/src/test/java/de | |
parent | 0c8c9a89a371d6515c34d1c4f7417c26059ee969 (diff) | |
download | AntennaPod-6f3a9b16764a57e43994ccbeeada5224dee93f44.zip |
Create module for sync service and move DBWriter to database module (#7040)
Diffstat (limited to 'core/src/test/java/de')
12 files changed, 26 insertions, 241 deletions
diff --git a/core/src/test/java/de/danoeh/antennapod/core/feed/LocalFeedUpdaterTest.java b/core/src/test/java/de/danoeh/antennapod/core/feed/LocalFeedUpdaterTest.java index 12256264a..9703894f5 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/feed/LocalFeedUpdaterTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/feed/LocalFeedUpdaterTest.java @@ -35,7 +35,7 @@ import java.util.Objects; import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.storage.database.DBReader; -import de.danoeh.antennapod.core.storage.DBWriter; +import de.danoeh.antennapod.storage.database.DBWriter; import static org.hamcrest.CoreMatchers.endsWith; import static org.hamcrest.CoreMatchers.is; diff --git a/core/src/test/java/de/danoeh/antennapod/core/storage/DbCleanupTests.java b/core/src/test/java/de/danoeh/antennapod/core/storage/DbCleanupTests.java index a7d435aed..a29a87b05 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/storage/DbCleanupTests.java +++ b/core/src/test/java/de/danoeh/antennapod/core/storage/DbCleanupTests.java @@ -15,6 +15,8 @@ import androidx.test.platform.app.InstrumentationRegistry; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; +import de.danoeh.antennapod.net.download.serviceinterface.AutoDownloadManager; +import de.danoeh.antennapod.storage.database.DBWriter; import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; import de.danoeh.antennapod.storage.preferences.SynchronizationSettings; import de.danoeh.antennapod.storage.preferences.UserPreferences; @@ -80,6 +82,7 @@ public class DbCleanupTests { UserPreferences.init(context); PlaybackPreferences.init(context); SynchronizationSettings.init(context); + AutoDownloadManager.setInstance(new AutoDownloadManagerImpl()); } @After @@ -108,7 +111,7 @@ public class DbCleanupTests { List<File> files = new ArrayList<>(); populateItems(numItems, feed, items, files, FeedItem.PLAYED, false, false); - AutoDownloadManager.performAutoCleanup(context); + AutoDownloadManager.getInstance().performAutoCleanup(context); for (int i = 0; i < files.size(); i++) { if (i < EPISODE_CACHE_SIZE) { assertTrue(files.get(i).exists()); @@ -167,7 +170,7 @@ public class DbCleanupTests { List<File> files = new ArrayList<>(); populateItems(numItems, feed, items, files, FeedItem.UNPLAYED, false, false); - AutoDownloadManager.performAutoCleanup(context); + AutoDownloadManager.getInstance().performAutoCleanup(context); for (File file : files) { assertTrue(file.exists()); } @@ -183,7 +186,7 @@ public class DbCleanupTests { List<File> files = new ArrayList<>(); populateItems(numItems, feed, items, files, FeedItem.PLAYED, true, false); - AutoDownloadManager.performAutoCleanup(context); + AutoDownloadManager.getInstance().performAutoCleanup(context); for (File file : files) { assertTrue(file.exists()); } @@ -223,7 +226,7 @@ public class DbCleanupTests { List<File> files = new ArrayList<>(); populateItems(numItems, feed, items, files, FeedItem.PLAYED, false, true); - AutoDownloadManager.performAutoCleanup(context); + AutoDownloadManager.getInstance().performAutoCleanup(context); for (File file : files) { assertTrue(file.exists()); } diff --git a/core/src/test/java/de/danoeh/antennapod/core/storage/DbNullCleanupAlgorithmTest.java b/core/src/test/java/de/danoeh/antennapod/core/storage/DbNullCleanupAlgorithmTest.java index 243bef941..bbcf362b9 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/storage/DbNullCleanupAlgorithmTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/storage/DbNullCleanupAlgorithmTest.java @@ -14,6 +14,8 @@ import androidx.test.platform.app.InstrumentationRegistry; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; +import de.danoeh.antennapod.net.download.serviceinterface.AutoDownloadManager; +import de.danoeh.antennapod.storage.database.DBWriter; import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.storage.database.PodDBAdapter; import org.junit.After; @@ -61,6 +63,7 @@ public class DbNullCleanupAlgorithmTest { prefEdit.commit(); UserPreferences.init(context); + AutoDownloadManager.setInstance(new AutoDownloadManagerImpl()); } @After @@ -114,7 +117,7 @@ public class DbNullCleanupAlgorithmTest { //noinspection ConstantConditions assertTrue(item.getMedia().getId() != 0); } - AutoDownloadManager.performAutoCleanup(context); + AutoDownloadManager.getInstance().performAutoCleanup(context); for (int i = 0; i < files.size(); i++) { assertTrue(files.get(i).exists()); } diff --git a/core/src/test/java/de/danoeh/antennapod/core/storage/DbQueueCleanupAlgorithmTest.java b/core/src/test/java/de/danoeh/antennapod/core/storage/DbQueueCleanupAlgorithmTest.java index c14c3c2aa..04762b123 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/storage/DbQueueCleanupAlgorithmTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/storage/DbQueueCleanupAlgorithmTest.java @@ -7,6 +7,7 @@ import java.util.List; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedItem; +import de.danoeh.antennapod.net.download.serviceinterface.AutoDownloadManager; import de.danoeh.antennapod.storage.preferences.UserPreferences; import org.junit.Test; @@ -24,6 +25,7 @@ public class DbQueueCleanupAlgorithmTest extends DbCleanupTests { public DbQueueCleanupAlgorithmTest() { setCleanupAlgorithm(UserPreferences.EPISODE_CLEANUP_QUEUE); + AutoDownloadManager.setInstance(new AutoDownloadManagerImpl()); } /** @@ -40,7 +42,7 @@ public class DbQueueCleanupAlgorithmTest extends DbCleanupTests { List<File> files = new ArrayList<>(); populateItems(numItems, feed, items, files, FeedItem.UNPLAYED, false, false); - AutoDownloadManager.performAutoCleanup(context); + AutoDownloadManager.getInstance().performAutoCleanup(context); for (int i = 0; i < files.size(); i++) { if (i < EPISODE_CACHE_SIZE) { assertTrue(files.get(i).exists()); diff --git a/core/src/test/java/de/danoeh/antennapod/core/storage/DbReaderTest.java b/core/src/test/java/de/danoeh/antennapod/core/storage/DbReaderTest.java index 99db467bf..d37e0d7e1 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/storage/DbReaderTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/storage/DbReaderTest.java @@ -19,6 +19,7 @@ import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.model.feed.FeedOrder; import de.danoeh.antennapod.model.feed.SortOrder; import de.danoeh.antennapod.storage.database.DBReader; +import de.danoeh.antennapod.storage.database.DBWriter; import de.danoeh.antennapod.storage.database.NavDrawerData; import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.storage.database.LongList; diff --git a/core/src/test/java/de/danoeh/antennapod/core/storage/DbTasksTest.java b/core/src/test/java/de/danoeh/antennapod/core/storage/DbTasksTest.java index 075e7a559..1f90dd7a9 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/storage/DbTasksTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/storage/DbTasksTest.java @@ -5,6 +5,8 @@ import android.content.Context; import androidx.test.platform.app.InstrumentationRegistry; import de.danoeh.antennapod.storage.database.DBReader; +import de.danoeh.antennapod.storage.database.DBWriter; +import de.danoeh.antennapod.storage.database.FeedDatabaseWriter; import de.danoeh.antennapod.storage.database.PodDBAdapter; import org.junit.After; import org.junit.Before; diff --git a/core/src/test/java/de/danoeh/antennapod/core/storage/DbWriterTest.java b/core/src/test/java/de/danoeh/antennapod/core/storage/DbWriterTest.java index 4fea67f79..90876cc11 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/storage/DbWriterTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/storage/DbWriterTest.java @@ -12,6 +12,7 @@ import androidx.test.platform.app.InstrumentationRegistry; import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterfaceStub; import de.danoeh.antennapod.storage.database.DBReader; +import de.danoeh.antennapod.storage.database.DBWriter; import de.danoeh.antennapod.storage.database.PodDBAdapter; import org.awaitility.Awaitility; import org.junit.After; diff --git a/core/src/test/java/de/danoeh/antennapod/core/storage/ExceptFavoriteCleanupAlgorithmTest.java b/core/src/test/java/de/danoeh/antennapod/core/storage/ExceptFavoriteCleanupAlgorithmTest.java index b464a2508..df26b9e4f 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/storage/ExceptFavoriteCleanupAlgorithmTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/storage/ExceptFavoriteCleanupAlgorithmTest.java @@ -1,5 +1,6 @@ package de.danoeh.antennapod.core.storage; +import de.danoeh.antennapod.net.download.serviceinterface.AutoDownloadManager; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; @@ -25,6 +26,7 @@ public class ExceptFavoriteCleanupAlgorithmTest extends DbCleanupTests { public ExceptFavoriteCleanupAlgorithmTest() { setCleanupAlgorithm(UserPreferences.EPISODE_CLEANUP_EXCEPT_FAVORITE); + AutoDownloadManager.setInstance(new AutoDownloadManagerImpl()); } @Test @@ -35,7 +37,7 @@ public class ExceptFavoriteCleanupAlgorithmTest extends DbCleanupTests { List<File> files = new ArrayList<>(); populateItems(numberOfItems, feed, items, files, FeedItem.UNPLAYED, false, false); - AutoDownloadManager.performAutoCleanup(context); + AutoDownloadManager.getInstance().performAutoCleanup(context); for (int i = 0; i < files.size(); i++) { if (i < EPISODE_CACHE_SIZE) { assertTrue("Only enough items should be deleted", files.get(i).exists()); @@ -53,7 +55,7 @@ public class ExceptFavoriteCleanupAlgorithmTest extends DbCleanupTests { List<File> files = new ArrayList<>(); populateItems(numberOfItems, feed, items, files, FeedItem.UNPLAYED, true, false); - AutoDownloadManager.performAutoCleanup(context); + AutoDownloadManager.getInstance().performAutoCleanup(context); for (int i = 0; i < files.size(); i++) { if (i < EPISODE_CACHE_SIZE) { assertTrue("Only enough items should be deleted", files.get(i).exists()); @@ -71,7 +73,7 @@ public class ExceptFavoriteCleanupAlgorithmTest extends DbCleanupTests { List<File> files = new ArrayList<>(); populateItems(numberOfItems, feed, items, files, FeedItem.UNPLAYED, false, true); - AutoDownloadManager.performAutoCleanup(context); + AutoDownloadManager.getInstance().performAutoCleanup(context); for (int i = 0; i < files.size(); i++) { assertTrue("Favorite episodes should should not be deleted", files.get(i).exists()); } diff --git a/core/src/test/java/de/danoeh/antennapod/core/storage/FeedItemDuplicateGuesserTest.java b/core/src/test/java/de/danoeh/antennapod/core/storage/FeedItemDuplicateGuesserTest.java index f3c993066..38dbe8caa 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/storage/FeedItemDuplicateGuesserTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/storage/FeedItemDuplicateGuesserTest.java @@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.storage; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; +import de.danoeh.antennapod.storage.database.FeedItemDuplicateGuesser; import org.junit.Test; import java.util.Date; diff --git a/core/src/test/java/de/danoeh/antennapod/core/storage/ItemEnqueuePositionCalculatorTest.java b/core/src/test/java/de/danoeh/antennapod/core/storage/ItemEnqueuePositionCalculatorTest.java index f0f81eee1..dfad714a8 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/storage/ItemEnqueuePositionCalculatorTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/storage/ItemEnqueuePositionCalculatorTest.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.core.storage; import de.danoeh.antennapod.model.playback.RemoteMedia; import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterfaceStub; +import de.danoeh.antennapod.storage.database.ItemEnqueuePositionCalculator; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; diff --git a/core/src/test/java/de/danoeh/antennapod/core/sync/EpisodeActionFilterTest.java b/core/src/test/java/de/danoeh/antennapod/core/sync/EpisodeActionFilterTest.java deleted file mode 100644 index 1f638bf32..000000000 --- a/core/src/test/java/de/danoeh/antennapod/core/sync/EpisodeActionFilterTest.java +++ /dev/null @@ -1,212 +0,0 @@ -package de.danoeh.antennapod.core.sync; - - -import androidx.core.util.Pair; - -import junit.framework.TestCase; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import de.danoeh.antennapod.net.sync.model.EpisodeAction; - - -public class EpisodeActionFilterTest extends TestCase { - - EpisodeActionFilter episodeActionFilter = new EpisodeActionFilter(); - - public void testGetRemoteActionsHappeningAfterLocalActions() throws ParseException { - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date morning = format.parse("2021-01-01 08:00:00"); - Date lateMorning = format.parse("2021-01-01 09:00:00"); - - List<EpisodeAction> episodeActions = new ArrayList<>(); - episodeActions.add(new EpisodeAction - .Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY) - .timestamp(morning) - .position(10) - .build() - ); - episodeActions.add(new EpisodeAction - .Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY) - .timestamp(lateMorning) - .position(20) - .build() - ); - episodeActions.add(new EpisodeAction - .Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY) - .timestamp(morning) - .position(5) - .build() - ); - - Date morningFiveMinutesLater = format.parse("2021-01-01 08:05:00"); - List<EpisodeAction> remoteActions = new ArrayList<>(); - remoteActions.add(new EpisodeAction - .Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY) - .timestamp(morningFiveMinutesLater) - .position(10) - .build() - ); - remoteActions.add(new EpisodeAction - .Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY) - .timestamp(morningFiveMinutesLater) - .position(5) - .build() - ); - - Map<Pair<String, String>, EpisodeAction> uniqueList = episodeActionFilter - .getRemoteActionsOverridingLocalActions(remoteActions, episodeActions); - assertSame(1, uniqueList.size()); - } - - public void testGetRemoteActionsHappeningBeforeLocalActions() throws ParseException { - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date morning = format.parse("2021-01-01 08:00:00"); - Date lateMorning = format.parse("2021-01-01 09:00:00"); - - List<EpisodeAction> episodeActions = new ArrayList<>(); - episodeActions.add(new EpisodeAction - .Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY) - .timestamp(morning) - .position(10) - .build() - ); - episodeActions.add(new EpisodeAction - .Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY) - .timestamp(lateMorning) - .position(20) - .build() - ); - episodeActions.add(new EpisodeAction - .Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY) - .timestamp(morning) - .position(5) - .build() - ); - - Date morningFiveMinutesEarlier = format.parse("2021-01-01 07:55:00"); - List<EpisodeAction> remoteActions = new ArrayList<>(); - remoteActions.add(new EpisodeAction - .Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY) - .timestamp(morningFiveMinutesEarlier) - .position(10) - .build() - ); - remoteActions.add(new EpisodeAction - .Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY) - .timestamp(morningFiveMinutesEarlier) - .position(5) - .build() - ); - - Map<Pair<String, String>, EpisodeAction> uniqueList = episodeActionFilter - .getRemoteActionsOverridingLocalActions(remoteActions, episodeActions); - assertSame(0, uniqueList.size()); - } - - public void testGetMultipleRemoteActionsHappeningAfterLocalActions() throws ParseException { - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date morning = format.parse("2021-01-01 08:00:00"); - - List<EpisodeAction> episodeActions = new ArrayList<>(); - episodeActions.add(new EpisodeAction - .Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY) - .timestamp(morning) - .position(10) - .build() - ); - episodeActions.add(new EpisodeAction - .Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY) - .timestamp(morning) - .position(5) - .build() - ); - - Date morningFiveMinutesLater = format.parse("2021-01-01 08:05:00"); - List<EpisodeAction> remoteActions = new ArrayList<>(); - remoteActions.add(new EpisodeAction - .Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY) - .timestamp(morningFiveMinutesLater) - .position(10) - .build() - ); - remoteActions.add(new EpisodeAction - .Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY) - .timestamp(morningFiveMinutesLater) - .position(5) - .build() - ); - - Map<Pair<String, String>, EpisodeAction> uniqueList = episodeActionFilter - .getRemoteActionsOverridingLocalActions(remoteActions, episodeActions); - assertEquals(2, uniqueList.size()); - } - - public void testGetMultipleRemoteActionsHappeningBeforeLocalActions() throws ParseException { - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date morning = format.parse("2021-01-01 08:00:00"); - - List<EpisodeAction> episodeActions = new ArrayList<>(); - episodeActions.add(new EpisodeAction - .Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY) - .timestamp(morning) - .position(10) - .build() - ); - episodeActions.add(new EpisodeAction - .Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY) - .timestamp(morning) - .position(5) - .build() - ); - - Date morningFiveMinutesEarlier = format.parse("2021-01-01 07:55:00"); - List<EpisodeAction> remoteActions = new ArrayList<>(); - remoteActions.add(new EpisodeAction - .Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY) - .timestamp(morningFiveMinutesEarlier) - .position(10) - .build() - ); - remoteActions.add(new EpisodeAction - .Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY) - .timestamp(morningFiveMinutesEarlier) - .position(5) - .build() - ); - - Map<Pair<String, String>, EpisodeAction> uniqueList = episodeActionFilter - .getRemoteActionsOverridingLocalActions(remoteActions, episodeActions); - assertEquals(0, uniqueList.size()); - } - - public void testPresentRemoteTimestampOverridesMissingLocalTimestamp() throws ParseException { - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date arbitraryTime = format.parse("2021-01-01 08:00:00"); - - List<EpisodeAction> episodeActions = new ArrayList<>(); - episodeActions.add(new EpisodeAction - .Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY) - // no timestamp - .position(10) - .build() - ); - - List<EpisodeAction> remoteActions = new ArrayList<>(); - remoteActions.add(new EpisodeAction - .Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY) - .timestamp(arbitraryTime) - .position(10) - .build() - ); - - Map<Pair<String, String>, EpisodeAction> uniqueList = episodeActionFilter - .getRemoteActionsOverridingLocalActions(remoteActions, episodeActions); - assertSame(1, uniqueList.size()); - } -} diff --git a/core/src/test/java/de/danoeh/antennapod/core/sync/GuidValidatorTest.java b/core/src/test/java/de/danoeh/antennapod/core/sync/GuidValidatorTest.java deleted file mode 100644 index 552f7d70a..000000000 --- a/core/src/test/java/de/danoeh/antennapod/core/sync/GuidValidatorTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.danoeh.antennapod.core.sync; - -import junit.framework.TestCase; - -public class GuidValidatorTest extends TestCase { - - public void testIsValidGuid() { - assertTrue(GuidValidator.isValidGuid("skfjsdvgsd")); - } - - public void testIsInvalidGuid() { - assertFalse(GuidValidator.isValidGuid("")); - assertFalse(GuidValidator.isValidGuid(" ")); - assertFalse(GuidValidator.isValidGuid("\n")); - assertFalse(GuidValidator.isValidGuid(" \n")); - assertFalse(GuidValidator.isValidGuid(null)); - assertFalse(GuidValidator.isValidGuid("null")); - } -}
\ No newline at end of file |