summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2019-03-03 23:55:52 +0100
committerByteHamster <info@bytehamster.com>2019-03-03 23:55:52 +0100
commitc50d37fa1bbabd60278aecc9516a4e18e6d0dc10 (patch)
tree244134dda9958fb6849ccddae29098fe29c6bff6 /core
parent1593a0607774a157dffa6c95e068b6ab3b077cf7 (diff)
downloadAntennaPod-c50d37fa1bbabd60278aecc9516a4e18e6d0dc10.zip
Moved some implementation tests to unit tests
Diffstat (limited to 'core')
-rw-r--r--core/src/test/java/de/danoeh/antennapod/core/util/ConverterTest.java39
-rw-r--r--core/src/test/java/de/danoeh/antennapod/core/util/RewindAfterPauseUtilTest.java56
-rw-r--r--core/src/test/java/de/danoeh/antennapod/core/util/URIUtilTest.java24
3 files changed, 119 insertions, 0 deletions
diff --git a/core/src/test/java/de/danoeh/antennapod/core/util/ConverterTest.java b/core/src/test/java/de/danoeh/antennapod/core/util/ConverterTest.java
new file mode 100644
index 000000000..54e5462d0
--- /dev/null
+++ b/core/src/test/java/de/danoeh/antennapod/core/util/ConverterTest.java
@@ -0,0 +1,39 @@
+package de.danoeh.antennapod.core.util;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test class for converter
+ */
+public class ConverterTest {
+
+ @Test
+ public void testGetDurationStringLong() {
+ String expected = "13:05:10";
+ int input = 47110000;
+ assertEquals(expected, Converter.getDurationStringLong(input));
+ }
+
+ @Test
+ public void testGetDurationStringShort() {
+ String expected = "13:05";
+ assertEquals(expected, Converter.getDurationStringShort(47110000, true));
+ assertEquals(expected, Converter.getDurationStringShort(785000, false));
+ }
+
+ @Test
+ public void testDurationStringLongToMs() {
+ String input = "01:20:30";
+ long expected = 4830000;
+ assertEquals(expected, Converter.durationStringLongToMs(input));
+ }
+
+ @Test
+ public void testDurationStringShortToMs() {
+ String input = "8:30";
+ assertEquals(30600000, Converter.durationStringShortToMs(input, true));
+ assertEquals(510000, Converter.durationStringShortToMs(input, false));
+ }
+}
diff --git a/core/src/test/java/de/danoeh/antennapod/core/util/RewindAfterPauseUtilTest.java b/core/src/test/java/de/danoeh/antennapod/core/util/RewindAfterPauseUtilTest.java
new file mode 100644
index 000000000..dc64f6ae0
--- /dev/null
+++ b/core/src/test/java/de/danoeh/antennapod/core/util/RewindAfterPauseUtilTest.java
@@ -0,0 +1,56 @@
+package de.danoeh.antennapod.core.util;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for {@link RewindAfterPauseUtils}.
+ */
+public class RewindAfterPauseUtilTest {
+
+ @Test
+ public void testCalculatePositionWithRewindNoRewind() {
+ final int ORIGINAL_POSITION = 10000;
+ long lastPlayed = System.currentTimeMillis();
+ int position = RewindAfterPauseUtils.calculatePositionWithRewind(ORIGINAL_POSITION, lastPlayed);
+
+ assertEquals(ORIGINAL_POSITION, position);
+ }
+
+ @Test
+ public void testCalculatePositionWithRewindSmallRewind() {
+ final int ORIGINAL_POSITION = 10000;
+ long lastPlayed = System.currentTimeMillis() - RewindAfterPauseUtils.ELAPSED_TIME_FOR_SHORT_REWIND - 1000;
+ int position = RewindAfterPauseUtils.calculatePositionWithRewind(ORIGINAL_POSITION, lastPlayed);
+
+ assertEquals(ORIGINAL_POSITION - RewindAfterPauseUtils.SHORT_REWIND, position);
+ }
+
+ @Test
+ public void testCalculatePositionWithRewindMediumRewind() {
+ final int ORIGINAL_POSITION = 10000;
+ long lastPlayed = System.currentTimeMillis() - RewindAfterPauseUtils.ELAPSED_TIME_FOR_MEDIUM_REWIND - 1000;
+ int position = RewindAfterPauseUtils.calculatePositionWithRewind(ORIGINAL_POSITION, lastPlayed);
+
+ assertEquals(ORIGINAL_POSITION - RewindAfterPauseUtils.MEDIUM_REWIND, position);
+ }
+
+ @Test
+ public void testCalculatePositionWithRewindLongRewind() {
+ final int ORIGINAL_POSITION = 30000;
+ long lastPlayed = System.currentTimeMillis() - RewindAfterPauseUtils.ELAPSED_TIME_FOR_LONG_REWIND - 1000;
+ int position = RewindAfterPauseUtils.calculatePositionWithRewind(ORIGINAL_POSITION, lastPlayed);
+
+ assertEquals(ORIGINAL_POSITION - RewindAfterPauseUtils.LONG_REWIND, position);
+ }
+
+ @Test
+ public void testCalculatePositionWithRewindNegativeNumber() {
+ final int ORIGINAL_POSITION = 100;
+ long lastPlayed = System.currentTimeMillis() - RewindAfterPauseUtils.ELAPSED_TIME_FOR_LONG_REWIND - 1000;
+ int position = RewindAfterPauseUtils.calculatePositionWithRewind(ORIGINAL_POSITION, lastPlayed);
+
+ assertEquals(0, position);
+ }
+}
diff --git a/core/src/test/java/de/danoeh/antennapod/core/util/URIUtilTest.java b/core/src/test/java/de/danoeh/antennapod/core/util/URIUtilTest.java
new file mode 100644
index 000000000..3feb4d376
--- /dev/null
+++ b/core/src/test/java/de/danoeh/antennapod/core/util/URIUtilTest.java
@@ -0,0 +1,24 @@
+package de.danoeh.antennapod.core.util;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test class for URIUtil
+ */
+public class URIUtilTest {
+
+ @Test
+ public void testGetURIFromRequestUrlShouldNotEncode() {
+ final String testUrl = "http://example.com/this%20is%20encoded";
+ assertEquals(testUrl, URIUtil.getURIFromRequestUrl(testUrl).toString());
+ }
+
+ @Test
+ public void testGetURIFromRequestUrlShouldEncode() {
+ final String testUrl = "http://example.com/this is not encoded";
+ final String expected = "http://example.com/this%20is%20not%20encoded";
+ assertEquals(expected, URIUtil.getURIFromRequestUrl(testUrl).toString());
+ }
+}