This file contains hidden or 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
| data class Movie( | |
| val movieId: Int, | |
| val overview: String, | |
| val imageId: Int, | |
| val title: String, | |
| val rating: String, | |
| val releaseDate: String, | |
| ):Serializable |
This file contains hidden or 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
| @Composable | |
| fun MovieListContent(allMovies: List<Movie>, navController: NavHostController) { | |
| LazyColumn( | |
| contentPadding = PaddingValues(horizontal = 8.dp, vertical = 4.dp) | |
| ) { | |
| items( | |
| items = allMovies, | |
| itemContent = { | |
| MovieListItem(movie = it, navController = navController) |
This file contains hidden or 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
| @Test | |
| fun getSearchedResult_receivedResponse_wrongPageSize_shouldFail() { | |
| runBlocking { | |
| enqueueMockResponse("ImageResponse.json") | |
| val responseBody = service.getSearchedImage("nature", 5).body() | |
| val photoList = responseBody!!.photos | |
| assertThat(photoList.size).isEqualTo(6) | |
| } | |
| } |
This file contains hidden or 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
| //Mock Server | |
| testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.0' | |
| //Truth | |
| testImplementation "com.google.truth:truth:1.1" | |
| //okhttp | |
| implementation 'com.squareup.okhttp3:okhttp:4.9.1' | |
| testImplementation 'junit:junit:4.13.2' |
This file contains hidden or 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
| @Test | |
| fun getSearchedResult_sentRequest_receivedExpected() { | |
| runBlocking { | |
| // Prepare fake response | |
| enqueueMockResponse("ImageResponse.json") | |
| //Send Request to the MockServer | |
| val responseBody = service.getSearchedImage("nature", 5).body() | |
| //Request received by the mock server | |
| val request = server.takeRequest() | |
| assertThat(responseBody).isNotNull() |
This file contains hidden or 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
| private lateinit var service: ImageApiService | |
| private lateinit var server: MockWebServer | |
| @Before | |
| fun setUp() { | |
| server = MockWebServer() | |
| service = Retrofit.Builder() | |
| .baseUrl(server.url(""))//We will use MockWebServers url | |
| .addConverterFactory(GsonConverterFactory.create()) | |
| .build() |
This file contains hidden or 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
| interface ImageApiService { | |
| @GET("v1/search") | |
| suspend fun getSearchedImage( | |
| @Query("query") | |
| searchQuery:String, | |
| @Query("per_page") | |
| page:Int | |
| ): Response<APIResponse> | |
| } |
This file contains hidden or 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 MovieRemoteDataSourceImpl(private val movieApi: MovieApi, private val movieDB: MovieDB) : | |
| MovieRemoteDataSource { | |
| private val movieDao = movieDB.movieDao() | |
| @OptIn(ExperimentalPagingApi::class) | |
| override fun getPopularMovies(): Flow<PagingData<Movie>> { | |
| val pagingSourceFactory = { movieDao.getAllMovies() } | |
| return Pager( | |
| config = PagingConfig(pageSize = 20), | |
| remoteMediator = MovieRemoteMediator( |
This file contains hidden or 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
| interface MovieLocalDataSource { | |
| fun getMoviesFromDB(movieId : Int): Flow<Movie> | |
| } |