diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2013-10-04 17:23:38 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2013-10-04 17:23:38 +0200 |
commit | 15446f18479a57a8d485d1c95e810b609b67f69f (patch) | |
tree | b233e465b1d42edaa308b6a4fe803a90a5c9c11a /src/instrumentationTest/de/test/antennapod | |
parent | 44e4924db9afd40c2bfb9515ec84f2d569b150e3 (diff) | |
download | AntennaPod-15446f18479a57a8d485d1c95e810b609b67f69f.zip |
Fixed problem with automatic feed updates
Diffstat (limited to 'src/instrumentationTest/de/test/antennapod')
3 files changed, 92 insertions, 2 deletions
diff --git a/src/instrumentationTest/de/test/antennapod/AntennaPodTestRunner.java b/src/instrumentationTest/de/test/antennapod/AntennaPodTestRunner.java index 7aaa14909..e1699139d 100644 --- a/src/instrumentationTest/de/test/antennapod/AntennaPodTestRunner.java +++ b/src/instrumentationTest/de/test/antennapod/AntennaPodTestRunner.java @@ -12,7 +12,9 @@ public class AntennaPodTestRunner extends InstrumentationTestRunner { @Override public TestSuite getAllTests() { - return new TestSuiteBuilder(AntennaPodTestRunner.class).includeAllPackagesUnderHere().build(); - //return new TestSuiteBuilder(AntennaPodTestRunner.class).includeAllPackagesUnderHere().excludePackages("instrumentationTest.de.test.antennapod.syndication.handler").build(); + return new TestSuiteBuilder(AntennaPodTestRunner.class).includeAllPackagesUnderHere() + // .excludePackages("instrumentationTest.de.test.antennapod.syndication.handler") + // .excludePackages("instrumentationTest.de.test.antennapod.gpodnet") + .build(); } } diff --git a/src/instrumentationTest/de/test/antennapod/storage/DBReaderTest.java b/src/instrumentationTest/de/test/antennapod/storage/DBReaderTest.java index 0fb733b67..f15eeef3a 100644 --- a/src/instrumentationTest/de/test/antennapod/storage/DBReaderTest.java +++ b/src/instrumentationTest/de/test/antennapod/storage/DBReaderTest.java @@ -1,11 +1,67 @@ package instrumentationTest.de.test.antennapod.storage; +import android.content.Context; import android.test.InstrumentationTestCase; +import de.danoeh.antennapod.feed.Feed; +import de.danoeh.antennapod.feed.FeedItem; +import de.danoeh.antennapod.storage.DBReader; +import de.danoeh.antennapod.storage.PodDBAdapter; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; /** * Test class for DBReader */ public class DBReaderTest extends InstrumentationTestCase { + @Override + protected void tearDown() throws Exception { + super.tearDown(); + final Context context = getInstrumentation().getTargetContext(); + assertTrue(PodDBAdapter.deleteDatabase(context)); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + final Context context = getInstrumentation().getTargetContext(); + context.deleteDatabase(PodDBAdapter.DATABASE_NAME); + // make sure database is created + PodDBAdapter adapter = new PodDBAdapter(context); + adapter.open(); + adapter.close(); + } + + private void expiredFeedListTestHelper(long lastUpdate, long expirationTime, boolean shouldReturn) { + final Context context = getInstrumentation().getTargetContext(); + Feed feed = new Feed(0, new Date(lastUpdate), "feed", "link", "descr", null, + null, null, null, "feed", null, null, "url", false); + feed.setItems(new ArrayList<FeedItem>()); + PodDBAdapter adapter = new PodDBAdapter(context); + adapter.open(); + adapter.setCompleteFeed(feed); + adapter.close(); + + assertTrue(feed.getId() != 0); + List<Feed> expiredFeeds = DBReader.getExpiredFeedsList(context, expirationTime); + assertNotNull(expiredFeeds); + if (shouldReturn) { + assertTrue(expiredFeeds.size() == 1); + assertTrue(expiredFeeds.get(0).getId() == feed.getId()); + } else { + assertTrue(expiredFeeds.isEmpty()); + } + } + + public void testGetExpiredFeedsListShouldReturnFeed() { + final long expirationTime = 1000 * 60 * 60; // 1 hour + expiredFeedListTestHelper(System.currentTimeMillis() - expirationTime - 1, expirationTime, true); + } + public void testGetExpiredFeedsListShouldNotReturnFeed() { + final long expirationTime = 1000 * 60 * 60; // 1 hour + expiredFeedListTestHelper(System.currentTimeMillis() - expirationTime / 2, expirationTime, false); + } } diff --git a/src/instrumentationTest/de/test/antennapod/storage/DBTasksTest.java b/src/instrumentationTest/de/test/antennapod/storage/DBTasksTest.java index 7631a5787..3f928bd9b 100644 --- a/src/instrumentationTest/de/test/antennapod/storage/DBTasksTest.java +++ b/src/instrumentationTest/de/test/antennapod/storage/DBTasksTest.java @@ -249,4 +249,36 @@ public class DBTasksTest extends InstrumentationTestCase { lastDate = item.getPubDate(); } } + + private void expiredFeedListTestHelper(long lastUpdate, long expirationTime, boolean shouldReturn) { + final Context context = getInstrumentation().getTargetContext(); + UserPreferences.setUpdateInterval(context, expirationTime); + Feed feed = new Feed(0, new Date(lastUpdate), "feed", "link", "descr", null, + null, null, null, "feed", null, null, "url", false); + feed.setItems(new ArrayList<FeedItem>()); + PodDBAdapter adapter = new PodDBAdapter(context); + adapter.open(); + adapter.setCompleteFeed(feed); + adapter.close(); + + assertTrue(feed.getId() != 0); + List<Feed> expiredFeeds = DBTasks.getExpiredFeeds(context); + assertNotNull(expiredFeeds); + if (shouldReturn) { + assertTrue(expiredFeeds.size() == 1); + assertTrue(expiredFeeds.get(0).getId() == feed.getId()); + } else { + assertTrue(expiredFeeds.isEmpty()); + } + } + + public void testGetExpiredFeedsTestShouldReturn() { + final long expirationTime = 1000 * 60 * 60; + expiredFeedListTestHelper(System.currentTimeMillis() - expirationTime - 1, expirationTime, true); + } + + public void testGetExpiredFeedsTestShouldNotReturn() { + final long expirationTime = 1000 * 60 * 60; + expiredFeedListTestHelper(System.currentTimeMillis() - expirationTime / 2, expirationTime, false); + } } |