diff options
author | orionlee <orionlee@yahoo.com> | 2019-10-24 12:00:14 -0700 |
---|---|---|
committer | orionlee <orionlee@yahoo.com> | 2019-10-24 12:03:22 -0700 |
commit | bcd4b49dda0a75bb61396ee4c4ab5521c5dc0c26 (patch) | |
tree | 83d7c54a40213cedb87817ab13b4a6016d40fa18 /core/src/test/java | |
parent | 306b6f30a4c416445886af33954fac20dbc29f22 (diff) | |
download | AntennaPod-bcd4b49dda0a75bb61396ee4c4ab5521c5dc0c26.zip |
feeditem sort - handle boundary conditions
Diffstat (limited to 'core/src/test/java')
-rw-r--r-- | core/src/test/java/de/danoeh/antennapod/core/util/FeedItemPermutorsTest.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/core/src/test/java/de/danoeh/antennapod/core/util/FeedItemPermutorsTest.java b/core/src/test/java/de/danoeh/antennapod/core/util/FeedItemPermutorsTest.java index 82b3a794e..f66c77c3d 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/util/FeedItemPermutorsTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/util/FeedItemPermutorsTest.java @@ -10,6 +10,7 @@ import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; /** @@ -18,6 +19,14 @@ import static org.junit.Assert.assertTrue; public class FeedItemPermutorsTest { @Test + public void testEnsureNonNullPermutors() { + for(SortOrder sortOrder : SortOrder.values()) { + assertNotNull("The permutor for SortOrder " + sortOrder + " is unexpectedly null", + FeedItemPermutors.getPermutor(sortOrder)); + } + } + + @Test public void testPermutorForRule_EPISODE_TITLE_ASC() { Permutor<FeedItem> permutor = FeedItemPermutors.getPermutor(SortOrder.EPISODE_TITLE_A_Z); @@ -28,6 +37,19 @@ public class FeedItemPermutorsTest { } @Test + public void testPermutorForRule_EPISODE_TITLE_ASC_NullTitle() { + Permutor<FeedItem> permutor = FeedItemPermutors.getPermutor(SortOrder.EPISODE_TITLE_A_Z); + + List<FeedItem> itemList = getTestList(); + itemList.get(2) // itemId 2 + .setTitle(null); + assertTrue(checkIdOrder(itemList, 1, 3, 2)); // before sorting + permutor.reorder(itemList); + assertTrue(checkIdOrder(itemList, 2, 1, 3)); // after sorting + } + + + @Test public void testPermutorForRule_EPISODE_TITLE_DESC() { Permutor<FeedItem> permutor = FeedItemPermutors.getPermutor(SortOrder.EPISODE_TITLE_Z_A); @@ -48,6 +70,18 @@ public class FeedItemPermutorsTest { } @Test + public void testPermutorForRule_DATE_ASC_NulPubDatel() { + Permutor<FeedItem> permutor = FeedItemPermutors.getPermutor(SortOrder.DATE_OLD_NEW); + + List<FeedItem> itemList = getTestList(); + itemList.get(2) // itemId 2 + .setPubDate(null); + assertTrue(checkIdOrder(itemList, 1, 3, 2)); // before sorting + permutor.reorder(itemList); + assertTrue(checkIdOrder(itemList, 2, 1, 3)); // after sorting + } + + @Test public void testPermutorForRule_DATE_DESC() { Permutor<FeedItem> permutor = FeedItemPermutors.getPermutor(SortOrder.DATE_NEW_OLD); @@ -78,6 +112,18 @@ public class FeedItemPermutorsTest { } @Test + public void testPermutorForRule_DURATION_DESC_NullMedia() { + Permutor<FeedItem> permutor = FeedItemPermutors.getPermutor(SortOrder.DURATION_LONG_SHORT); + + List<FeedItem> itemList = getTestList(); + itemList.get(1) // itemId 3 + .setMedia(null); + assertTrue(checkIdOrder(itemList, 1, 3, 2)); // before sorting + permutor.reorder(itemList); + assertTrue(checkIdOrder(itemList, 2, 1, 3)); // after sorting + } + + @Test public void testPermutorForRule_FEED_TITLE_ASC() { Permutor<FeedItem> permutor = FeedItemPermutors.getPermutor(SortOrder.FEED_TITLE_A_Z); @@ -97,6 +143,18 @@ public class FeedItemPermutorsTest { assertTrue(checkIdOrder(itemList, 3, 2, 1)); // after sorting } + @Test + public void testPermutorForRule_FEED_TITLE_DESC_NullTitle() { + Permutor<FeedItem> permutor = FeedItemPermutors.getPermutor(SortOrder.FEED_TITLE_Z_A); + + List<FeedItem> itemList = getTestList(); + itemList.get(1) // itemId 3 + .getFeed().setTitle(null); + assertTrue(checkIdOrder(itemList, 1, 3, 2)); // before sorting + permutor.reorder(itemList); + assertTrue(checkIdOrder(itemList, 2, 1, 3)); // after sorting + } + /** * Generates a list with test data. */ |