Created
September 24, 2019 17:37
-
-
Save DHosseiny/ae68fb0cbbe45cc3f8ef85c8fdfa3ccc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PreferenceRepositoryTest { | |
@get:Rule | |
var instantExecutorRule = InstantTaskExecutorRule() | |
@Mock | |
private lateinit var connectionApiServices: ConnectionApiServices | |
private lateinit var preferenceRepository: PrefrenceRepository | |
@Before | |
fun setUp() { | |
MockitoAnnotations.initMocks(this) | |
preferenceRepository = PrefrenceRepository(connectionApiServices) | |
} | |
@Test | |
fun `checkConnection on start set liveData to LOADING`() { | |
whenever(connectionApiServices.checkConnection()).thenReturn(mock()) | |
val liveData = preferenceRepository.checkConnection() | |
assertEquals(liveData.value, Status.LOADING) | |
} | |
@Test | |
fun `checkConnection successful response set liveData to SUCCESS`() { | |
whenever(connectionApiServices.checkConnection()).thenReturn(Calls.response("TestResponse")) | |
val liveData = preferenceRepository.checkConnection() | |
assertEquals(liveData.value, Status.SUCCESS) | |
} | |
@Test | |
fun `checkConnection failure set liveData to ERROR`() { | |
whenever(connectionApiServices.checkConnection()).thenReturn(Calls.failure(IOException())) | |
val liveData = preferenceRepository.checkConnection() | |
assertEquals(liveData.value, Status.ERROR) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Retrofit mock + nhrmann/mockito kotlin(just a wrapper around mockito for kotlin)