episode cleanup 12 hour option: add unit test to prepare for using hours

rather than days as data structure
This commit is contained in:
orionlee 2018-11-14 12:01:40 -08:00
parent 1bb0694403
commit 4ff5690341
2 changed files with 26 additions and 1 deletions

View File

@ -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()

View File

@ -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);
}
}