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 getCandidates() { List candidates = new ArrayList<>(); List 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