Search in sources :

Example 6 with SubscriptionItem

use of org.schabi.newpipe.extractor.subscription.SubscriptionItem in project NewPipe by TeamNewPipe.

the class ImportExportJsonHelperTest method testEmptySource.

@Test
public void testEmptySource() throws Exception {
    String emptySource = "{\"app_version\":\"0.11.6\",\"app_version_int\": 47,\"subscriptions\":[]}";
    List<SubscriptionItem> items = ImportExportJsonHelper.readFrom(new ByteArrayInputStream(emptySource.getBytes("UTF-8")), null);
    assertTrue(items.isEmpty());
}
Also used : SubscriptionItem(org.schabi.newpipe.extractor.subscription.SubscriptionItem) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 7 with SubscriptionItem

use of org.schabi.newpipe.extractor.subscription.SubscriptionItem in project NewPipe by TeamNewPipe.

the class ImportExportJsonHelperTest method ultimateTest.

@Test
public void ultimateTest() throws Exception {
    // Read from file
    final List<SubscriptionItem> itemsFromFile = readFromFile();
    // Test writing to an output
    final String jsonOut = testWriteTo(itemsFromFile);
    // Read again
    final List<SubscriptionItem> itemsSecondRead = readFromWriteTo(jsonOut);
    // Check if both lists have the exact same items
    if (itemsFromFile.size() != itemsSecondRead.size()) {
        fail("The list of items were different from each other");
    }
    for (int i = 0; i < itemsFromFile.size(); i++) {
        final SubscriptionItem item1 = itemsFromFile.get(i);
        final SubscriptionItem item2 = itemsSecondRead.get(i);
        final boolean equals = item1.getServiceId() == item2.getServiceId() && item1.getUrl().equals(item2.getUrl()) && item1.getName().equals(item2.getName());
        if (!equals) {
            fail("The list of items were different from each other");
        }
    }
}
Also used : SubscriptionItem(org.schabi.newpipe.extractor.subscription.SubscriptionItem) Test(org.junit.Test)

Aggregations

SubscriptionItem (org.schabi.newpipe.extractor.subscription.SubscriptionItem)7 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 JsonArray (com.grack.nanojson.JsonArray)1 JsonObject (com.grack.nanojson.JsonObject)1 InputStream (java.io.InputStream)1 SubscriptionEntity (org.schabi.newpipe.database.subscription.SubscriptionEntity)1 InvalidSourceException (org.schabi.newpipe.extractor.subscription.SubscriptionExtractor.InvalidSourceException)1