Merge pull request #338 from wb9688/parse-duration-string-test

Add tests for parseDurationString()
This commit is contained in:
Tobias Groza 2020-06-15 11:01:21 +02:00 committed by GitHub
commit 92f6754f0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -142,9 +142,10 @@ public class YoutubeParsingHelper {
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));
}

View file

@ -5,9 +5,11 @@ import org.junit.Test;
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 class YoutubeParsingHelperTest {
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 "));
}
}