From 7dd4e5caa1442c6a5a08a054669940a51eba8b25 Mon Sep 17 00:00:00 2001 From: orionlee Date: Thu, 17 May 2018 14:23:07 -0700 Subject: [PATCH 1/5] core tests fix: ensure running test suite (gradlew connectedAndroidTest) include all test. The existing config does not include the tests in feed/ directory. --- core/build.gradle | 2 +- .../antennapod/core/{tests => }/AntennaPodTestRunner.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename core/src/androidTest/java/de/danoeh/antennapod/core/{tests => }/AntennaPodTestRunner.java (90%) diff --git a/core/build.gradle b/core/build.gradle index de156d7c7..9ac6ca0b5 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -10,7 +10,7 @@ android { versionCode 1 versionName "1.0" testApplicationId "de.danoeh.antennapod.core.tests" - testInstrumentationRunner "de.danoeh.antennapod.core.tests.AntennaPodTestRunner" + testInstrumentationRunner "de.danoeh.antennapod.core.AntennaPodTestRunner" } buildTypes { release { diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/tests/AntennaPodTestRunner.java b/core/src/androidTest/java/de/danoeh/antennapod/core/AntennaPodTestRunner.java similarity index 90% rename from core/src/androidTest/java/de/danoeh/antennapod/core/tests/AntennaPodTestRunner.java rename to core/src/androidTest/java/de/danoeh/antennapod/core/AntennaPodTestRunner.java index 78e854b41..5d086c054 100644 --- a/core/src/androidTest/java/de/danoeh/antennapod/core/tests/AntennaPodTestRunner.java +++ b/core/src/androidTest/java/de/danoeh/antennapod/core/AntennaPodTestRunner.java @@ -1,4 +1,4 @@ -package de.danoeh.antennapod.core.tests; +package de.danoeh.antennapod.core; import android.test.InstrumentationTestRunner; import android.test.suitebuilder.TestSuiteBuilder; From f05c7e23efce568b830d000df773209640028d7c Mon Sep 17 00:00:00 2001 From: orionlee Date: Thu, 17 May 2018 14:24:35 -0700 Subject: [PATCH 2/5] core tests fix: use consistent convention that tests are in the same java package as the classes under test. --- .../util => }/service/download/DownloadServiceTest.java | 3 +-- .../antennapod/core/{tests => }/util/DateUtilsTest.java | 4 +--- .../antennapod/core/{tests => }/util/LongLongMapTest.java | 4 +--- 3 files changed, 3 insertions(+), 8 deletions(-) rename core/src/androidTest/java/de/danoeh/antennapod/core/{tests/util => }/service/download/DownloadServiceTest.java (89%) rename core/src/androidTest/java/de/danoeh/antennapod/core/{tests => }/util/DateUtilsTest.java (98%) rename core/src/androidTest/java/de/danoeh/antennapod/core/{tests => }/util/LongLongMapTest.java (95%) diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/tests/util/service/download/DownloadServiceTest.java b/core/src/androidTest/java/de/danoeh/antennapod/core/service/download/DownloadServiceTest.java similarity index 89% rename from core/src/androidTest/java/de/danoeh/antennapod/core/tests/util/service/download/DownloadServiceTest.java rename to core/src/androidTest/java/de/danoeh/antennapod/core/service/download/DownloadServiceTest.java index 94cfb3278..ee27f6bbd 100644 --- a/core/src/androidTest/java/de/danoeh/antennapod/core/tests/util/service/download/DownloadServiceTest.java +++ b/core/src/androidTest/java/de/danoeh/antennapod/core/service/download/DownloadServiceTest.java @@ -1,4 +1,4 @@ -package de.danoeh.antennapod.core.tests.util.service.download; +package de.danoeh.antennapod.core.service.download; import android.test.AndroidTestCase; @@ -8,7 +8,6 @@ import java.util.List; import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedImage; import de.danoeh.antennapod.core.feed.FeedItem; -import de.danoeh.antennapod.core.service.download.DownloadService; public class DownloadServiceTest extends AndroidTestCase { diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/tests/util/DateUtilsTest.java b/core/src/androidTest/java/de/danoeh/antennapod/core/util/DateUtilsTest.java similarity index 98% rename from core/src/androidTest/java/de/danoeh/antennapod/core/tests/util/DateUtilsTest.java rename to core/src/androidTest/java/de/danoeh/antennapod/core/util/DateUtilsTest.java index ee90d9116..c7c9d98a9 100644 --- a/core/src/androidTest/java/de/danoeh/antennapod/core/tests/util/DateUtilsTest.java +++ b/core/src/androidTest/java/de/danoeh/antennapod/core/util/DateUtilsTest.java @@ -1,4 +1,4 @@ -package de.danoeh.antennapod.core.tests.util; +package de.danoeh.antennapod.core.util; import android.test.AndroidTestCase; @@ -7,8 +7,6 @@ import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; -import de.danoeh.antennapod.core.util.DateUtils; - public class DateUtilsTest extends AndroidTestCase { public void testParseDateWithMicroseconds() throws Exception { diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/tests/util/LongLongMapTest.java b/core/src/androidTest/java/de/danoeh/antennapod/core/util/LongLongMapTest.java similarity index 95% rename from core/src/androidTest/java/de/danoeh/antennapod/core/tests/util/LongLongMapTest.java rename to core/src/androidTest/java/de/danoeh/antennapod/core/util/LongLongMapTest.java index 50c2a9c3c..d75cd5c77 100644 --- a/core/src/androidTest/java/de/danoeh/antennapod/core/tests/util/LongLongMapTest.java +++ b/core/src/androidTest/java/de/danoeh/antennapod/core/util/LongLongMapTest.java @@ -1,9 +1,7 @@ -package de.danoeh.antennapod.core.tests.util; +package de.danoeh.antennapod.core.util; import android.test.AndroidTestCase; -import de.danoeh.antennapod.core.util.LongIntMap; - public class LongLongMapTest extends AndroidTestCase { public void testEmptyMap() { From 46ae3e0b00a3b3ec8ef7ba01efad8bcfb1a79398 Mon Sep 17 00:00:00 2001 From: orionlee Date: Fri, 18 May 2018 13:21:36 -0700 Subject: [PATCH 3/5] core tests: Convert tests that are effectively unit tests to be one (standard android junit tests). Provides implementations for android platform utils needed (in unit test environment): 1. android.util.Log, 2. android.text.TextUtils.isEmpty() --- core/build.gradle | 3 + .../src/test/java/android/text/TextUtils.java | 32 +++ core/src/test/java/android/util/Log.java | 245 ++++++++++++++++++ .../antennapod/core/feed/FeedImageMother.java | 0 .../antennapod/core/feed/FeedItemMother.java | 0 .../antennapod/core/feed/FeedItemTest.java | 14 +- .../antennapod/core/feed/FeedMother.java | 0 .../danoeh/antennapod/core/feed/FeedTest.java | 18 +- .../antennapod/core/util/LongLongMapTest.java | 10 +- 9 files changed, 312 insertions(+), 10 deletions(-) create mode 100644 core/src/test/java/android/text/TextUtils.java create mode 100644 core/src/test/java/android/util/Log.java rename core/src/{androidTest => test}/java/de/danoeh/antennapod/core/feed/FeedImageMother.java (100%) rename core/src/{androidTest => test}/java/de/danoeh/antennapod/core/feed/FeedItemMother.java (100%) rename core/src/{androidTest => test}/java/de/danoeh/antennapod/core/feed/FeedItemTest.java (87%) rename core/src/{androidTest => test}/java/de/danoeh/antennapod/core/feed/FeedMother.java (100%) rename core/src/{androidTest => test}/java/de/danoeh/antennapod/core/feed/FeedTest.java (88%) rename core/src/{androidTest => test}/java/de/danoeh/antennapod/core/util/LongLongMapTest.java (92%) diff --git a/core/build.gradle b/core/build.gradle index 9ac6ca0b5..649a078a5 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -79,6 +79,9 @@ dependencies { } else { System.out.println("core: free build hack, skipping some dependencies") } + + testImplementation 'junit:junit:4.12' + } allprojects { diff --git a/core/src/test/java/android/text/TextUtils.java b/core/src/test/java/android/text/TextUtils.java new file mode 100644 index 000000000..c31234171 --- /dev/null +++ b/core/src/test/java/android/text/TextUtils.java @@ -0,0 +1,32 @@ +package android.text; + +/** + * A slim-down version of standard {@link android.text.TextUtils} to be used in unit tests. + */ +public class TextUtils { + + /** + * Returns true if a and b are equal, including if they are both null. + *

Note: In platform versions 1.1 and earlier, this method only worked well if + * both the arguments were instances of String.

+ * @param a first CharSequence to check + * @param b second CharSequence to check + * @return true if a and b are equal + */ + public static boolean equals(CharSequence a, CharSequence b) { + if (a == b) return true; + int length; + if (a != null && b != null && (length = a.length()) == b.length()) { + if (a instanceof String && b instanceof String) { + return a.equals(b); + } else { + for (int i = 0; i < length; i++) { + if (a.charAt(i) != b.charAt(i)) return false; + } + return true; + } + } + return false; + } + +} diff --git a/core/src/test/java/android/util/Log.java b/core/src/test/java/android/util/Log.java new file mode 100644 index 000000000..881d10209 --- /dev/null +++ b/core/src/test/java/android/util/Log.java @@ -0,0 +1,245 @@ +package android.util; + +import java.io.PrintWriter; +import java.io.StringWriter; + +/** + * A stub for {@link android.util.Log} to be used in unit tests. + * + * It outputs the log statements to standard error. + */ +public final class Log { + + /** + * Priority constant for the println method; use Log.v. + */ + public static final int VERBOSE = 2; + + /** + * Priority constant for the println method; use Log.d. + */ + public static final int DEBUG = 3; + + /** + * Priority constant for the println method; use Log.i. + */ + public static final int INFO = 4; + + /** + * Priority constant for the println method; use Log.w. + */ + public static final int WARN = 5; + + /** + * Priority constant for the println method; use Log.e. + */ + public static final int ERROR = 6; + + /** + * Priority constant for the println method. + */ + public static final int ASSERT = 7; + + private Log() { + } + + /** + * Send a {@link #VERBOSE} log message. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + */ + public static int v(String tag, String msg) { + return println_native(LOG_ID_MAIN, VERBOSE, tag, msg); + } + + /** + * Send a {@link #VERBOSE} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log + */ + public static int v(String tag, String msg, Throwable tr) { + return printlns(LOG_ID_MAIN, VERBOSE, tag, msg, tr); + } + + /** + * Send a {@link #DEBUG} log message. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + */ + public static int d(String tag, String msg) { + return println_native(LOG_ID_MAIN, DEBUG, tag, msg); + } + + /** + * Send a {@link #DEBUG} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log + */ + public static int d(String tag, String msg, Throwable tr) { + return printlns(LOG_ID_MAIN, DEBUG, tag, msg, tr); + } + + /** + * Send an {@link #INFO} log message. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + */ + public static int i(String tag, String msg) { + return println_native(LOG_ID_MAIN, INFO, tag, msg); + } + + /** + * Send a {@link #INFO} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log + */ + public static int i(String tag, String msg, Throwable tr) { + return printlns(LOG_ID_MAIN, INFO, tag, msg, tr); + } + + /** + * Send a {@link #WARN} log message. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + */ + public static int w(String tag, String msg) { + return println_native(LOG_ID_MAIN, WARN, tag, msg); + } + + /** + * Send a {@link #WARN} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log + */ + public static int w(String tag, String msg, Throwable tr) { + return printlns(LOG_ID_MAIN, WARN, tag, msg, tr); + } + + /** + * Checks to see whether or not a log for the specified tag is loggable at the specified level. + * + * @return true in all cases (for unit test environment) + */ + public static boolean isLoggable(String tag, int level) { + return true; + } + + /* + * Send a {@link #WARN} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param tr An exception to log + */ + public static int w(String tag, Throwable tr) { + return printlns(LOG_ID_MAIN, WARN, tag, "", tr); + } + + /** + * Send an {@link #ERROR} log message. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + */ + public static int e(String tag, String msg) { + return println_native(LOG_ID_MAIN, ERROR, tag, msg); + } + + /** + * Send a {@link #ERROR} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log + */ + public static int e(String tag, String msg, Throwable tr) { + return printlns(LOG_ID_MAIN, ERROR, tag, msg, tr); + } + + /** + * What a Terrible Failure: Report a condition that should never happen. + * The error will always be logged at level ASSERT with the call stack. + * Depending on system configuration, a report may be added to the + * {@link android.os.DropBoxManager} and/or the process may be terminated + * immediately with an error dialog. + * @param tag Used to identify the source of a log message. + * @param msg The message you would like logged. + */ + public static int wtf(String tag, String msg) { + return wtf(LOG_ID_MAIN, tag, msg, null, false, false); + } + + /** + * Like {@link #wtf(String, String)}, but also writes to the log the full + * call stack. + * @hide + */ + public static int wtfStack(String tag, String msg) { + return wtf(LOG_ID_MAIN, tag, msg, null, true, false); + } + + /** + * What a Terrible Failure: Report an exception that should never happen. + * Similar to {@link #wtf(String, String)}, with an exception to log. + * @param tag Used to identify the source of a log message. + * @param tr An exception to log. + */ + public static int wtf(String tag, Throwable tr) { + return wtf(LOG_ID_MAIN, tag, tr.getMessage(), tr, false, false); + } + + /** + * What a Terrible Failure: Report an exception that should never happen. + * Similar to {@link #wtf(String, Throwable)}, with a message as well. + * @param tag Used to identify the source of a log message. + * @param msg The message you would like logged. + * @param tr An exception to log. May be null. + */ + public static int wtf(String tag, String msg, Throwable tr) { + return wtf(LOG_ID_MAIN, tag, msg, tr, false, false); + } + + /** + * Priority Constant for wtf. + * Added for this custom Log implementation, not in android sources. + */ + private static final int WTF = 8; + static int wtf(int logId, String tag, String msg, Throwable tr, boolean localStack, + boolean system) { + return printlns(LOG_ID_MAIN, WTF, tag, msg, tr); + } + + private static final int LOG_ID_MAIN = 0; + + private static final String[] PRIORITY_ABBREV = { "0", "1", "V", "D", "I", "W", "E", "A", "WTF" }; + + private static int println_native(int bufID, int priority, String tag, String msg) { + String res = PRIORITY_ABBREV[priority] + "/" + tag + " " + msg + System.lineSeparator(); + System.err.print(res); + return res.length(); + } + + private static int printlns(int bufID, int priority, String tag, String msg, + Throwable tr) { + StringWriter trSW = new StringWriter(); + if (tr != null) { + trSW.append(" , Exception: "); + PrintWriter trPW = new PrintWriter(trSW); + tr.printStackTrace(trPW); + trPW.flush(); + } + return println_native(bufID, priority, tag, msg + trSW.toString()); + } + +} diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedImageMother.java b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedImageMother.java similarity index 100% rename from core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedImageMother.java rename to core/src/test/java/de/danoeh/antennapod/core/feed/FeedImageMother.java diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedItemMother.java b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedItemMother.java similarity index 100% rename from core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedItemMother.java rename to core/src/test/java/de/danoeh/antennapod/core/feed/FeedItemMother.java diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedItemTest.java b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedItemTest.java similarity index 87% rename from core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedItemTest.java rename to core/src/test/java/de/danoeh/antennapod/core/feed/FeedItemTest.java index 9e12e8ae0..92aacd9d7 100644 --- a/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedItemTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedItemTest.java @@ -1,22 +1,26 @@ package de.danoeh.antennapod.core.feed; -import android.test.AndroidTestCase; +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.assertTrue; -public class FeedItemTest extends AndroidTestCase { +public class FeedItemTest { private FeedItem original; private FeedImage originalImage; private FeedItem changedFeedItem; - @Override - protected void setUp() { + @Before + public void setUp() { original = anyFeedItemWithImage(); originalImage = original.getImage(); changedFeedItem = anyFeedItemWithImage(); } + @Test public void testUpdateFromOther_feedItemImageDownloadUrlChanged() throws Exception { setNewFeedItemImageDownloadUrl(); @@ -25,6 +29,7 @@ public class FeedItemTest extends AndroidTestCase { feedItemImageWasUpdated(); } + @Test public void testUpdateFromOther_feedItemImageRemoved() throws Exception { feedItemImageRemoved(); @@ -33,6 +38,7 @@ public class FeedItemTest extends AndroidTestCase { feedItemImageWasNotUpdated(); } + @Test public void testUpdateFromOther_feedItemImageAdded() throws Exception { feedItemHadNoImage(); setNewFeedItemImageDownloadUrl(); diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedMother.java b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedMother.java similarity index 100% rename from core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedMother.java rename to core/src/test/java/de/danoeh/antennapod/core/feed/FeedMother.java diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedTest.java b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedTest.java similarity index 88% rename from core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedTest.java rename to core/src/test/java/de/danoeh/antennapod/core/feed/FeedTest.java index 8067ec93f..55f3bdafe 100644 --- a/core/src/androidTest/java/de/danoeh/antennapod/core/feed/FeedTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/feed/FeedTest.java @@ -1,41 +1,49 @@ package de.danoeh.antennapod.core.feed; -import android.test.AndroidTestCase; +import org.junit.Before; +import org.junit.Test; import static de.danoeh.antennapod.core.feed.FeedImageMother.anyFeedImage; 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 extends AndroidTestCase { +public class FeedTest { private Feed original; private FeedImage originalImage; private Feed changedFeed; - @Override - protected void setUp() { + @Before + public void setUp() { original = anyFeed(); originalImage = original.getImage(); changedFeed = anyFeed(); } + @Test public void testCompareWithOther_feedImageDownloadUrlChanged() throws Exception { setNewFeedImageDownloadUrl(); feedHasChanged(); } + @Test public void testCompareWithOther_sameFeedImage() throws Exception { changedFeed.setImage(anyFeedImage()); feedHasNotChanged(); } + @Test public void testCompareWithOther_feedImageRemoved() throws Exception { feedImageRemoved(); feedHasNotChanged(); } + @Test public void testUpdateFromOther_feedImageDownloadUrlChanged() throws Exception { setNewFeedImageDownloadUrl(); @@ -44,6 +52,7 @@ public class FeedTest extends AndroidTestCase { feedImageWasUpdated(); } + @Test public void testUpdateFromOther_feedImageRemoved() throws Exception { feedImageRemoved(); @@ -52,6 +61,7 @@ public class FeedTest extends AndroidTestCase { feedImageWasNotUpdated(); } + @Test public void testUpdateFromOther_feedImageAdded() throws Exception { feedHadNoImage(); setNewFeedImageDownloadUrl(); diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/util/LongLongMapTest.java b/core/src/test/java/de/danoeh/antennapod/core/util/LongLongMapTest.java similarity index 92% rename from core/src/androidTest/java/de/danoeh/antennapod/core/util/LongLongMapTest.java rename to core/src/test/java/de/danoeh/antennapod/core/util/LongLongMapTest.java index d75cd5c77..0ed77eb9f 100644 --- a/core/src/androidTest/java/de/danoeh/antennapod/core/util/LongLongMapTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/util/LongLongMapTest.java @@ -1,9 +1,12 @@ package de.danoeh.antennapod.core.util; -import android.test.AndroidTestCase; +import org.junit.Test; -public class LongLongMapTest extends AndroidTestCase { +import static org.junit.Assert.assertEquals; +public class LongLongMapTest { + + @Test public void testEmptyMap() { LongIntMap map = new LongIntMap(); assertEquals(0, map.size()); @@ -16,6 +19,7 @@ public class LongLongMapTest extends AndroidTestCase { assertEquals(1, map.hashCode()); } + @Test public void testSingleElement() { LongIntMap map = new LongIntMap(); map.put(17, 42); @@ -28,6 +32,7 @@ public class LongLongMapTest extends AndroidTestCase { assertEquals(true, map.delete(17)); } + @Test public void testAddAndDelete() { LongIntMap map = new LongIntMap(); for(int i=0; i < 100; i++) { @@ -44,6 +49,7 @@ public class LongLongMapTest extends AndroidTestCase { } } + @Test public void testOverwrite() { LongIntMap map = new LongIntMap(); map.put(17, 42); From eb0ef1e2014c8e1b8f7ff76359bd476cc52fd7b5 Mon Sep 17 00:00:00 2001 From: orionlee Date: Fri, 18 May 2018 13:42:39 -0700 Subject: [PATCH 4/5] core tests: Make DownloadServiceTest be a unit test (the portion of DownloadService tested is all in-memory logic). --- .../antennapod/core/service/download/DownloadService.java | 4 +--- .../core/service/download/DownloadServiceTest.java | 8 ++++++-- 2 files changed, 7 insertions(+), 5 deletions(-) rename core/src/{androidTest => test}/java/de/danoeh/antennapod/core/service/download/DownloadServiceTest.java (89%) diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java index a62c9d8bf..ae103ee18 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java @@ -7,8 +7,6 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.media.MediaMetadataRetriever; import android.os.Binder; import android.os.Build; @@ -1107,7 +1105,7 @@ public class DownloadService extends Service { * that every image reference is unique. */ @VisibleForTesting - public static void removeDuplicateImages(Feed feed) { + static void removeDuplicateImages(Feed feed) { Set known = new HashSet<>(); for (FeedItem item : feed.getItems()) { String url = item.hasItemImage() ? item.getImage().getDownload_url() : null; diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/service/download/DownloadServiceTest.java b/core/src/test/java/de/danoeh/antennapod/core/service/download/DownloadServiceTest.java similarity index 89% rename from core/src/androidTest/java/de/danoeh/antennapod/core/service/download/DownloadServiceTest.java rename to core/src/test/java/de/danoeh/antennapod/core/service/download/DownloadServiceTest.java index ee27f6bbd..e40de2064 100644 --- a/core/src/androidTest/java/de/danoeh/antennapod/core/service/download/DownloadServiceTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/service/download/DownloadServiceTest.java @@ -1,6 +1,7 @@ package de.danoeh.antennapod.core.service.download; -import android.test.AndroidTestCase; + +import org.junit.Test; import java.util.ArrayList; import java.util.List; @@ -9,8 +10,11 @@ import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedImage; import de.danoeh.antennapod.core.feed.FeedItem; -public class DownloadServiceTest extends AndroidTestCase { +import static org.junit.Assert.assertEquals; +public class DownloadServiceTest { + + @Test public void testRemoveDuplicateImages() { List items = new ArrayList<>(); for (int i = 0; i < 50; i++) { From 1f14d8482e7e99b157a2a398c557387c06b48946 Mon Sep 17 00:00:00 2001 From: orionlee Date: Fri, 18 May 2018 13:44:00 -0700 Subject: [PATCH 5/5] core tests: DateUtilsTest - states why it remains to be an androidTest. --- .../antennapod/core/util/DateUtilsTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/util/DateUtilsTest.java b/core/src/androidTest/java/de/danoeh/antennapod/core/util/DateUtilsTest.java index c7c9d98a9..d5efdbc24 100644 --- a/core/src/androidTest/java/de/danoeh/antennapod/core/util/DateUtilsTest.java +++ b/core/src/androidTest/java/de/danoeh/antennapod/core/util/DateUtilsTest.java @@ -7,6 +7,14 @@ import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; +/** + * Unit test for {@link DateUtils}. + * + * Note: It NEEDS to be run in android devices, i.e., it cannot be run in standard JDK, because + * the test invokes some android platform-specific behavior in the underlying + * {@link java.text.SimpleDateFormat} used by {@link DateUtils}. + * + */ public class DateUtilsTest extends AndroidTestCase { public void testParseDateWithMicroseconds() throws Exception { @@ -99,6 +107,12 @@ public class DateUtilsTest extends AndroidTestCase { assertEquals(expected, actual); } + /** + * Requires Android platform. + * + * Reason: Standard JDK cannot parse timezone -08:00 (ISO 8601 format). It only accepts + * -0800 (RFC 822 format) + */ public void testParseDateWithNoTimezonePadding() throws Exception { GregorianCalendar exp = new GregorianCalendar(2017, 1, 22, 22, 28, 0); exp.setTimeZone(TimeZone.getTimeZone("UTC")); @@ -107,6 +121,12 @@ public class DateUtilsTest extends AndroidTestCase { assertEquals(expected, actual); } + /** + * Requires Android platform. Root cause: {@link DateUtils} implementation makes + * use of ISO 8601 time zone, which does not work on standard JDK. + * + * @see #testParseDateWithNoTimezonePadding() + */ public void testParseDateWithForCest() throws Exception { GregorianCalendar exp1 = new GregorianCalendar(2017, 0, 28, 22, 0, 0); exp1.setTimeZone(TimeZone.getTimeZone("UTC"));