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
@DisplayName("test on click listener for movie item") | |
@Test | |
fun testOnclickListener() { | |
MovieStateFlow.onClickStateFlow.value = "Spider man" | |
moviePresenter.observeOnClickStateFlow() | |
verify(view).openSingleItemView("Spider man") | |
} |
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
@DisplayName("when movie list api failed then show error view") | |
@Test | |
fun testApiFailed() { | |
moviePresenter.callMoviesApi() | |
verify(view).showLoadingView() | |
verify(view).showErrorView() | |
verify(view).hideLoadingView() | |
} |
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
import com.app.coroutinesmvp.model.MovieModel | |
import com.app.coroutinesmvp.presenter.MoviePresenter | |
import com.nhaarman.mockitokotlin2.mock | |
import com.nhaarman.mockitokotlin2.verify | |
import com.nhaarman.mockitokotlin2.whenever | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.MainScope | |
import kotlinx.coroutines.flow.flow | |
import kotlinx.coroutines.plus |
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
internal fun callMoviesApi() { | |
movieModel.callMoviesApi() | |
.onStart { | |
movieView.showLoadingView() | |
} | |
.catch { | |
movieView.showErrorView() | |
} | |
.onEach { | |
movieView.showMoviesList(it) |
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
import com.app.coroutinesmvp.data.MovieListResponse | |
import retrofit2.http.GET | |
import retrofit2.http.Query | |
interface MovieApi { | |
@GET("/3/discover/movie") | |
suspend fun getMoviesList(@Query("api_key") apiKey: String): MovieListResponse | |
} |
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
import com.app.coroutinesmvp.api.MovieApi | |
import com.app.coroutinesmvp.model.MovieModel | |
import com.nhaarman.mockitokotlin2.mock | |
import com.nhaarman.mockitokotlin2.whenever | |
import kotlin.test.assertEquals | |
import kotlin.test.assertNull | |
import kotlinx.coroutines.flow.catch | |
import kotlinx.coroutines.flow.collect | |
import kotlinx.coroutines.runBlocking |
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
@MovieActivityScope | |
class MovieModel @Inject constructor( | |
private val movieApi: MovieApi | |
) { | |
fun callMoviesApi(): Flow<MovieListResponse> { | |
return flow { | |
val carbonOffsetResponse = movieApi.getMoviesList("a427cfb730b4a73e67c646d8b44dd216") | |
emit(carbonOffsetResponse) | |
}.flowOn(Dispatchers.IO) | |
} |
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
@MovieActivityScope | |
class MoviePresenter @Inject constructor( | |
private val movieView: MovieContract.MovieView, | |
private val scope: CoroutineScope, | |
private val movieModel: MovieModel | |
) { | |
fun onAttach() { | |
callMoviesApi() | |
observeOnClickStateFlow() |
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
@Subcomponent(modules = [MovieActivityModule::class]) | |
@MovieActivityScope | |
interface MovieComponent { | |
fun inject(movieActivity: MovieActivity) | |
@Subcomponent.Builder | |
interface Builder { | |
@BindsInstance | |
fun activity(appCompatActivity: AppCompatActivity): Builder |
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
@Subcomponent(modules = [MovieActivityModule::class]) | |
@MovieActivityScope | |
interface MovieComponent { | |
fun inject(movieActivity: MovieActivity) | |
@Subcomponent.Builder | |
interface Builder { | |
@BindsInstance | |
fun activity(appCompatActivity: AppCompatActivity): Builder |
NewerOlder