Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoconvert to Kotlin #10923

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  

This file was deleted.

36 changes: 36 additions & 0 deletions app/src/androidTest/java/org/schabi/newpipe/error/ErrorInfoTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.schabi.newpipe.error

import android.os.Parcel
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.schabi.newpipe.R
import org.schabi.newpipe.extractor.ServiceList
import org.schabi.newpipe.extractor.exceptions.ParsingException

/**
* Instrumented tests for [ErrorInfo].
*/
@RunWith(AndroidJUnit4::class)
@LargeTest
class ErrorInfoTest {
@Test
fun errorInfoTestParcelable() {
val info = ErrorInfo(ParsingException("Hello"),
UserAction.USER_REPORT, "request", ServiceList.YouTube.serviceId)
// Obtain a Parcel object and write the parcelable object to it:
val parcel = Parcel.obtain()
info.writeToParcel(parcel, 0)
parcel.setDataPosition(0)
val infoFromParcel = ErrorInfo.CREATOR.createFromParcel(parcel) as ErrorInfo
Assert.assertTrue(infoFromParcel.stackTraces.contentToString().contains(ErrorInfoTest::class.java.getSimpleName()))
Assert.assertEquals(UserAction.USER_REPORT, infoFromParcel.userAction)
Assert.assertEquals(ServiceList.YouTube.serviceInfo.name,
infoFromParcel.serviceName)
Assert.assertEquals("request", infoFromParcel.request)
Assert.assertEquals(R.string.parsing_error.toLong(), infoFromParcel.messageStringId.toLong())
parcel.recycle()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.schabi.newpipe.local.subscription

import androidx.test.core.app.ApplicationProvider
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.schabi.newpipe.database.AppDatabase
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
import org.schabi.newpipe.database.subscription.SubscriptionEntity
import org.schabi.newpipe.database.subscription.SubscriptionEntity.Companion.from
import org.schabi.newpipe.extractor.channel.ChannelInfo
import org.schabi.newpipe.extractor.exceptions.ExtractionException
import org.schabi.newpipe.testUtil.TestDatabase.Companion.createReplacingNewPipeDatabase
import org.schabi.newpipe.testUtil.TrampolineSchedulerRule
import java.io.IOException

class SubscriptionManagerTest {
private var database: AppDatabase? = null
private var manager: SubscriptionManager? = null

@Rule
var trampolineScheduler = TrampolineSchedulerRule()
private val assertOneSubscriptionEntity: SubscriptionEntity
private get() {
val entities = manager
.getSubscriptions(FeedGroupEntity.GROUP_ALL_ID, "", false)
.blockingFirst()
Assert.assertEquals(1, entities.size.toLong())
return entities[0]
}

@Before
fun setup() {
database = createReplacingNewPipeDatabase()
manager = SubscriptionManager(ApplicationProvider.getApplicationContext())
}

@After
fun cleanUp() {
database!!.close()
}

@Test
@Throws(ExtractionException::class, IOException::class)
fun testInsert() {
val info = ChannelInfo.getInfo("https://www.youtube.com/c/3blue1brown")
val subscription = from(info)
manager!!.insertSubscription(subscription)
val readSubscription = assertOneSubscriptionEntity

// the uid has changed, since the uid is chosen upon inserting, but the rest should match
Assert.assertEquals(subscription.getServiceId().toLong(), readSubscription.getServiceId().toLong())
Assert.assertEquals(subscription.getUrl(), readSubscription.getUrl())
Assert.assertEquals(subscription.getName(), readSubscription.getName())
Assert.assertEquals(subscription.getAvatarUrl(), readSubscription.getAvatarUrl())
Assert.assertEquals(subscription.getSubscriberCount(), readSubscription.getSubscriberCount())
Assert.assertEquals(subscription.getDescription(), readSubscription.getDescription())
}

@Test
@Throws(ExtractionException::class, IOException::class)
fun testUpdateNotificationMode() {
val info = ChannelInfo.getInfo("https://www.youtube.com/c/veritasium")
val subscription = from(info)
subscription.setNotificationMode(0)
manager!!.insertSubscription(subscription)
manager!!.updateNotificationMode(subscription.getServiceId(), subscription.getUrl()!!, 1)
.blockingAwait()
val anotherSubscription = assertOneSubscriptionEntity
Assert.assertEquals(0, subscription.getNotificationMode().toLong())
Assert.assertEquals(subscription.getUrl(), anotherSubscription.getUrl())
Assert.assertEquals(1, anotherSubscription.getNotificationMode().toLong())
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.schabi.newpipe.settings

import android.content.Intent
import leakcanary.LeakCanary.newLeakDisplayActivityIntent
import org.schabi.newpipe.settings.DebugSettingsFragment.DebugSettingsBVDLeakCanaryAPI

/**
* Build variant dependent (BVD) leak canary API implementation for the debug settings fragment.
* This class is loaded via reflection by
* [DebugSettingsFragment.DebugSettingsBVDLeakCanaryAPI].
*/
@Suppress("unused") // Class is used but loaded via reflection

class DebugSettingsBVDLeakCanary : DebugSettingsBVDLeakCanaryAPI {
override fun getNewLeakDisplayActivityIntent(): Intent? {
return newLeakDisplayActivityIntent()
}
}
Loading
Loading