Restored tests
This commit is contained in:
parent
9b738ca5d4
commit
8fa3180446
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue