From 542dbd190c6aa4b01c1b644e5c107333817442cd Mon Sep 17 00:00:00 2001
From: Herbert Reiter <46045854+damoasda@users.noreply.github.com>
Date: Sat, 2 Jan 2021 17:49:30 +0100
Subject: Run more util tests with Robolectric (#4815)
---
.../util/syndication/FeedDiscovererTest.java | 124 ---------------------
1 file changed, 124 deletions(-)
delete mode 100644 app/src/androidTest/java/de/test/antennapod/util/syndication/FeedDiscovererTest.java
(limited to 'app/src/androidTest/java/de/test/antennapod/util/syndication')
diff --git a/app/src/androidTest/java/de/test/antennapod/util/syndication/FeedDiscovererTest.java b/app/src/androidTest/java/de/test/antennapod/util/syndication/FeedDiscovererTest.java
deleted file mode 100644
index b213a5efa..000000000
--- a/app/src/androidTest/java/de/test/antennapod/util/syndication/FeedDiscovererTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package de.test.antennapod.util.syndication;
-
-import androidx.test.platform.app.InstrumentationRegistry;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.nio.charset.Charset;
-import java.util.Map;
-
-import de.danoeh.antennapod.core.util.syndication.FeedDiscoverer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Test class for FeedDiscoverer
- */
-public class FeedDiscovererTest {
-
- private FeedDiscoverer fd;
-
- private File testDir;
-
- @Before
- public void setUp() throws Exception {
- fd = new FeedDiscoverer();
- testDir = new File(InstrumentationRegistry
- .getInstrumentation().getTargetContext().getFilesDir(), "FeedDiscovererTest");
- testDir.mkdir();
- assertTrue(testDir.exists());
- }
-
- @After
- public void tearDown() throws Exception {
- FileUtils.deleteDirectory(testDir);
- }
-
- private String createTestHtmlString(String rel, String type, String href, String title) {
- return String.format("
Test",
- rel, type, href, title);
- }
-
- private String createTestHtmlString(String rel, String type, String href) {
- return String.format("Test",
- rel, type, href);
- }
-
- private void checkFindUrls(boolean isAlternate, boolean isRss, boolean withTitle, boolean isAbsolute, boolean fromString) throws Exception {
- final String title = "Test title";
- final String hrefAbs = "http://example.com/feed";
- final String hrefRel = "/feed";
- final String base = "http://example.com";
-
- final String rel = (isAlternate) ? "alternate" : "feed";
- final String type = (isRss) ? "application/rss+xml" : "application/atom+xml";
- final String href = (isAbsolute) ? hrefAbs : hrefRel;
-
- Map res;
- String html = (withTitle) ? createTestHtmlString(rel, type, href, title)
- : createTestHtmlString(rel, type, href);
- if (fromString) {
- res = fd.findLinks(html, base);
- } else {
- File testFile = new File(testDir, "feed");
- FileOutputStream out = new FileOutputStream(testFile);
- IOUtils.write(html, out, Charset.forName("UTF-8"));
- out.close();
- res = fd.findLinks(testFile, base);
- }
-
- assertNotNull(res);
- assertEquals(1, res.size());
- for (String key : res.keySet()) {
- assertEquals(hrefAbs, key);
- }
- assertTrue(res.containsKey(hrefAbs));
- if (withTitle) {
- assertEquals(title, res.get(hrefAbs));
- } else {
- assertEquals(href, res.get(hrefAbs));
- }
- }
-
- @Test
- public void testAlternateRSSWithTitleAbsolute() throws Exception {
- checkFindUrls(true, true, true, true, true);
- }
-
- @Test
- public void testAlternateRSSWithTitleRelative() throws Exception {
- checkFindUrls(true, true, true, false, true);
- }
-
- @Test
- public void testAlternateRSSNoTitleAbsolute() throws Exception {
- checkFindUrls(true, true, false, true, true);
- }
-
- @Test
- public void testAlternateRSSNoTitleRelative() throws Exception {
- checkFindUrls(true, true, false, false, true);
- }
-
- @Test
- public void testAlternateAtomWithTitleAbsolute() throws Exception {
- checkFindUrls(true, false, true, true, true);
- }
-
- @Test
- public void testFeedAtomWithTitleAbsolute() throws Exception {
- checkFindUrls(false, false, true, true, true);
- }
-
- @Test
- public void testAlternateRSSWithTitleAbsoluteFromFile() throws Exception {
- checkFindUrls(true, true, true, true, false);
- }
-}
--
cgit v1.2.3