Made FeedItem/FeedMedia objects easier to create

This commit is contained in:
daniel oeh 2013-08-19 10:56:16 +02:00
parent ba28e2523e
commit 6e1a533bf7
3 changed files with 36 additions and 25 deletions

View File

@ -48,6 +48,19 @@ public class FeedItem extends FeedComponent implements
this.read = true;
}
/**
* This constructor should be used for creating test objects.
* */
public FeedItem(long id, String title, String itemIdentifier, String link, Date pubDate, boolean read, Feed feed) {
this.id = id;
this.title = title;
this.itemIdentifier = itemIdentifier;
this.link = link;
this.pubDate = (pubDate != null) ? (Date) pubDate.clone() : null;
this.read = read;
this.feed = feed;
}
public void updateFromOther(FeedItem other) {
super.updateFromOther(other);
if (other.title != null) {
@ -142,8 +155,16 @@ public class FeedItem extends FeedComponent implements
return media;
}
/**
* Sets the media object of this FeedItem. If the given
* FeedMedia object is not null, it's 'item'-attribute value
* will also be set to this item.
* */
public void setMedia(FeedMedia media) {
this.media = media;
if (media != null && media.getItem() != this) {
media.setItem(this);
}
}
public Feed getFeed() {

View File

@ -165,8 +165,16 @@ public class FeedMedia extends FeedFile implements Playable {
return item;
}
/**
* Sets the item object of this FeedMedia. If the given
* FeedItem object is not null, it's 'media'-attribute value
* will also be set to this media object.
* */
public void setItem(FeedItem item) {
this.item = item;
if (item != null && item.getMedia() != this) {
item.setMedia(this);
}
}
public Date getPlaybackCompletionDate() {

View File

@ -59,10 +59,7 @@ public class DBWriterTest extends InstrumentationTestCase {
Feed feed = new Feed("url", new Date(), "title");
List<FeedItem> items = new ArrayList<FeedItem>();
feed.setItems(items);
FeedItem item = new FeedItem();
item.setTitle("title");
item.setPubDate(new Date());
item.setFeed(feed);
FeedItem item = new FeedItem(0, "Item", "Item", "url", new Date(), true, feed);
FeedMedia media = new FeedMedia(0, item, 1, 1, 1, "mime_type", dest.getAbsolutePath(), "download_url", true, null);
item.setMedia(media);
@ -101,10 +98,7 @@ public class DBWriterTest extends InstrumentationTestCase {
List<File> itemFiles = new ArrayList<File>();
// create items with downloaded media files
for (int i = 0; i < 10; i++) {
FeedItem item = new FeedItem();
item.setTitle("Item " + i);
item.setPubDate(new Date(System.currentTimeMillis()));
item.setFeed(feed);
FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), true, feed);
feed.getItems().add(item);
File enc = new File(destFolder, "file " + i);
@ -165,16 +159,13 @@ public class DBWriterTest extends InstrumentationTestCase {
List<File> itemFiles = new ArrayList<File>();
// create items with downloaded media files
for (int i = 0; i < 10; i++) {
FeedItem item = new FeedItem();
item.setTitle("Item " + i);
item.setPubDate(new Date(System.currentTimeMillis()));
item.setFeed(feed);
FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), true, feed);
feed.getItems().add(item);
File enc = new File(destFolder, "file " + i);
assertTrue(enc.createNewFile());
itemFiles.add(enc);
itemFiles.add(enc);
FeedMedia media = new FeedMedia(0, item, 1, 1, 1, "mime_type", enc.getAbsolutePath(), "download_url", true, null);
item.setMedia(media);
}
@ -265,10 +256,7 @@ public class DBWriterTest extends InstrumentationTestCase {
// create items
for (int i = 0; i < 10; i++) {
FeedItem item = new FeedItem();
item.setTitle("Item " + i);
item.setPubDate(new Date(System.currentTimeMillis()));
item.setFeed(feed);
FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), true, feed);
feed.getItems().add(item);
}
@ -320,10 +308,7 @@ public class DBWriterTest extends InstrumentationTestCase {
List<File> itemFiles = new ArrayList<File>();
// create items with downloaded media files
for (int i = 0; i < 10; i++) {
FeedItem item = new FeedItem();
item.setTitle("Item " + i);
item.setPubDate(new Date(System.currentTimeMillis()));
item.setFeed(feed);
FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), true, feed);
feed.getItems().add(item);
File enc = new File(destFolder, "file " + i);
@ -395,10 +380,7 @@ public class DBWriterTest extends InstrumentationTestCase {
List<File> itemFiles = new ArrayList<File>();
// create items with downloaded media files
for (int i = 0; i < 10; i++) {
FeedItem item = new FeedItem();
item.setTitle("Item " + i);
item.setPubDate(new Date(System.currentTimeMillis()));
item.setFeed(feed);
FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), true, feed);
feed.getItems().add(item);
File enc = new File(destFolder, "file " + i);