From 33b1121fc7f3a92f0b1b21bb66d6abc87b4e48c5 Mon Sep 17 00:00:00 2001 From: wb9688 Date: Sat, 30 May 2020 17:20:54 +0200 Subject: [PATCH] Add tests for parseDurationString() --- .../extractor/services/youtube/YoutubeParsingHelper.java | 7 ++++--- .../services/youtube/YoutubeParsingHelperTest.java | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java index 6df9b4b87e..748766c104 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java @@ -142,9 +142,10 @@ public static long parseDurationString(String input) default: throw new ParsingException("Error duration string with unknown format: " + input); } - return ((((Long.parseLong(Utils.removeNonDigitCharacters(days)) * 24) - + Long.parseLong(Utils.removeNonDigitCharacters(hours)) * 60) - + Long.parseLong(Utils.removeNonDigitCharacters(minutes))) * 60) + + return ((Long.parseLong(Utils.removeNonDigitCharacters(days)) * 24 + + Long.parseLong(Utils.removeNonDigitCharacters(hours))) * 60 + + Long.parseLong(Utils.removeNonDigitCharacters(minutes))) * 60 + Long.parseLong(Utils.removeNonDigitCharacters(seconds)); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelperTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelperTest.java index 0a3e007fc2..34a3008761 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelperTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelperTest.java @@ -5,9 +5,11 @@ import org.schabi.newpipe.DownloaderTestImpl; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.ParsingException; import java.io.IOException; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class YoutubeParsingHelperTest { @@ -27,4 +29,11 @@ public void testAreHardcodedYoutubeMusicKeysValid() throws IOException, Extracti assertTrue("Hardcoded YouTube Music keys are not valid anymore", 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 ")); + } }