diff options
author | ByteHamster <info@bytehamster.com> | 2018-06-06 15:08:46 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2018-06-06 15:08:46 +0200 |
commit | 8fa31804466b1e958f561a991ac7ef1057cfcb3a (patch) | |
tree | abc3d84c7f3fa1ebf344ca9f5fa665678abcc5c7 | |
parent | 9b738ca5d47c7e47b691e900381eea27cf2ba34d (diff) | |
download | AntennaPod-8fa31804466b1e958f561a991ac7ef1057cfcb3a.zip |
Restored tests
4 files changed, 178 insertions, 0 deletions
diff --git a/core/src/test/java/de/danoeh/antennapod/core/feed/FeedItemMother.java b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedItemMother.java new file mode 100644 index 000000000..b78cecc23 --- /dev/null +++ b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedItemMother.java @@ -0,0 +1,16 @@ +package de.danoeh.antennapod.core.feed; + +import java.util.Date; + +import static de.danoeh.antennapod.core.feed.FeedMother.anyFeed; + +class FeedItemMother { + private static final String IMAGE_URL = "http://example.com/image"; + + static FeedItem anyFeedItemWithImage() { + FeedItem item = new FeedItem(0, "Item", "Item", "url", new Date(), FeedItem.PLAYED, anyFeed()); + item.setImageUrl(IMAGE_URL); + return item; + } + +} 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 new file mode 100644 index 000000000..e36a09f00 --- /dev/null +++ b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedItemTest.java @@ -0,0 +1,60 @@ +package de.danoeh.antennapod.core.feed; + +import org.junit.Before; +import org.junit.Test; + +import static de.danoeh.antennapod.core.feed.FeedItemMother.anyFeedItemWithImage; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +public class FeedItemTest { + + private FeedItem original; + private FeedItem changedFeedItem; + + @Before + public void setUp() { + original = anyFeedItemWithImage(); + changedFeedItem = anyFeedItemWithImage(); + } + + @Test + public void testUpdateFromOther_feedItemImageDownloadUrlChanged() throws Exception { + setNewFeedItemImageDownloadUrl(); + original.updateFromOther(changedFeedItem); + assertFeedItemImageWasUpdated(); + } + + @Test + public void testUpdateFromOther_feedItemImageRemoved() throws Exception { + feedItemImageRemoved(); + original.updateFromOther(changedFeedItem); + assertFeedItemImageWasNotUpdated(); + } + + @Test + public void testUpdateFromOther_feedItemImageAdded() throws Exception { + original.setImageUrl(null); + setNewFeedItemImageDownloadUrl(); + original.updateFromOther(changedFeedItem); + assertFeedItemImageWasUpdated(); + } + + private void setNewFeedItemImageDownloadUrl() { + changedFeedItem.setImageUrl("http://example.com/new_picture"); + } + + private void feedItemImageRemoved() { + changedFeedItem.setImageUrl(null); + } + + private void assertFeedItemImageWasUpdated() { + assertEquals(original.getImageUrl(), changedFeedItem.getImageUrl()); + } + + private void assertFeedItemImageWasNotUpdated() { + assertEquals(anyFeedItemWithImage().getImageUrl(), original.getImageUrl()); + } + +}
\ No newline at end of file diff --git a/core/src/test/java/de/danoeh/antennapod/core/feed/FeedMother.java b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedMother.java new file mode 100644 index 000000000..f46797d28 --- /dev/null +++ b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedMother.java @@ -0,0 +1,12 @@ +package de.danoeh.antennapod.core.feed; + +class FeedMother { + public static final String IMAGE_URL = "http://example.com/image"; + + public static Feed anyFeed() { + return new Feed(0, null, "title", "http://example.com", "This is the description", + "http://example.com/payment", "Daniel", "en", null, "http://example.com/feed", IMAGE_URL, + null, "http://example.com/feed", true); + } + +} diff --git a/core/src/test/java/de/danoeh/antennapod/core/feed/FeedTest.java b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedTest.java new file mode 100644 index 000000000..4717041f4 --- /dev/null +++ b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedTest.java @@ -0,0 +1,90 @@ +package de.danoeh.antennapod.core.feed; + +import org.junit.Before; +import org.junit.Test; + +import static de.danoeh.antennapod.core.feed.FeedMother.anyFeed; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class FeedTest { + + private Feed original; + private Feed changedFeed; + + @Before + public void setUp() { + original = anyFeed(); + changedFeed = anyFeed(); + } + + @Test + public void testCompareWithOther_feedImageDownloadUrlChanged() throws Exception { + setNewFeedImageDownloadUrl(); + feedHasChanged(); + } + + @Test + public void testCompareWithOther_sameFeedImage() throws Exception { + changedFeed.setImageUrl(FeedMother.IMAGE_URL); + feedHasNotChanged(); + } + + @Test + public void testCompareWithOther_feedImageRemoved() throws Exception { + feedImageRemoved(); + feedHasNotChanged(); + } + + @Test + public void testUpdateFromOther_feedImageDownloadUrlChanged() throws Exception { + setNewFeedImageDownloadUrl(); + original.updateFromOther(changedFeed); + feedImageWasUpdated(); + } + + @Test + public void testUpdateFromOther_feedImageRemoved() throws Exception { + feedImageRemoved(); + original.updateFromOther(changedFeed); + feedImageWasNotUpdated(); + } + + @Test + public void testUpdateFromOther_feedImageAdded() throws Exception { + feedHadNoImage(); + setNewFeedImageDownloadUrl(); + original.updateFromOther(changedFeed); + feedImageWasUpdated(); + } + + private void feedHasNotChanged() { + assertFalse(original.compareWithOther(changedFeed)); + } + + private void feedHadNoImage() { + original.setImageUrl(null); + } + + private void setNewFeedImageDownloadUrl() { + changedFeed.setImageUrl("http://example.com/new_picture"); + } + + private void feedHasChanged() { + assertTrue(original.compareWithOther(changedFeed)); + } + + private void feedImageRemoved() { + changedFeed.setImageUrl(null); + } + + private void feedImageWasUpdated() { + assertEquals(original.getImageUrl(), changedFeed.getImageUrl()); + } + + private void feedImageWasNotUpdated() { + assertEquals(anyFeed().getImageUrl(), original.getImageUrl()); + } + +}
\ No newline at end of file |