diff --git a/app/src/androidTest/java/de/test/antennapod/feed/FeedItemTest.java b/app/src/androidTest/java/de/test/antennapod/feed/FeedItemTest.java deleted file mode 100644 index 0b9a67d0a..000000000 --- a/app/src/androidTest/java/de/test/antennapod/feed/FeedItemTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package de.test.antennapod.feed; - -import androidx.test.filters.SmallTest; -import de.danoeh.antennapod.core.feed.FeedItem; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -@SmallTest -public class FeedItemTest { - private static final String TEXT_LONG = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; - private static final String TEXT_SHORT = "Lorem ipsum"; - - /** - * If one of `description` or `content:encoded` is null, use the other one. - */ - @Test - public void testShownotesNullValues() throws Exception { - testShownotes(null, TEXT_LONG); - testShownotes(TEXT_LONG, null); - } - - /** - * If `description` is reasonably longer than `content:encoded`, use `description`. - */ - @Test - public void testShownotesLength() throws Exception { - testShownotes(TEXT_SHORT, TEXT_LONG); - testShownotes(TEXT_LONG, TEXT_SHORT); - } - - /** - * Checks if the shownotes equal TEXT_LONG, using the given `description` and `content:encoded` - * @param description Description of the feed item - * @param contentEncoded `content:encoded` of the feed item - */ - private void testShownotes(String description, String contentEncoded) throws Exception { - FeedItem item = new FeedItem(); - item.setDescription(description); - item.setContentEncoded(contentEncoded); - assertEquals(TEXT_LONG, item.loadShownotes().call()); - } -} diff --git a/app/src/androidTest/java/de/test/antennapod/feed/FeedFilterTest.java b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedFilterTest.java similarity index 88% rename from app/src/androidTest/java/de/test/antennapod/feed/FeedFilterTest.java rename to core/src/test/java/de/danoeh/antennapod/core/feed/FeedFilterTest.java index fc2943205..8b4a13473 100644 --- a/app/src/androidTest/java/de/test/antennapod/feed/FeedFilterTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedFilterTest.java @@ -1,19 +1,15 @@ -package de.test.antennapod.feed; +package de.danoeh.antennapod.core.feed; -import androidx.test.filters.SmallTest; -import de.danoeh.antennapod.core.feed.FeedFilter; -import de.danoeh.antennapod.core.feed.FeedItem; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -@SmallTest public class FeedFilterTest { @Test - public void testNullFilter() throws Exception { + public void testNullFilter() { FeedFilter filter = new FeedFilter(); FeedItem item = new FeedItem(); item.setTitle("Hello world"); @@ -26,7 +22,7 @@ public class FeedFilterTest { } @Test - public void testBasicIncludeFilter() throws Exception { + public void testBasicIncludeFilter() { String includeFilter = "Hello"; FeedFilter filter = new FeedFilter(includeFilter, ""); FeedItem item = new FeedItem(); @@ -44,7 +40,7 @@ public class FeedFilterTest { } @Test - public void testBasicExcludeFilter() throws Exception { + public void testBasicExcludeFilter() { String excludeFilter = "Hello"; FeedFilter filter = new FeedFilter("", excludeFilter); FeedItem item = new FeedItem(); @@ -62,7 +58,7 @@ public class FeedFilterTest { } @Test - public void testComplexIncludeFilter() throws Exception { + public void testComplexIncludeFilter() { String includeFilter = "Hello \n\"Two words\""; FeedFilter filter = new FeedFilter(includeFilter, ""); FeedItem item = new FeedItem(); @@ -84,7 +80,7 @@ public class FeedFilterTest { } @Test - public void testComplexExcludeFilter() throws Exception { + public void testComplexExcludeFilter() { String excludeFilter = "Hello \"Two words\""; FeedFilter filter = new FeedFilter("", excludeFilter); FeedItem item = new FeedItem(); @@ -106,7 +102,7 @@ public class FeedFilterTest { } @Test - public void testComboFilter() throws Exception { + public void testComboFilter() { String includeFilter = "Hello world"; String excludeFilter = "dislike"; FeedFilter filter = new FeedFilter(includeFilter, excludeFilter); diff --git a/core/src/test/java/de/danoeh/antennapod/core/feed/FeedItemTest.java b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedItemTest.java index 6bd753561..5bcbed97a 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/feed/FeedItemTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedItemTest.java @@ -2,16 +2,23 @@ package de.danoeh.antennapod.core.feed; import org.junit.Before; import org.junit.Test; +import org.mockito.MockedStatic; +import org.mockito.Mockito; import java.text.SimpleDateFormat; import java.util.Date; +import de.danoeh.antennapod.core.storage.DBReader; + import static de.danoeh.antennapod.core.feed.FeedItemMother.anyFeedItemWithImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; public class FeedItemTest { + private static final String TEXT_LONG = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; + private static final String TEXT_SHORT = "Lorem ipsum"; + private FeedItem original; private FeedItem changedFeedItem; @@ -22,21 +29,21 @@ public class FeedItemTest { } @Test - public void testUpdateFromOther_feedItemImageDownloadUrlChanged() throws Exception { + public void testUpdateFromOther_feedItemImageDownloadUrlChanged() { setNewFeedItemImageDownloadUrl(); original.updateFromOther(changedFeedItem); assertFeedItemImageWasUpdated(); } @Test - public void testUpdateFromOther_feedItemImageRemoved() throws Exception { + public void testUpdateFromOther_feedItemImageRemoved() { feedItemImageRemoved(); original.updateFromOther(changedFeedItem); assertFeedItemImageWasNotUpdated(); } @Test - public void testUpdateFromOther_feedItemImageAdded() throws Exception { + public void testUpdateFromOther_feedItemImageAdded() { original.setImageUrl(null); setNewFeedItemImageDownloadUrl(); original.updateFromOther(changedFeedItem); @@ -102,4 +109,36 @@ public class FeedItemTest { assertEquals(anyFeedItemWithImage().getImageUrl(), original.getImageUrl()); } + /** + * If one of `description` or `content:encoded` is null, use the other one. + */ + @Test + public void testShownotesNullValues() throws Exception { + testShownotes(null, TEXT_LONG); + testShownotes(TEXT_LONG, null); + } + + /** + * If `description` is reasonably longer than `content:encoded`, use `description`. + */ + @Test + public void testShownotesLength() throws Exception { + testShownotes(TEXT_SHORT, TEXT_LONG); + testShownotes(TEXT_LONG, TEXT_SHORT); + } + + /** + * Checks if the shownotes equal TEXT_LONG, using the given `description` and `content:encoded`. + * + * @param description Description of the feed item + * @param contentEncoded `content:encoded` of the feed item + */ + private void testShownotes(String description, String contentEncoded) throws Exception { + try (MockedStatic ignore = Mockito.mockStatic(DBReader.class)) { + FeedItem item = new FeedItem(); + item.setDescription(description); + item.setContentEncoded(contentEncoded); + assertEquals(TEXT_LONG, item.loadShownotes().call()); + } + } } \ No newline at end of file