refactor extract common FeedItem List to IDs method
This commit is contained in:
parent
69c0022472
commit
d24669d4c1
@ -14,7 +14,6 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.danoeh.antennapod.core.feed.Feed;
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
@ -25,6 +24,7 @@ import de.danoeh.antennapod.core.storage.DBTasks;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||
|
||||
import static de.danoeh.antennapod.core.util.FeedItemUtil.getIdList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@ -237,15 +237,11 @@ public class DBTasksTest {
|
||||
|
||||
private void assertEqualsByIds(String msg, List<? extends FeedItem> expected, List<? extends FeedItem> actual) {
|
||||
// assert only the IDs, so that any differences are easily to spot.
|
||||
List<Long> expectedIds = toIds(expected);
|
||||
List<Long> actualIds = toIds(actual);
|
||||
List<Long> expectedIds = getIdList(expected);
|
||||
List<Long> actualIds = getIdList(actual);
|
||||
assertEquals(msg, expectedIds, actualIds);
|
||||
}
|
||||
|
||||
private static List<Long> toIds(List<? extends FeedItem> items) {
|
||||
return items.stream().map(FeedItem::getId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Feed createSavedFeed(String title, int numFeedItems) {
|
||||
final Feed feed = new Feed("url", null, title);
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
package de.danoeh.antennapod.core.util;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
@ -40,6 +43,15 @@ public class FeedItemUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static List<Long> getIdList(List<? extends FeedItem> items) {
|
||||
List<Long> result = new ArrayList<>();
|
||||
for (FeedItem item : items) {
|
||||
result.add(item.getId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the link for the feed item for the purpose of Share. It fallbacks to
|
||||
* use the feed's link if the named feed item has no link.
|
||||
|
@ -18,6 +18,7 @@ import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.feed.FeedMother;
|
||||
import de.danoeh.antennapod.core.storage.ItemEnqueuePositionCalculator.Options;
|
||||
|
||||
import static de.danoeh.antennapod.core.util.FeedItemUtil.getIdList;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@ -122,10 +123,10 @@ public class ItemEnqueuePositionCalculatorTest {
|
||||
}
|
||||
|
||||
private static final List<FeedItem> QUEUE_FRONT_IN_PROGRESS = Arrays.asList(tFI(11, 60000), tFI(12), tFI(13));
|
||||
private static final List<Long> QUEUE_FRONT_IN_PROGRESS_IDS = toIDs(QUEUE_FRONT_IN_PROGRESS);
|
||||
private static final List<Long> QUEUE_FRONT_IN_PROGRESS_IDS = getIdList(QUEUE_FRONT_IN_PROGRESS);
|
||||
|
||||
private static final List<FeedItem> QUEUE_FRONT_NO_MEDIA = Arrays.asList(tFINoMedia(11), tFI(12), tFI(13));
|
||||
private static final List<Long> QUEUE_FRONT_NO_MEDIA_IDS = toIDs(QUEUE_FRONT_NO_MEDIA);
|
||||
private static final List<Long> QUEUE_FRONT_NO_MEDIA_IDS = getIdList(QUEUE_FRONT_NO_MEDIA);
|
||||
|
||||
}
|
||||
|
||||
@ -249,7 +250,7 @@ public class ItemEnqueuePositionCalculatorTest {
|
||||
List<Long> idsExpected) {
|
||||
int posActual = calculator.calcPosition(positionAmongAdd, itemToAdd, queue);
|
||||
queue.add(posActual, itemToAdd);
|
||||
assertEquals(message, idsExpected, toIDs(queue));
|
||||
assertEquals(message, idsExpected, getIdList(queue));
|
||||
}
|
||||
|
||||
static final List<FeedItem> QUEUE_EMPTY = Collections.unmodifiableList(Arrays.asList());
|
||||
@ -306,8 +307,4 @@ public class ItemEnqueuePositionCalculatorTest {
|
||||
}
|
||||
|
||||
|
||||
static List<Long> toIDs(List<FeedItem> items) {
|
||||
return items.stream().map(i->i.getId()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user