2017-08-06 22:20:15 +02:00
package org.schabi.newpipe.extractor ;
import org.junit.Test ;
import java.util.HashSet ;
2017-08-16 04:40:03 +02:00
import static org.junit.Assert.* ;
import static org.schabi.newpipe.extractor.NewPipe.getServiceByUrl ;
2017-08-07 18:12:51 +02:00
import static org.schabi.newpipe.extractor.ServiceList.YouTube ;
2017-08-06 22:20:15 +02:00
public class NewPipeTest {
@Test
public void getAllServicesTest ( ) throws Exception {
2018-02-10 03:46:05 +01:00
assertEquals ( NewPipe . getServices ( ) . size ( ) , ServiceList . all ( ) . size ( ) ) ;
2017-08-06 22:20:15 +02:00
}
@Test
public void testAllServicesHaveDifferentId ( ) throws Exception {
HashSet < Integer > servicesId = new HashSet < > ( ) ;
for ( StreamingService streamingService : NewPipe . getServices ( ) ) {
2018-02-10 03:46:05 +01:00
String errorMsg = " There are services with the same id = " + streamingService . getServiceId ( ) + " (current service > " + streamingService . getServiceInfo ( ) . getName ( ) + " ) " ;
2017-08-06 22:20:15 +02:00
assertTrue ( errorMsg , servicesId . add ( streamingService . getServiceId ( ) ) ) ;
}
}
@Test
public void getServiceWithId ( ) throws Exception {
2018-02-10 03:46:05 +01:00
assertEquals ( NewPipe . getService ( YouTube . getServiceId ( ) ) , YouTube ) ;
2017-08-06 22:20:15 +02:00
}
@Test
public void getServiceWithName ( ) throws Exception {
2018-02-10 03:46:05 +01:00
assertEquals ( NewPipe . getService ( YouTube . getServiceInfo ( ) . getName ( ) ) , YouTube ) ;
2017-08-06 22:20:15 +02:00
}
@Test
public void getServiceWithUrl ( ) throws Exception {
2018-02-10 03:46:05 +01:00
assertEquals ( getServiceByUrl ( " https://www.youtube.com/watch?v=_r6CgaFNAGg " ) , YouTube ) ;
assertEquals ( getServiceByUrl ( " https://www.youtube.com/channel/UCi2bIyFtz-JdI-ou8kaqsqg " ) , YouTube ) ;
assertEquals ( getServiceByUrl ( " https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH " ) , YouTube ) ;
assertNotEquals ( getServiceByUrl ( " https://soundcloud.com/pegboardnerds " ) , YouTube ) ;
2017-08-06 22:20:15 +02:00
}
@Test
public void getIdWithServiceName ( ) throws Exception {
2018-02-10 03:46:05 +01:00
assertEquals ( NewPipe . getIdOfService ( YouTube . getServiceInfo ( ) . getName ( ) ) , YouTube . getServiceId ( ) ) ;
2017-08-06 22:20:15 +02:00
}
@Test
public void getServiceNameWithId ( ) throws Exception {
2018-02-10 03:46:05 +01:00
assertEquals ( NewPipe . getNameOfService ( YouTube . getServiceId ( ) ) , YouTube . getServiceInfo ( ) . getName ( ) ) ;
2017-08-06 22:20:15 +02:00
}
}