convert android tests to junit tests

This commit is contained in:
Christian Schabesberger 2017-02-16 00:17:43 +01:00
parent a5252bb765
commit 477f182b43
12 changed files with 128 additions and 101 deletions

View File

@ -45,8 +45,8 @@ dependencies {
compile 'com.google.android.exoplayer:exoplayer:r1.5.5' compile 'com.google.android.exoplayer:exoplayer:r1.5.5'
compile 'com.google.code.gson:gson:2.4' compile 'com.google.code.gson:gson:2.4'
compile 'com.nononsenseapps:filepicker:3.0.0' compile 'com.nononsenseapps:filepicker:3.0.0'
compile 'ch.acra:acra:4.9.0'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19' testCompile 'org.mockito:mockito-core:1.10.19'
compile 'ch.acra:acra:4.9.0' testCompile 'org.json:json:20160810'
compile 'com.google.android.gms:play-services-appindexing:8.4.0'
} }

View File

@ -1,52 +0,0 @@
package org.schabi.newpipe.extractor.youtube;
import android.test.AndroidTestCase;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.stream_info.StreamExtractor;
import java.io.IOException;
/**
* Created by Christian Schabesberger on 11.03.16.
*
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
* YoutubeStreamExtractorLiveStreamTest.java is part of NewPipe.
*
* NewPipe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NewPipe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
public class YoutubeStreamExtractorLiveStreamTest extends AndroidTestCase {
private StreamExtractor extractor;
public void setUp() throws IOException, ExtractionException {
//todo: make the extractor not throw over a livestream
/*
NewPipe.init(Downloader.getInstance());
extractor = NewPipe.getService("Youtube")
.getExtractorInstance("https://www.youtube.com/watch?v=J0s6NjqdjLE", Downloader.getInstance());
*/
}
public void testStreamType() throws ParsingException {
assertTrue(true);
// assertTrue(extractor.getStreamType() == AbstractVideoInfo.StreamType.LIVE_STREAM);
}
}

View File

@ -170,11 +170,7 @@
<meta-data <meta-data
android:name="android.support.FILE_PROVIDER_PATHS" android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/> android:resource="@xml/provider_paths"/>
</provider><!-- ATTENTION: This was auto-generated to add Google Play services to your project for </provider>
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application> </application>
</manifest> </manifest>

View File

