1183 Update feed image
This commit is contained in:
parent
404a9c2fbf
commit
19acd8d88c
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue