mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-07-20 18:08:53 +00:00
subscription: Cover testing for import input fallback
Import requests queued by older code can omit the explicit mode field. That path must still be decoded as the previous export format while the new channel URL and input stream modes keep their WorkManager payloads stable. The pure data tests cover those round trips and the invalid mode cases without requiring the worker to be started.
This commit is contained in:
committed by
Aayush Gupta
parent
b1cdb29844
commit
e47f505074
+62
@@ -0,0 +1,62 @@
|
||||
package org.schabi.newpipe.local.subscription.workers
|
||||
|
||||
import androidx.work.Data
|
||||
import androidx.work.workDataOf
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.schabi.newpipe.local.subscription.workers.SubscriptionImportInput.ChannelUrlMode
|
||||
import org.schabi.newpipe.local.subscription.workers.SubscriptionImportInput.InputStreamMode
|
||||
import org.schabi.newpipe.local.subscription.workers.SubscriptionImportInput.PreviousExportMode
|
||||
|
||||
class SubscriptionImportInputTest {
|
||||
|
||||
@Test
|
||||
fun `Channel URL mode round-trips through Work Data`() {
|
||||
val input = ChannelUrlMode(serviceId = 0, url = "https://www.youtube.com")
|
||||
assertEquals(input, SubscriptionImportInput.fromData(input.toData()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Input stream mode round-trips through Work Data`() {
|
||||
val input = InputStreamMode(
|
||||
serviceId = 0,
|
||||
url = "content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Fsubscriptions.csv"
|
||||
)
|
||||
assertEquals(input, SubscriptionImportInput.fromData(input.toData()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Previous export mode round-trips through Work Data`() {
|
||||
val input = PreviousExportMode(url = "content://media/external/file/newpipe_subscriptions.json")
|
||||
assertEquals(input, SubscriptionImportInput.fromData(input.toData()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Missing mode falls back to previous export mode`() {
|
||||
val data = Data.Builder()
|
||||
.putString("url", "content://media/external/file/newpipe_subscriptions.json")
|
||||
.build()
|
||||
|
||||
assertEquals(
|
||||
PreviousExportMode("content://media/external/file/newpipe_subscriptions.json"),
|
||||
SubscriptionImportInput.fromData(data)
|
||||
)
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun `Unknown mode throws`() {
|
||||
SubscriptionImportInput.fromData(workDataOf("mode" to 99, "url" to "https://www.youtube.com"))
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun `Channel URL mode without service id throws`() {
|
||||
SubscriptionImportInput.fromData(workDataOf("mode" to 0, "url" to "https://www.youtube.com"))
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun `Input stream mode without service id throws`() {
|
||||
SubscriptionImportInput.fromData(
|
||||
workDataOf("mode" to 1, "url" to "content://media/external/file/subscriptions.csv")
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user