Skip to content

Commit a7bf5fa

Browse files
committed
Add tests for BaseViewModel: failure handling.
1 parent 4361448 commit a7bf5fa

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fernandocejas.sample.framework.platform
2+
3+
import android.arch.lifecycle.MutableLiveData
4+
import com.fernandocejas.sample.AndroidTest
5+
import com.fernandocejas.sample.framework.exception.Failure
6+
import com.fernandocejas.sample.framework.exception.Failure.NetworkConnection
7+
import org.amshove.kluent.shouldBeInstanceOf
8+
import org.junit.Test
9+
10+
class BaseViewModelTest : AndroidTest() {
11+
12+
@Test fun `should handle failure by updating live data`() {
13+
val viewModel = MyViewModel()
14+
15+
viewModel.handleError(NetworkConnection())
16+
17+
val failure = viewModel.failure
18+
val error = viewModel.failure.value
19+
20+
failure shouldBeInstanceOf MutableLiveData::class.java
21+
error shouldBeInstanceOf NetworkConnection::class.java
22+
}
23+
24+
private class MyViewModel : BaseViewModel() {
25+
fun handleError(failure: Failure) = handleFailure(failure)
26+
}
27+
}

0 commit comments

Comments
 (0)