Skip to content

Instantly share code, notes, and snippets.

@lukaszkalnik
Last active February 10, 2020 21:23
Show Gist options
  • Save lukaszkalnik/341b724eb92196135a1b23da82054b6f to your computer and use it in GitHub Desktop.
Save lukaszkalnik/341b724eb92196135a1b23da82054b6f to your computer and use it in GitHub Desktop.
class GetLightsUseCaseTest {
private val testEntity = TestClassesProvider.entity()
private val mockApi = mockk<GatewayApi>()
private val lights = listOf(Light(id = "1234"))
private val mockConverter = mockk<EntityConverter<List<Light>>> converter@{
every { [email protected](testEntity) } returns lights
}
private val useCase = getLightsUseCaseFactory(mockApi, mockConverter)
@Test
fun `calling use case with response success should return list of lights`() {
val roomId = "room 1"
coEvery { mockApi.getLights(roomId) } returns Response.success(testEntity)
val result = runBlocking { useCase(roomId) }
coVerifyAll { mockApi.getLights(roomId) }
verifyAll { mockConverter(testEntity) }
assertThat(result).isInstanceOf(Success::class.java)
result as Success
assertThat(result.success).isEqualTo(lights)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment