Get rid of the livedata.testing library.
- The com.jraska.livedata:testing-ktx dependency was introduced to be able to test LiveData, however that dependency has not been migrated away from JCenter (to mavenCentral). Also, we are able to provide a similar functionality with an extension function, and that is what I did.
This commit is contained in:
parent
7492bc9774
commit
c8a2929c54
6 changed files with 28 additions and 35 deletions
|
@ -131,7 +131,6 @@ dependencies {
|
||||||
androidTestImplementation "androidx.room:room-testing:$room_version"
|
androidTestImplementation "androidx.room:room-testing:$room_version"
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||||
androidTestImplementation 'com.jraska.livedata:testing-ktx:1.0.0'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Added to avoid the compilation problem due to a duplicate ListenableFuture library
|
// Added to avoid the compilation problem due to a duplicate ListenableFuture library
|
||||||
|
|
|
@ -23,20 +23,18 @@ import java.util.concurrent.CountDownLatch
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
object LiveDataTestUtil {
|
object LiveDataTestUtil {
|
||||||
fun <T> getValue(liveData: LiveData<T>): T {
|
fun <T> LiveData<T>.blockingObserve(): T? {
|
||||||
val data = arrayOfNulls<Any>(1)
|
var value: T? = null
|
||||||
val latch = CountDownLatch(1)
|
val latch = CountDownLatch(1)
|
||||||
val observer = object : Observer<T> {
|
|
||||||
override fun onChanged(o: T?) {
|
|
||||||
data[0] = o
|
|
||||||
latch.countDown()
|
|
||||||
liveData.removeObserver(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
liveData.observeForever(observer)
|
|
||||||
latch.await(2, TimeUnit.SECONDS)
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
val observer = Observer<T> { t ->
|
||||||
return data[0] as T
|
value = t
|
||||||
|
latch.countDown()
|
||||||
|
}
|
||||||
|
|
||||||
|
observeForever(observer)
|
||||||
|
|
||||||
|
latch.await(2, TimeUnit.SECONDS)
|
||||||
|
return value
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,14 +6,11 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import androidx.test.core.app.ApplicationProvider
|
import androidx.test.core.app.ApplicationProvider
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import com.jraska.livedata.test
|
import cy.agorise.bitsybitshareswallet.LiveDataTestUtil.blockingObserve
|
||||||
import cy.agorise.bitsybitshareswallet.database.BitsyDatabase
|
import cy.agorise.bitsybitshareswallet.database.BitsyDatabase
|
||||||
import cy.agorise.bitsybitshareswallet.database.entities.EquivalentValue
|
import cy.agorise.bitsybitshareswallet.database.entities.EquivalentValue
|
||||||
import cy.agorise.bitsybitshareswallet.database.entities.Transfer
|
import cy.agorise.bitsybitshareswallet.database.entities.Transfer
|
||||||
import org.junit.After
|
import org.junit.*
|
||||||
import org.junit.Before
|
|
||||||
import org.junit.Rule
|
|
||||||
import org.junit.Test
|
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
|
@ -111,13 +108,12 @@ class TransfersTests {
|
||||||
"1.2.1029856",
|
"1.2.1029856",
|
||||||
98,
|
98,
|
||||||
"1.3.120",
|
"1.3.120",
|
||||||
"",
|
"")
|
||||||
1000)
|
|
||||||
db.transferDao().insert(t1)
|
db.transferDao().insert(t1)
|
||||||
db.transferDao().insert(t2)
|
db.transferDao().insert(t2)
|
||||||
db.transferDao().getTransfersWithMissingBtsValue()
|
|
||||||
.test()
|
// transfer should be t2
|
||||||
.assertHasValue()
|
val transfer = db.transferDao().getTransfersWithMissingBtsValue().blockingObserve()
|
||||||
.assertValue { transfer -> transfer.id == "1.11.702181910" }
|
Assert.assertEquals("1.11.684483739", transfer?.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,16 +19,18 @@ data class Transfer (
|
||||||
@ColumnInfo(name = "memo") val memo: String,
|
@ColumnInfo(name = "memo") val memo: String,
|
||||||
@ColumnInfo(name = "bts_value") var btsValue: Long? = NOT_CALCULATED
|
@ColumnInfo(name = "bts_value") var btsValue: Long? = NOT_CALCULATED
|
||||||
){
|
){
|
||||||
companion object {
|
|
||||||
// Constant used to specify an uninitialized BTS equivalent value
|
|
||||||
val NOT_CALCULATED: Long? = -1L
|
|
||||||
// Constant used to specify a BTS equivalent value whose calculation returned an error
|
|
||||||
val ERROR: Long? = -2L
|
|
||||||
}
|
|
||||||
init {
|
init {
|
||||||
if(transferAssetId == "1.3.0"){
|
if(transferAssetId == "1.3.0"){
|
||||||
// If the transferred asset is BTS, we can fill the btsValue field immediately
|
// If the transferred asset is BTS, we can fill the btsValue field immediately
|
||||||
btsValue = transferAmount
|
btsValue = transferAmount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
// Constant used to specify an uninitialized BTS equivalent value
|
||||||
|
const val NOT_CALCULATED: Long = -1L
|
||||||
|
// Constant used to specify a BTS equivalent value whose calculation returned an error
|
||||||
|
const val ERROR: Long = -2L
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -43,7 +43,7 @@ class TransferViewModel(application: Application) : AndroidViewModel(application
|
||||||
mTransferRepository.update(transfer)
|
mTransferRepository.update(transfer)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateBtsValue(transfer: Transfer, value: Long?) {
|
fun updateBtsValue(transfer: Transfer, value: Long) {
|
||||||
transfer.btsValue = value
|
transfer.btsValue = value
|
||||||
mTransferRepository.update(transfer)
|
mTransferRepository.update(transfer)
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,6 @@ allprojects {
|
||||||
includeModule("me.dm7.barcodescanner", "zxing")
|
includeModule("me.dm7.barcodescanner", "zxing")
|
||||||
includeModule("me.dm7.barcodescanner", "core")
|
includeModule("me.dm7.barcodescanner", "core")
|
||||||
includeModule("com.andrognito.patternlockview", "patternlockview")
|
includeModule("com.andrognito.patternlockview", "patternlockview")
|
||||||
includeModule("com.jraska.livedata", "testing-ktx")
|
|
||||||
includeModule("com.jraska.livedata", "testing")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue