paulex
01/27/2020, 12:39 AMoverride fun createWallet(request: CreateWalletRequest?, responseObserver: StreamObserver<Wallet>) {
GlobalScope.launch {
val wallet = async { return@async this@WalletService.repo.get(1) }
responseObserver.onNext(wallet.await())
responseObserver.onCompleted()
}
}
The code within the GlobalScope.launch runs well, i can print it out...
the onNext(value) is called and i can't seem to get the value from my test...
What i've tried but doesn't work...
@ExperimentalCoroutinesApi
@Test
fun `createWallet should pass`() = runBlockingTest {
//Arrange
val responseObserver = mockk<StreamObserver<Wallet>>()
val slot = slot<Wallet>()
every { responseObserver.onNext(capture(slot)) } just Runs
every { responseObserver.onCompleted() } just Runs
val wallet = Wallet.newBuilder().setUserId(2).build()
coEvery { repo.get(1) } returns wallet
val request = CreateWalletRequest.newBuilder()
.setWallet(wallet)
.build()
//Act
this@WalletServiceTest.walletService.createWallet(request, responseObserver)
//Assert
assertThat(slot.captured).isNotNull()
}