diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedImageMother.java b/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedImageMother.java new file mode 100644 index 000000000..f240c870e --- /dev/null +++ b/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedImageMother.java @@ -0,0 +1,9 @@ +package de.danoeh.antennapod.core.feed; + +public class FeedImageMother { + + public static FeedImage anyFeedImage() { + return new FeedImage(0, "image", null, "http://example.com/picture", false); + } + +} diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedMother.java b/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedMother.java new file mode 100644 index 000000000..1cea6b9c9 --- /dev/null +++ b/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedMother.java @@ -0,0 +1,14 @@ +package de.danoeh.antennapod.core.feed; + +import static de.danoeh.antennapod.core.feed.FeedImageMother.anyFeedImage; + +public class FeedMother { + + public static Feed anyFeed() { + FeedImage image = anyFeedImage(); + 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, + null, "http://example.com/feed", true); + } + +} diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedTest.java b/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedTest.java new file mode 100644 index 000000000..d3e00cd60 --- /dev/null +++ b/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedTest.java @@ -0,0 +1,92 @@ +package de.danoeh.antennapod.core.feed; + +import android.test.AndroidTestCase; + +import static de.danoeh.antennapod.core.feed.FeedImageMother.anyFeedImage; +import static de.danoeh.antennapod.core.feed.FeedMother.anyFeed; + +public class FeedTest extends AndroidTestCase { + + private Feed original; + private FeedImage originalImage; + private Feed changedFeed; + + @Override + protected void setUp() { + original = anyFeed(); + originalImage = original.getImage(); + changedFeed = anyFeed(); + } + + public void testCompareWithOther_feedImageDownloadUrlChanged() throws Exception { + setNewFeedImageDownloadUrl(); + + feedHasChanged(); + } + + public void testCompareWithOther_sameFeedImage() throws Exception { + changedFeed.setImage(anyFeedImage()); + + feedHasNotChanged(); + } + + private void feedHasNotChanged() { + assertFalse(original.compareWithOther(changedFeed)); + } + + public void testCompareWithOther_feedImageRemoved() throws Exception { + feedImageRemoved(); + + feedHasNotChanged(); + } + + public void testUpdateFromOther_feedImageDownloadUrlChanged() throws Exception { + setNewFeedImageDownloadUrl(); + + original.updateFromOther(changedFeed); + + feedImageWasUpdated(); + } + + public void testUpdateFromOther_feedImageRemoved() throws Exception { + feedImageRemoved(); + + original.updateFromOther(changedFeed); + + feedImageWasNotUpdated(); + } + + public void testUpdateFromOther_feedImageAdded() throws Exception { + feedHadNoImage(); + setNewFeedImageDownloadUrl(); + + original.updateFromOther(changedFeed); + + feedImageWasUpdated(); + } + + private void feedHadNoImage() { + original.setImage(null); + } + + private void setNewFeedImageDownloadUrl() { + changedFeed.getImage().setDownload_url("http://example.com/new_picture"); + } + + private void feedHasChanged() { + assertTrue(original.compareWithOther(changedFeed)); + } + + private void feedImageRemoved() { + changedFeed.setImage(null); + } + + private void feedImageWasUpdated() { + assertEquals(original.getImage().getDownload_url(), changedFeed.getImage().getDownload_url()); + } + + private void feedImageWasNotUpdated() { + assertTrue(originalImage == original.getImage()); + } + +} \ No newline at end of file diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java b/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java index d4af60a07..746dd43c4 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java @@ -266,6 +266,9 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource { public void updateFromOther(Feed other) { // don't update feed's download_url, we do that manually if redirected // see AntennapodHttpClient + if (other.image != null) { + this.image = other.image; + } if (other.feedTitle != null) { feedTitle = other.feedTitle; } @@ -302,6 +305,9 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource { if (super.compareWithOther(other)) { return true; } + if(other.image != null && !TextUtils.equals(image.download_url, other.image.download_url)) { + return true; + } if (!TextUtils.equals(feedTitle, other.feedTitle)) { return true; }