1183 Update feed item image
This commit is contained in:
parent
41624c20a9
commit
14ac9e6920
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue