From c50d37fa1bbabd60278aecc9516a4e18e6d0dc10 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sun, 3 Mar 2019 23:55:52 +0100 Subject: [PATCH] Moved some implementation tests to unit tests --- .../antennapod/core}/util/ConverterTest.java | 20 +++++++++++-------- .../core}/util/RewindAfterPauseUtilTest.java | 13 ++++++++---- .../antennapod/core}/util/URIUtilTest.java | 10 ++++++---- 3 files changed, 27 insertions(+), 16 deletions(-) rename {app/src/androidTest/java/de/test/antennapod => core/src/test/java/de/danoeh/antennapod/core}/util/ConverterTest.java (63%) rename {app/src/androidTest/java/de/test/antennapod => core/src/test/java/de/danoeh/antennapod/core}/util/RewindAfterPauseUtilTest.java (91%) rename {app/src/androidTest/java/de/test/antennapod => core/src/test/java/de/danoeh/antennapod/core}/util/URIUtilTest.java (76%) diff --git a/app/src/androidTest/java/de/test/antennapod/util/ConverterTest.java b/core/src/test/java/de/danoeh/antennapod/core/util/ConverterTest.java similarity index 63% rename from app/src/androidTest/java/de/test/antennapod/util/ConverterTest.java rename to core/src/test/java/de/danoeh/antennapod/core/util/ConverterTest.java index cd1a489d8..54e5462d0 100644 --- a/app/src/androidTest/java/de/test/antennapod/util/ConverterTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/util/ConverterTest.java @@ -1,33 +1,37 @@ -package de.test.antennapod.util; +package de.danoeh.antennapod.core.util; -import android.test.AndroidTestCase; +import org.junit.Test; -import de.danoeh.antennapod.core.util.Converter; +import static org.junit.Assert.assertEquals; /** * Test class for converter */ -public class ConverterTest extends AndroidTestCase { +public class ConverterTest { - public void testGetDurationStringLong() throws Exception { + @Test + public void testGetDurationStringLong() { String expected = "13:05:10"; int input = 47110000; assertEquals(expected, Converter.getDurationStringLong(input)); } - public void testGetDurationStringShort() throws Exception { + @Test + public void testGetDurationStringShort() { String expected = "13:05"; assertEquals(expected, Converter.getDurationStringShort(47110000, true)); assertEquals(expected, Converter.getDurationStringShort(785000, false)); } - public void testDurationStringLongToMs() throws Exception { + @Test + public void testDurationStringLongToMs() { String input = "01:20:30"; long expected = 4830000; assertEquals(expected, Converter.durationStringLongToMs(input)); } - public void testDurationStringShortToMs() throws Exception { + @Test + public void testDurationStringShortToMs() { String input = "8:30"; assertEquals(30600000, Converter.durationStringShortToMs(input, true)); assertEquals(510000, Converter.durationStringShortToMs(input, false)); diff --git a/app/src/androidTest/java/de/test/antennapod/util/RewindAfterPauseUtilTest.java b/core/src/test/java/de/danoeh/antennapod/core/util/RewindAfterPauseUtilTest.java similarity index 91% rename from app/src/androidTest/java/de/test/antennapod/util/RewindAfterPauseUtilTest.java rename to core/src/test/java/de/danoeh/antennapod/core/util/RewindAfterPauseUtilTest.java index d564d0492..dc64f6ae0 100644 --- a/app/src/androidTest/java/de/test/antennapod/util/RewindAfterPauseUtilTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/util/RewindAfterPauseUtilTest.java @@ -1,14 +1,15 @@ -package de.test.antennapod.util; +package de.danoeh.antennapod.core.util; -import junit.framework.TestCase; +import org.junit.Test; -import de.danoeh.antennapod.core.util.RewindAfterPauseUtils; +import static org.junit.Assert.assertEquals; /** * Tests for {@link RewindAfterPauseUtils}. */ -public class RewindAfterPauseUtilTest extends TestCase { +public class RewindAfterPauseUtilTest { + @Test public void testCalculatePositionWithRewindNoRewind() { final int ORIGINAL_POSITION = 10000; long lastPlayed = System.currentTimeMillis(); @@ -17,6 +18,7 @@ public class RewindAfterPauseUtilTest extends TestCase { assertEquals(ORIGINAL_POSITION, position); } + @Test public void testCalculatePositionWithRewindSmallRewind() { final int ORIGINAL_POSITION = 10000; long lastPlayed = System.currentTimeMillis() - RewindAfterPauseUtils.ELAPSED_TIME_FOR_SHORT_REWIND - 1000; @@ -25,6 +27,7 @@ public class RewindAfterPauseUtilTest extends TestCase { 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; @@ -33,6 +36,7 @@ public class RewindAfterPauseUtilTest extends TestCase { 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; @@ -41,6 +45,7 @@ public class RewindAfterPauseUtilTest extends TestCase { 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; diff --git a/app/src/androidTest/java/de/test/antennapod/util/URIUtilTest.java b/core/src/test/java/de/danoeh/antennapod/core/util/URIUtilTest.java similarity index 76% rename from app/src/androidTest/java/de/test/antennapod/util/URIUtilTest.java rename to core/src/test/java/de/danoeh/antennapod/core/util/URIUtilTest.java index 2cca6b4dc..3feb4d376 100644 --- a/app/src/androidTest/java/de/test/antennapod/util/URIUtilTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/util/URIUtilTest.java @@ -1,19 +1,21 @@ -package de.test.antennapod.util; +package de.danoeh.antennapod.core.util; -import android.test.AndroidTestCase; +import org.junit.Test; -import de.danoeh.antennapod.core.util.URIUtil; +import static org.junit.Assert.assertEquals; /** * Test class for URIUtil */ -public class URIUtilTest extends AndroidTestCase { +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";