diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2017-06-05 11:23:24 +0200 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2017-06-05 11:26:42 +0200 |
commit | 14ac9e69207eb017d3e0fcee70a323042fe46cc7 (patch) | |
tree | 53dc5673c546a324e0c5f21c6190bd53d88403de | |
parent | 41624c20a9876665e4ae80a9c5145c745c48da37 (diff) | |
download | AntennaPod-14ac9e69207eb017d3e0fcee70a323042fe46cc7.zip |
1183 Update feed item image
3 files changed, 84 insertions, 0 deletions
diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedItemMother.java b/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedItemMother.java new file mode 100644 index 000000000..3d7c4fe5f --- /dev/null +++ b/core/src/androidTest/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.FeedImageMother.anyFeedImage; +import static de.danoeh.antennapod.core.feed.FeedMother.anyFeed; + +class FeedItemMother { + + static FeedItem anyFeedItemWithImage() { + FeedItem item = new FeedItem(0, "Item", "Item", "url", new Date(), FeedItem.PLAYED, anyFeed()); + item.setImage(anyFeedImage()); + return item; + } + +} diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedItemTest.java b/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedItemTest.java new file mode 100644 index 000000000..9e12e8ae0 --- /dev/null +++ b/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedItemTest.java @@ -0,0 +1,65 @@ +package de.danoeh.antennapod.core.feed; + +import android.test.AndroidTestCase; + +import static de.danoeh.antennapod.core.feed.FeedItemMother.anyFeedItemWithImage; + +public class FeedItemTest extends AndroidTestCase { + + private FeedItem original; + private FeedImage originalImage; + private FeedItem changedFeedItem; + + @Override + protected void setUp() { + original = anyFeedItemWithImage(); + originalImage = original.getImage(); + changedFeedItem = anyFeedItemWithImage(); + } + + public void testUpdateFromOther_feedItemImageDownloadUrlChanged() throws Exception { + setNewFeedItemImageDownloadUrl(); + + original.updateFromOther(changedFeedItem); + + feedItemImageWasUpdated(); + } + + public void testUpdateFromOther_feedItemImageRemoved() throws Exception { + feedItemImageRemoved(); + + original.updateFromOther(changedFeedItem); + + feedItemImageWasNotUpdated(); + } + + public void testUpdateFromOther_feedItemImageAdded() throws Exception { + feedItemHadNoImage(); + setNewFeedItemImageDownloadUrl(); + + original.updateFromOther(changedFeedItem); + + feedItemImageWasUpdated(); + } + + private void feedItemHadNoImage() { + original.setImage(null); + } + + private void setNewFeedItemImageDownloadUrl() { + changedFeedItem.getImage().setDownload_url("http://example.com/new_picture"); + } + + private void feedItemImageRemoved() { + changedFeedItem.setImage(null); + } + + private void feedItemImageWasUpdated() { + assertEquals(original.getImage().getDownload_url(), changedFeedItem.getImage().getDownload_url()); + } + + private void feedItemImageWasNotUpdated() { + assertTrue(originalImage == original.getImage()); + } + +}
\ No newline at end of file diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java index ee7a738d0..66c4b10d0 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java @@ -177,6 +177,9 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr public void updateFromOther(FeedItem other) { super.updateFromOther(other); + if (other.image != null) { + this.image = other.image; + } if (other.title != null) { title = other.title; } |