@ -29,7 +29,7 @@ import java.util.EnumSet;
public abstract class SearchEngine { public abstract class SearchEngine {
public enum Filter { public enum Filter {
VIDEO, CHANNEL, PLAY_LIST STREAM, CHANNEL, PLAY_LIST
} }
public static class NothingFoundException extends ExtractionException { public static class NothingFoundException extends ExtractionException {

View File

@ -58,9 +58,9 @@ public class YoutubeSearchEngine extends SearchEngine {
String url = "https://www.youtube.com/results" String url = "https://www.youtube.com/results"
+ "?q=" + URLEncoder.encode(query, CHARSET_UTF_8) + "?q=" + URLEncoder.encode(query, CHARSET_UTF_8)
+ "&page=" + Integer.toString(page + 1); + "&page=" + Integer.toString(page + 1);
if(filter.contains(Filter.VIDEO) && !filter.contains(Filter.CHANNEL)) { if(filter.contains(Filter.STREAM) && !filter.contains(Filter.CHANNEL)) {
url += "&sp=EgIQAQ%253D%253D"; url += "&sp=EgIQAQ%253D%253D";
} else if(!filter.contains(Filter.VIDEO) && filter.contains(Filter.CHANNEL)) { } else if(!filter.contains(Filter.STREAM) && filter.contains(Filter.CHANNEL)) {
url += "&sp=EgIQAg%253D%253D"; url += "&sp=EgIQAg%253D%253D";
} }

View File

@ -61,7 +61,7 @@ public class SearchInfoItemFragment extends Fragment {
private static final String TAG = SearchInfoItemFragment.class.toString(); private static final String TAG = SearchInfoItemFragment.class.toString();
private EnumSet<SearchEngine.Filter> filter = private EnumSet<SearchEngine.Filter> filter =
EnumSet.of(SearchEngine.Filter.CHANNEL, SearchEngine.Filter.VIDEO); EnumSet.of(SearchEngine.Filter.CHANNEL, SearchEngine.Filter.STREAM);
/** /**
* Listener for search queries * Listener for search queries
@ -300,10 +300,10 @@ public class SearchInfoItemFragment extends Fragment {
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) { switch(item.getItemId()) {
case R.id.menu_filter_all: case R.id.menu_filter_all:
changeFilter(item, EnumSet.of(SearchEngine.Filter.VIDEO, SearchEngine.Filter.CHANNEL)); changeFilter(item, EnumSet.of(SearchEngine.Filter.STREAM, SearchEngine.Filter.CHANNEL));
return true; return true;
case R.id.menu_filter_video: case R.id.menu_filter_video:
changeFilter(item, EnumSet.of(SearchEngine.Filter.VIDEO)); changeFilter(item, EnumSet.of(SearchEngine.Filter.STREAM));
return true; return true;
case R.id.menu_filter_channel: case R.id.menu_filter_channel:
changeFilter(item, EnumSet.of(SearchEngine.Filter.CHANNEL)); changeFilter(item, EnumSet.of(SearchEngine.Filter.CHANNEL));

View File

@ -1,16 +1,21 @@
package org.schabi.newpipe.extractor.youtube; package org.schabi.newpipe.extractor.services.youtube.youtube;
import android.test.AndroidTestCase; import org.junit.Before;
import org.junit.Test;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
/** /**
* Created by Christian Schabesberger on 12.09.16. * Created by Christian Schabesberger on 12.09.16.
* *
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org> * Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
* YoutubeSearchEngineTest.java is part of NewPipe. * YoutubeSearchEngineStreamTest.java is part of NewPipe.
* *
* NewPipe is free software: you can redistribute it and/or modify * NewPipe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -26,56 +31,70 @@ import org.schabi.newpipe.extractor.channel.ChannelExtractor;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>. * along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/ */
public class YoutubeChannelExtractorTest extends AndroidTestCase { /**
* Test for {@link ChannelExtractor}
*/
public class YoutubeChannelExtractorTest {
ChannelExtractor extractor; ChannelExtractor extractor;
@Override
@Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
NewPipe.init(Downloader.getInstance()); NewPipe.init(Downloader.getInstance());
extractor = NewPipe.getService("Youtube") extractor = NewPipe.getService("Youtube")
.getChannelExtractorInstance("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw", 0); .getChannelExtractorInstance("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw", 0);
} }
@Test
public void testGetDownloader() throws Exception { public void testGetDownloader() throws Exception {
assertNotNull(NewPipe.getDownloader()); assertNotNull(NewPipe.getDownloader());
} }
@Test
public void testGetChannelName() throws Exception { public void testGetChannelName() throws Exception {
assertEquals(extractor.getChannelName(), "Gronkh"); assertEquals(extractor.getChannelName(), "Gronkh");
} }
@Test
public void testGetAvatarUrl() throws Exception { public void testGetAvatarUrl() throws Exception {
assertTrue(extractor.getAvatarUrl(), extractor.getAvatarUrl().contains("yt3")); assertTrue(extractor.getAvatarUrl(), extractor.getAvatarUrl().contains("yt3"));
} }
@Test
public void testGetBannerurl() throws Exception { public void testGetBannerurl() throws Exception {
assertTrue(extractor.getBannerUrl(), extractor.getBannerUrl().contains("yt3")); assertTrue(extractor.getBannerUrl(), extractor.getBannerUrl().contains("yt3"));
} }
@Test
public void testGetFeedUrl() throws Exception { public void testGetFeedUrl() throws Exception {
assertTrue(extractor.getFeedUrl(), extractor.getFeedUrl().contains("feed")); assertTrue(extractor.getFeedUrl(), extractor.getFeedUrl().contains("feed"));
} }
@Test
public void testGetStreams() throws Exception { public void testGetStreams() throws Exception {
assertTrue("no streams are received", !extractor.getStreams().getItemList().isEmpty()); assertTrue("no streams are received", !extractor.getStreams().getItemList().isEmpty());
} }
@Test
public void testGetStreamsErrors() throws Exception { public void testGetStreamsErrors() throws Exception {
assertTrue("errors during stream list extraction", extractor.getStreams().getErrors().isEmpty()); assertTrue("errors during stream list extraction", extractor.getStreams().getErrors().isEmpty());
} }
@Test
public void testHasNextPage() throws Exception { public void testHasNextPage() throws Exception {
// this particular example (link) has a next page !!! // this particular example (link) has a next page !!!
assertTrue("no next page link found", extractor.hasNextPage()); assertTrue("no next page link found", extractor.hasNextPage());
} }
@Test
public void testGetNextPage() throws Exception { public void testGetNextPage() throws Exception {
extractor = NewPipe.getService("Youtube") extractor = NewPipe.getService("Youtube")
.getChannelExtractorInstance("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw", 1); .getChannelExtractorInstance("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw", 1);
assertTrue("next page didn't have content", !extractor.getStreams().getItemList().isEmpty()); assertTrue("next page didn't have content", !extractor.getStreams().getItemList().isEmpty());
} }
@Test
public void testGetNextNextPageUrl() throws Exception { public void testGetNextNextPageUrl() throws Exception {
extractor = NewPipe.getService("Youtube") extractor = NewPipe.getService("Youtube")
.getChannelExtractorInstance("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw", 2); .getChannelExtractorInstance("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw", 2);

View File

@ -1,19 +1,26 @@
package org.schabi.newpipe.extractor.youtube; package org.schabi.newpipe.extractor.services.youtube.youtube;
import android.test.AndroidTestCase; import org.junit.Before;
import org.junit.Test;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.search.SearchEngine; import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.search.SearchResult; import org.schabi.newpipe.extractor.search.SearchResult;
import java.util.List; import java.util.EnumSet;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
/** /**
* Created by Christian Schabesberger on 29.12.15. * Created by Christian Schabesberger on 29.12.15.
* *
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org> * Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
* YoutubeSearchEngineTest.java is part of NewPipe. * YoutubeSearchEngineStreamTest.java is part of NewPipe.
* *
* NewPipe is free software: you can redistribute it and/or modify * NewPipe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -29,26 +36,37 @@ import java.util.List;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>. * along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/ */
public class YoutubeSearchEngineTest extends AndroidTestCase { /**
* Test for {@link SearchEngine}
*/
public class YoutubeSearchEngineStreamTest {
private SearchResult result; private SearchResult result;
@Override @Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
NewPipe.init(Downloader.getInstance()); NewPipe.init(Downloader.getInstance());
SearchEngine engine = NewPipe.getService("Youtube").getSearchEngineInstance(); SearchEngine engine = NewPipe.getService("Youtube").getSearchEngineInstance();
result = engine.search("this is something boring", 0, "de").getSearchResult(); result = engine.search("this is something boring", 0, "de",
EnumSet.of(SearchEngine.Filter.STREAM)).getSearchResult();
} }
@Test
public void testResultList() { public void testResultList() {
assertFalse(result.resultList.isEmpty()); assertFalse(result.resultList.isEmpty());
} }
@Test
public void testChannelItemType() {
assertEquals(result.resultList.get(0).infoType(), InfoItem.InfoType.STREAM);
}
@Test
public void testResultErrors() { public void testResultErrors() {
assertTrue(result.errors == null || result.errors.isEmpty()); assertTrue(result.errors == null || result.errors.isEmpty());
} }
@Test
public void testSuggestion() { public void testSuggestion() {
//todo write a real test //todo write a real test
assertTrue(result.suggestion != null); assertTrue(result.suggestion != null);

View File

@ -1,13 +1,13 @@
package org.schabi.newpipe.extractor.youtube; package org.schabi.newpipe.extractor.services.youtube.youtube;
import android.test.AndroidTestCase;
import org.junit.Before;
import org.junit.Test;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.SuggestionExtractor; import org.schabi.newpipe.extractor.SuggestionExtractor;
import org.schabi.newpipe.extractor.services.youtube.YoutubeSuggestionExtractor; import org.schabi.newpipe.extractor.services.youtube.YoutubeSuggestionExtractor;
import java.util.List; import java.util.List;
import static junit.framework.Assert.assertFalse;
/** /**
* Created by Christian Schabesberger on 18.11.16. * Created by Christian Schabesberger on 18.11.16.
@ -29,18 +29,21 @@ import java.util.List;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>. * along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/ */
public class YoutubeSearchResultTest extends AndroidTestCase { /**
* Test for {@link SuggestionExtractor}
*/
public class YoutubeSearchResultTest {
List<String> suggestionReply; List<String> suggestionReply;
@Override @Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
NewPipe.init(Downloader.getInstance()); NewPipe.init(Downloader.getInstance());
SuggestionExtractor engine = new YoutubeSuggestionExtractor(0); SuggestionExtractor engine = new YoutubeSuggestionExtractor(0);
suggestionReply = engine.suggestionList("hello", "de"); suggestionReply = engine.suggestionList("hello", "de");
} }
@Test
public void testIfSuggestions() { public void testIfSuggestions() {
assertFalse(suggestionReply.isEmpty()); assertFalse(suggestionReply.isEmpty());
} }

View File

@ -1,7 +1,7 @@
package org.schabi.newpipe.extractor.youtube; package org.schabi.newpipe.extractor.services.youtube.youtube;
import android.test.AndroidTestCase;
import org.junit.Before;
import org.junit.Test;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.AbstractStreamInfo; import org.schabi.newpipe.extractor.AbstractStreamInfo;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
@ -12,6 +12,8 @@ import org.schabi.newpipe.extractor.stream_info.VideoStream;
import java.io.IOException; import java.io.IOException;
import static junit.framework.Assert.assertTrue;
/** /**
* Created by Christian Schabesberger on 30.12.15. * Created by Christian Schabesberger on 30.12.15.
* *
@ -32,22 +34,27 @@ import java.io.IOException;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>. * along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/ */
public class YoutubeStreamExtractorDefaultTest extends AndroidTestCase { /**
* Test for {@link StreamExtractor}
*/
public class YoutubeStreamExtractorDefaultTest {
public static final String HTTPS = "https://"; public static final String HTTPS = "https://";
private StreamExtractor extractor; private StreamExtractor extractor;
@Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
NewPipe.init(Downloader.getInstance()); NewPipe.init(Downloader.getInstance());
extractor = NewPipe.getService("Youtube") extractor = NewPipe.getService("Youtube")
.getExtractorInstance("https://www.youtube.com/watch?v=YQHsXMglC9A"); .getExtractorInstance("https://www.youtube.com/watch?v=YQHsXMglC9A");
} }
@Test
public void testGetInvalidTimeStamp() throws ParsingException { public void testGetInvalidTimeStamp() throws ParsingException {
assertTrue(Integer.toString(extractor.getTimeStamp()), assertTrue(Integer.toString(extractor.getTimeStamp()),
extractor.getTimeStamp() <= 0); extractor.getTimeStamp() <= 0);
} }
@Test
public void testGetValidTimeStamp() throws ExtractionException, IOException { public void testGetValidTimeStamp() throws ExtractionException, IOException {
StreamExtractor extractor = StreamExtractor extractor =
NewPipe.getService("Youtube") NewPipe.getService("Youtube")
@ -56,49 +63,60 @@ public class YoutubeStreamExtractorDefaultTest extends AndroidTestCase {
extractor.getTimeStamp() == 174); extractor.getTimeStamp() == 174);
} }
@Test
public void testGetTitle() throws ParsingException { public void testGetTitle() throws ParsingException {
assertTrue(!extractor.getTitle().isEmpty()); assertTrue(!extractor.getTitle().isEmpty());
} }
@Test
public void testGetDescription() throws ParsingException { public void testGetDescription() throws ParsingException {
assertTrue(extractor.getDescription() != null); assertTrue(extractor.getDescription() != null);
} }
@Test
public void testGetUploader() throws ParsingException { public void testGetUploader() throws ParsingException {
assertTrue(!extractor.getUploader().isEmpty()); assertTrue(!extractor.getUploader().isEmpty());
} }
@Test
public void testGetLength() throws ParsingException { public void testGetLength() throws ParsingException {
assertTrue(extractor.getLength() > 0); assertTrue(extractor.getLength() > 0);
} }
@Test
public void testGetViewCount() throws ParsingException { public void testGetViewCount() throws ParsingException {
assertTrue(Long.toString(extractor.getViewCount()), assertTrue(Long.toString(extractor.getViewCount()),
extractor.getViewCount() > /* specific to that video */ 1224000074); extractor.getViewCount() > /* specific to that video */ 1224000074);
} }
@Test
public void testGetUploadDate() throws ParsingException { public void testGetUploadDate() throws ParsingException {
assertTrue(extractor.getUploadDate().length() > 0); assertTrue(extractor.getUploadDate().length() > 0);
} }
@Test
public void testGetChannelUrl() throws ParsingException { public void testGetChannelUrl() throws ParsingException {
assertTrue(extractor.getChannelUrl().length() > 0); assertTrue(extractor.getChannelUrl().length() > 0);
} }
@Test
public void testGetThumbnailUrl() throws ParsingException { public void testGetThumbnailUrl() throws ParsingException {
assertTrue(extractor.getThumbnailUrl(), assertTrue(extractor.getThumbnailUrl(),
extractor.getThumbnailUrl().contains(HTTPS)); extractor.getThumbnailUrl().contains(HTTPS));
} }
@Test
public void testGetUploaderThumbnailUrl() throws ParsingException { public void testGetUploaderThumbnailUrl() throws ParsingException {
assertTrue(extractor.getUploaderThumbnailUrl(), assertTrue(extractor.getUploaderThumbnailUrl(),
extractor.getUploaderThumbnailUrl().contains(HTTPS)); extractor.getUploaderThumbnailUrl().contains(HTTPS));
} }
@Test
public void testGetAudioStreams() throws ParsingException { public void testGetAudioStreams() throws ParsingException {
assertTrue(!extractor.getAudioStreams().isEmpty()); assertTrue(!extractor.getAudioStreams().isEmpty());
} }
@Test
public void testGetVideoStreams() throws ParsingException { public void testGetVideoStreams() throws ParsingException {
for(VideoStream s : extractor.getVideoStreams()) { for(VideoStream s : extractor.getVideoStreams()) {
assertTrue(s.url, assertTrue(s.url,
@ -109,10 +127,12 @@ public class YoutubeStreamExtractorDefaultTest extends AndroidTestCase {
} }
} }
@Test
public void testStreamType() throws ParsingException { public void testStreamType() throws ParsingException {
assertTrue(extractor.getStreamType() == AbstractStreamInfo.StreamType.VIDEO_STREAM); assertTrue(extractor.getStreamType() == AbstractStreamInfo.StreamType.VIDEO_STREAM);
} }
@Test
public void testGetDashMpd() throws ParsingException { public void testGetDashMpd() throws ParsingException {
assertTrue(extractor.getDashMpdUrl(), assertTrue(extractor.getDashMpdUrl(),
extractor.getDashMpdUrl() != null || !extractor.getDashMpdUrl().isEmpty()); extractor.getDashMpdUrl() != null || !extractor.getDashMpdUrl().isEmpty());

View File

@ -1,14 +1,14 @@
package org.schabi.newpipe.extractor.youtube; package org.schabi.newpipe.extractor.services.youtube.youtube;
import android.test.AndroidTestCase;
import org.junit.Test;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
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.services.youtube.YoutubeStreamExtractor; import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor;
import java.io.IOException; import java.io.IOException;
import static junit.framework.Assert.assertTrue;
/** /**
* Created by Christian Schabesberger on 30.12.15. * Created by Christian Schabesberger on 30.12.15.
* *
@ -31,11 +31,15 @@ import java.io.IOException;
// This class only works in Germany. // This class only works in Germany.
public class YoutubeStreamExtractorGemaTest extends AndroidTestCase { /**
* Test for {@link YoutubeStreamExtractor}
*/
public class YoutubeStreamExtractorGemaTest {
// Deaktivate this Test Case bevore uploading it githup, otherwise CI will fail. // Deaktivate this Test Case bevore uploading it githup, otherwise CI will fail.
private static final boolean testActive = false; private static final boolean testActive = false;
@Test
public void testGemaError() throws IOException, ExtractionException { public void testGemaError() throws IOException, ExtractionException {
if(testActive) { if(testActive) {
try { try {

View File

@ -1,32 +1,40 @@
package org.schabi.newpipe.extractor.youtube; package org.schabi.newpipe.extractor.services.youtube.youtube;
import android.test.AndroidTestCase;
import org.junit.Before;
import org.junit.Test;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
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 org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamUrlIdHandler;
import org.schabi.newpipe.extractor.stream_info.StreamExtractor; import org.schabi.newpipe.extractor.stream_info.StreamExtractor;
import org.schabi.newpipe.extractor.stream_info.VideoStream; import org.schabi.newpipe.extractor.stream_info.VideoStream;
import java.io.IOException; import java.io.IOException;
public class YoutubeStreamExtractorRestrictedTest extends AndroidTestCase { import static junit.framework.Assert.assertTrue;
/**
* Test for {@link YoutubeStreamUrlIdHandler}
*/
public class YoutubeStreamExtractorRestrictedTest {
public static final String HTTPS = "https://"; public static final String HTTPS = "https://";
private StreamExtractor extractor; private StreamExtractor extractor;
@Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
NewPipe.init(Downloader.getInstance()); NewPipe.init(Downloader.getInstance());
extractor = NewPipe.getService("Youtube") extractor = NewPipe.getService("Youtube")
.getExtractorInstance("https://www.youtube.com/watch?v=i6JTvzrpBy0"); .getExtractorInstance("https://www.youtube.com/watch?v=i6JTvzrpBy0");
} }
@Test
public void testGetInvalidTimeStamp() throws ParsingException { public void testGetInvalidTimeStamp() throws ParsingException {
assertTrue(Integer.toString(extractor.getTimeStamp()), assertTrue(Integer.toString(extractor.getTimeStamp()),
extractor.getTimeStamp() <= 0); extractor.getTimeStamp() <= 0);
} }
@Test
public void testGetValidTimeStamp() throws ExtractionException, IOException { public void testGetValidTimeStamp() throws ExtractionException, IOException {
StreamExtractor extractor= NewPipe.getService("Youtube") StreamExtractor extractor= NewPipe.getService("Youtube")
.getExtractorInstance("https://youtu.be/FmG385_uUys?t=174"); .getExtractorInstance("https://youtu.be/FmG385_uUys?t=174");
@ -34,49 +42,60 @@ public class YoutubeStreamExtractorRestrictedTest extends AndroidTestCase {
extractor.getTimeStamp() == 174); extractor.getTimeStamp() == 174);
} }
@Test
public void testGetAgeLimit() throws ParsingException { public void testGetAgeLimit() throws ParsingException {
assertTrue(extractor.getAgeLimit() == 18); assertTrue(extractor.getAgeLimit() == 18);
} }
@Test
public void testGetTitle() throws ParsingException { public void testGetTitle() throws ParsingException {
assertTrue(!extractor.getTitle().isEmpty()); assertTrue(!extractor.getTitle().isEmpty());
} }
@Test
public void testGetDescription() throws ParsingException { public void testGetDescription() throws ParsingException {
assertTrue(extractor.getDescription() != null); assertTrue(extractor.getDescription() != null);
} }
@Test
public void testGetUploader() throws ParsingException { public void testGetUploader() throws ParsingException {
assertTrue(!extractor.getUploader().isEmpty()); assertTrue(!extractor.getUploader().isEmpty());
} }
@Test
public void testGetLength() throws ParsingException { public void testGetLength() throws ParsingException {
assertTrue(extractor.getLength() > 0); assertTrue(extractor.getLength() > 0);
} }
@Test
public void testGetViews() throws ParsingException { public void testGetViews() throws ParsingException {
assertTrue(extractor.getLength() > 0); assertTrue(extractor.getLength() > 0);
} }
@Test
public void testGetUploadDate() throws ParsingException { public void testGetUploadDate() throws ParsingException {
assertTrue(extractor.getUploadDate().length() > 0); assertTrue(extractor.getUploadDate().length() > 0);
} }
@Test
public void testGetThumbnailUrl() throws ParsingException { public void testGetThumbnailUrl() throws ParsingException {
assertTrue(extractor.getThumbnailUrl(), assertTrue(extractor.getThumbnailUrl(),
extractor.getThumbnailUrl().contains(HTTPS)); extractor.getThumbnailUrl().contains(HTTPS));
} }
@Test
public void testGetUploaderThumbnailUrl() throws ParsingException { public void testGetUploaderThumbnailUrl() throws ParsingException {
assertTrue(extractor.getUploaderThumbnailUrl(), assertTrue(extractor.getUploaderThumbnailUrl(),
extractor.getUploaderThumbnailUrl().contains(HTTPS)); extractor.getUploaderThumbnailUrl().contains(HTTPS));
} }
@Test
public void testGetAudioStreams() throws ParsingException { public void testGetAudioStreams() throws ParsingException {
// audiostream not always necessary // audiostream not always necessary
//assertTrue(!extractor.getAudioStreams().isEmpty()); //assertTrue(!extractor.getAudioStreams().isEmpty());
} }
@Test
public void testGetVideoStreams() throws ParsingException { public void testGetVideoStreams() throws ParsingException {
for(VideoStream s : extractor.getVideoStreams()) { for(VideoStream s : extractor.getVideoStreams()) {
assertTrue(s.url, assertTrue(s.url,