Merge pull request #3047 from ByteHamster/move-to-unit-test

Moved some implementation tests to unit tests
This commit is contained in:
H. Lehmann 2019-03-04 18:56:51 +01:00 committed by GitHub
commit cfa9304c82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 16 deletions

View File

@ -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));

View File

@ -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;

View File

@ -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";