diff --git a/app/build.gradle b/app/build.gradle index 9d310f5..d197867 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -131,7 +131,6 @@ dependencies { androidTestImplementation "androidx.room:room-testing:$room_version" androidTestImplementation 'androidx.test.ext:junit:1.1.2' 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 diff --git a/app/src/androidTest/java/cy/agorise/bitsybitshareswallet/LiveDataTestUtil.kt b/app/src/androidTest/java/cy/agorise/bitsybitshareswallet/LiveDataTestUtil.kt index d906a53..5565c2f 100644 --- a/app/src/androidTest/java/cy/agorise/bitsybitshareswallet/LiveDataTestUtil.kt +++ b/app/src/androidTest/java/cy/agorise/bitsybitshareswallet/LiveDataTestUtil.kt @@ -23,20 +23,18 @@ import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit object LiveDataTestUtil { - fun getValue(liveData: LiveData): T { - val data = arrayOfNulls(1) + fun LiveData.blockingObserve(): T? { + var value: T? = null val latch = CountDownLatch(1) - val observer = object : Observer { - override fun onChanged(o: T?) { - data[0] = o - latch.countDown() - liveData.removeObserver(this) - } - } - liveData.observeForever(observer) - latch.await(2, TimeUnit.SECONDS) - @Suppress("UNCHECKED_CAST") - return data[0] as T + val observer = Observer { t -> + value = t + latch.countDown() + } + + observeForever(observer) + + latch.await(2, TimeUnit.SECONDS) + return value } } \ No newline at end of file diff --git a/app/src/androidTest/java/cy/agorise/bitsybitshareswallet/TransfersTests.kt b/app/src/androidTest/java/cy/agorise/bitsybitshareswallet/TransfersTests.kt index d4f8960..7e1eb05 100644 --- a/app/src/androidTest/java/cy/agorise/bitsybitshareswallet/TransfersTests.kt +++ b/app/src/androidTest/java/cy/agorise/bitsybitshareswallet/TransfersTests.kt @@ -6,14 +6,11 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule import androidx.room.Room import androidx.test.core.app.ApplicationProvider 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.entities.EquivalentValue import cy.agorise.bitsybitshareswallet.database.entities.Transfer -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test +import org.junit.* import org.junit.runner.RunWith import java.io.IOException @@ -111,13 +108,12 @@ class TransfersTests { "1.2.1029856", 98, "1.3.120", - "", - 1000) + "") db.transferDao().insert(t1) db.transferDao().insert(t2) - db.transferDao().getTransfersWithMissingBtsValue() - .test() - .assertHasValue() - .assertValue { transfer -> transfer.id == "1.11.702181910" } + + // transfer should be t2 + val transfer = db.transferDao().getTransfersWithMissingBtsValue().blockingObserve() + Assert.assertEquals("1.11.684483739", transfer?.id) } -} \ No newline at end of file +} diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/database/entities/Transfer.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/database/entities/Transfer.kt index bc13707..e73a537 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/database/entities/Transfer.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/database/entities/Transfer.kt @@ -19,16 +19,18 @@ data class Transfer ( @ColumnInfo(name = "memo") val memo: String, @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 { if(transferAssetId == "1.3.0"){ // If the transferred asset is BTS, we can fill the btsValue field immediately 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 + } } \ No newline at end of file diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/viewmodels/TransferViewModel.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/viewmodels/TransferViewModel.kt index 3d5ce22..a237d30 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/viewmodels/TransferViewModel.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/viewmodels/TransferViewModel.kt @@ -43,7 +43,7 @@ class TransferViewModel(application: Application) : AndroidViewModel(application mTransferRepository.update(transfer) } - fun updateBtsValue(transfer: Transfer, value: Long?) { + fun updateBtsValue(transfer: Transfer, value: Long) { transfer.btsValue = value mTransferRepository.update(transfer) } diff --git a/build.gradle b/build.gradle index b5ae386..f4fb38b 100644 --- a/build.gradle +++ b/build.gradle @@ -38,8 +38,6 @@ allprojects { includeModule("me.dm7.barcodescanner", "zxing") includeModule("me.dm7.barcodescanner", "core") includeModule("com.andrognito.patternlockview", "patternlockview") - includeModule("com.jraska.livedata", "testing-ktx") - includeModule("com.jraska.livedata", "testing") } } }