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