Fix inventory tests

pull/1306/head
Alex Baker 5 years ago
parent 979d312a32
commit af62239911

@ -60,7 +60,15 @@ class InventoryTest : InjectingTestCase() {
private fun withPurchases(vararg purchases: String) {
preferences.setPurchases(purchases.toHashSet())
inventory = Inventory(context, preferences, signatureVerifier, localBroadcastManager, caldavDao)
runOnMainSync {
inventory = Inventory(
context,
preferences,
signatureVerifier,
localBroadcastManager,
caldavDao
)
}
}
companion object {

@ -2,6 +2,7 @@ package org.tasks.injection
import android.content.Context
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import androidx.test.platform.app.InstrumentationRegistry
import dagger.hilt.android.testing.HiltAndroidRule
import org.junit.Before
import org.junit.Rule
@ -15,6 +16,9 @@ abstract class InjectingTestCase {
hiltRule.inject()
}
protected fun runOnMainSync(runnable: Runnable) =
InstrumentationRegistry.getInstrumentation().runOnMainSync(runnable)
protected val context: Context
get() = getApplicationContext()
}

@ -3,6 +3,7 @@ package org.tasks.billing
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Handler
import androidx.lifecycle.MutableLiveData
import dagger.hilt.android.qualifiers.ApplicationContext
import org.tasks.BuildConfig
@ -109,6 +110,12 @@ class Inventory @Inject constructor(
}
init {
verifyAndAdd(preferences.purchases)
val runnable = { verifyAndAdd(preferences.purchases) }
val mainLooper = context.mainLooper
if (mainLooper.isCurrentThread) {
runnable()
} else {
Handler(context.mainLooper).post(runnable)
}
}
}

Loading…
Cancel
Save