Skip to content

Commit

Permalink
Autoconvert the rest to Kotlin as well
Browse files Browse the repository at this point in the history
  • Loading branch information
wb9688 committed Mar 30, 2024
1 parent 6b4f856 commit a2bb804
Show file tree
Hide file tree
Showing 28 changed files with 1,494 additions and 1,656 deletions.

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()
}
}

This file was deleted.

Loading

0 comments on commit a2bb804

Please sign in to comment.