Improved test of saving to feed cache.
authorstechong
Wed, 20 May 2009 13:34:23 -0500
changeset 174 619ca8fc1260
parent 173 5afc27b54777
child 175 f70af3d98d07
Improved test of saving to feed cache.
core/com.nokia.carbide.cpp.news.reader.tests/src/com/nokia/carbide/cpp/news/reader/tests/FeedCacheManagerTest.java
--- a/core/com.nokia.carbide.cpp.news.reader.tests/src/com/nokia/carbide/cpp/news/reader/tests/FeedCacheManagerTest.java	Wed May 20 13:32:51 2009 -0500
+++ b/core/com.nokia.carbide.cpp.news.reader.tests/src/com/nokia/carbide/cpp/news/reader/tests/FeedCacheManagerTest.java	Wed May 20 13:34:23 2009 -0500
@@ -19,9 +19,11 @@
 
 import java.io.File;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
+import com.nokia.carbide.cpp.internal.news.reader.feed.CarbideSyndEntry;
 import com.nokia.carbide.cpp.internal.news.reader.feed.CarbideSyndFeed;
 import com.nokia.carbide.cpp.internal.news.reader.feed.FeedManager;
 import com.nokia.carbide.cpp.internal.news.reader.gen.FeedCache.FeedCacheFactory;
@@ -29,6 +31,10 @@
 import com.nokia.carbide.cpp.internal.news.reader.gen.FeedCache.FeedCacheType;
 import com.nokia.carbide.cpp.internal.news.reader.gen.FeedCache.FeedType;
 import com.nokia.carbide.cpp.internal.news.reader.gen.FeedCache.IFeedCacheChangedlistener;
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndEntryImpl;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.feed.synd.SyndFeedImpl;
 
 import junit.framework.TestCase;
 
@@ -190,6 +196,32 @@
 		}
 	}
 
+	public void testSaveFeedToCache() {
+		try {
+			feedCacheManager.setFeedCache(null);
+			feedCacheManager.saveFeedToCache(null);
+			assertNull(feedCacheManager.getFeedCache());
+			File file = getDefaultFeedCacheFile();
+			URL url = file.toURL();
+			if (feedCacheManager.loadCacheFromFile(url)) {
+				SyndFeed syndFeed = new SyndFeedImpl();
+				CarbideSyndFeed feed = new CarbideSyndFeed(syndFeed);
+				List<CarbideSyndEntry> entries = new ArrayList<CarbideSyndEntry>();
+				SyndEntry syndEntry = new SyndEntryImpl();
+				CarbideSyndEntry entry = new CarbideSyndEntry(syndEntry);
+				entries.add(entry);
+				feed.setEntries(entries);
+				feed.setDescription("A feed for testing feed cache manager.");
+				feed.setTitle("Test feed");
+				feed.setLink("http://www.nokia.com");
+				feedCacheManager.saveFeedToCache(feed);
+				assertTrue(feedCacheManager.isFeedInCache(feed));
+			}
+		} catch (Exception e) {
+			fail();
+		}
+	}
+
 	public void testSetCacheUpdated() {
 		feedCacheManager.setCacheUpdated(true);
 		assertTrue(feedCacheManager.isCacheUpdated());