diff options
author | orionlee <orionlee@yahoo.com> | 2018-11-14 12:01:40 -0800 |
---|---|---|
committer | orionlee <orionlee@yahoo.com> | 2019-01-04 10:32:14 -0800 |
commit | 4ff5690341d6969f73010003d28b7a9e0d31f0c8 (patch) | |
tree | b9dc68cb754297bcf81ce86f465ebe3191944bb8 /core | |
parent | 1bb0694403460aedf0bd7a2839fe5d4e19842a6b (diff) | |
download | AntennaPod-4ff5690341d6969f73010003d28b7a9e0d31f0c8.zip |
episode cleanup 12 hour option: add unit test to prepare for using hours
rather than days as data structure
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java | 7 | ||||
-rw-r--r-- | core/src/test/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithmTest.java | 20 |
2 files changed, 26 insertions, 1 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java b/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java index 6d71bbc9f..3bec93d29 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java @@ -80,12 +80,17 @@ public class APCleanupAlgorithm extends EpisodeCleanupAlgorithm { return counter; } + @VisibleForTesting + Date calcMostRecentDateForDeletion(@NonNull Date currentDate) { + return minusDays(currentDate, numberOfDaysAfterPlayback); + } + @NonNull private List<FeedItem> getCandidates() { List<FeedItem> candidates = new ArrayList<>(); List<FeedItem> downloadedItems = DBReader.getDownloadedItems(); - Date mostRecentDateForDeletion = minusDays(new Date(), numberOfDaysAfterPlayback); + Date mostRecentDateForDeletion = calcMostRecentDateForDeletion(new Date()); for (FeedItem item : downloadedItems) { if (item.hasMedia() && item.getMedia().isDownloaded() diff --git a/core/src/test/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithmTest.java b/core/src/test/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithmTest.java new file mode 100644 index 000000000..dc4054af8 --- /dev/null +++ b/core/src/test/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithmTest.java @@ -0,0 +1,20 @@ +package de.danoeh.antennapod.core.storage; + +import org.junit.Test; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import static org.junit.Assert.assertEquals; + +public class APCleanupAlgorithmTest { + + @Test + public void testCalcMostRecentDateForDeletion() throws Exception { + APCleanupAlgorithm algo = new APCleanupAlgorithm(1.0f); + Date curDateForTest = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").parse("2018-11-13T14:08:56-0800"); + Date resExpected = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").parse("2018-11-12T14:08:56-0800"); + Date resActual = algo.calcMostRecentDateForDeletion(curDateForTest); + assertEquals("cutoff for retaining most recent 1 day", resExpected, resActual); + } +}
\ No newline at end of file |