Add tests for parseDurationString()

This commit is contained in:
wb9688 2020-05-30 17:20:54 +02:00
parent bda83fe6a5
commit 33b1121fc7
2 changed files with 13 additions and 3 deletions

View File

@ -142,9 +142,10 @@ public class YoutubeParsingHelper {
default: default:
throw new ParsingException("Error duration string with unknown format: " + input); throw new ParsingException("Error duration string with unknown format: " + input);
} }
return ((((Long.parseLong(Utils.removeNonDigitCharacters(days)) * 24)
+ Long.parseLong(Utils.removeNonDigitCharacters(hours)) * 60) return ((Long.parseLong(Utils.removeNonDigitCharacters(days)) * 24
+ Long.parseLong(Utils.removeNonDigitCharacters(minutes))) * 60) + Long.parseLong(Utils.removeNonDigitCharacters(hours))) * 60
+ Long.parseLong(Utils.removeNonDigitCharacters(minutes))) * 60
+ Long.parseLong(Utils.removeNonDigitCharacters(seconds)); + Long.parseLong(Utils.removeNonDigitCharacters(seconds));
} }

View File

@ -5,9 +5,11 @@ import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl; import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import java.io.IOException; import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class YoutubeParsingHelperTest { public class YoutubeParsingHelperTest {
@ -27,4 +29,11 @@ public class YoutubeParsingHelperTest {
assertTrue("Hardcoded YouTube Music keys are not valid anymore", assertTrue("Hardcoded YouTube Music keys are not valid anymore",
YoutubeParsingHelper.areHardcodedYoutubeMusicKeysValid()); YoutubeParsingHelper.areHardcodedYoutubeMusicKeysValid());
} }
@Test
public void testParseDurationString() throws ParsingException {
assertEquals(1162567, YoutubeParsingHelper.parseDurationString("12:34:56:07"));
assertEquals(4445767, YoutubeParsingHelper.parseDurationString("1,234:56:07"));
assertEquals(754, YoutubeParsingHelper.parseDurationString("12:34 "));
}
} }