-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move unit tests to modules; introduce test fixtures; add two tests on…
… the data source layer
- Loading branch information
1 parent
d5e95a8
commit 2695cc4
Showing
30 changed files
with
153 additions
and
64 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
5 changes: 2 additions & 3 deletions
5
...ertalan/flickslate/mappers/MappersTest.kt → ...ata/network/model/MovieResponseDtoTest.kt
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
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
4 changes: 1 addition & 3 deletions
4
...n/flickslate/testhelper/MovieDtoMother.kt → ...vies/data/network/model/MovieDtoMother.kt
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
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
3 changes: 1 addition & 2 deletions
3
...alan/flickslate/testhelper/MovieMother.kt → ...kslate/movies/domain/model/MovieMother.kt
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
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
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
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
22 changes: 22 additions & 0 deletions
22
.../test/java/com/zsoltbertalan/flickslate/search/data/network/FailNetworkRequestResponse.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.zsoltbertalan.flickslate.search.data.network | ||
|
||
import com.zsoltbertalan.flickslate.search.data.network.model.GenreReplyDto | ||
import com.zsoltbertalan.flickslate.shared.data.network.model.ErrorBody | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.ResponseBody.Companion.toResponseBody | ||
import retrofit2.Response | ||
|
||
/** | ||
* TODO | ||
* This can be used to test [com.zsoltbertalan.flickslate.search.data.network.GenreRemoteDataSource] | ||
*/ | ||
@Suppress("unused") | ||
fun failNetworkRequestResponse(): () -> Response<GenreReplyDto> = { | ||
val errorBody = ErrorBody( | ||
success = false, | ||
status_code = 6, | ||
status_message = "Invalid id: The pre-requisite id is invalid or not found." | ||
) | ||
Response.error(404, Json.encodeToString(errorBody).toResponseBody()) | ||
} |
7 changes: 5 additions & 2 deletions
7
...n/flickslate/testhelper/GenreDtoMother.kt → ...ate/search/data/network/GenreDtoMother.kt
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
46 changes: 46 additions & 0 deletions
46
...c/test/java/com/zsoltbertalan/flickslate/search/data/network/GenreRemoteDataSourceTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.zsoltbertalan.flickslate.search.data.network | ||
|
||
import com.github.michaelbull.result.Err | ||
import com.github.michaelbull.result.Ok | ||
import com.zsoltbertalan.flickslate.shared.model.Failure | ||
import com.zsoltbertalan.flickslate.shared.model.GenreMother | ||
import com.zsoltbertalan.flickslate.shared.model.GenresReply | ||
import io.kotest.matchers.equals.shouldBeEqual | ||
import io.mockk.coEvery | ||
import io.mockk.mockk | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Before | ||
import org.junit.Test | ||
import retrofit2.Response | ||
|
||
class GenreRemoteDataSourceTest { | ||
|
||
private val searchService: SearchService = mockk() | ||
private lateinit var genreRemoteDataSource: GenreRemoteDataSource | ||
|
||
@Before | ||
fun setup() { | ||
coEvery { searchService.getGenres(any(), any()) } returns Response.success(GenreDtoMother.createGenreReplyDto()) | ||
genreRemoteDataSource = GenreRemoteDataSource(searchService) | ||
} | ||
|
||
@Test | ||
fun `when getGenres called and service returns result then returns correct result`() = runTest { | ||
genreRemoteDataSource.getGenres("") shouldBeEqual Ok(GenresReply(GenreMother.createGenreList(), "")) | ||
} | ||
|
||
@Test | ||
fun `when getGenres called and service returns failure then returns correct result`() = runTest { | ||
coEvery { searchService.getGenres(any(), any()) } returns failNetworkRequestResponse()() | ||
genreRemoteDataSource.getGenres("") shouldBeEqual | ||
Err( | ||
Failure.ServerError( | ||
""" | ||
{"success":false, | ||
"status_code":6,"status_message":"Invalid id: The pre-requisite id is invalid | ||
or not found."}""".trimIndent().filterNot { it == '\n' } | ||
) | ||
) | ||
} | ||
|
||
} |
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
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
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
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
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
Oops, something went wrong.