-
Notifications
You must be signed in to change notification settings - Fork 0
#68. First test added. Many things have to be reviewed after accept t… #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
soygabimoreno
wants to merge
1
commit into
develop
Choose a base branch
from
feature/68_movie_view_model_test
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
18 changes: 18 additions & 0 deletions
18
presentation/src/main/java/com/architectcoders/presentation/event/Event.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.architectcoders.presentation.event | ||
|
|
||
| open class Event<out T>(private val content: T) { | ||
|
|
||
| var hasBeenHandled = false | ||
| private set | ||
|
|
||
| fun getContentIfNotHandled(): T? { | ||
| return if (hasBeenHandled) { | ||
| null | ||
| } else { | ||
| hasBeenHandled = true | ||
| content | ||
| } | ||
| } | ||
|
|
||
| fun peekContent(): T = content | ||
| } |
11 changes: 11 additions & 0 deletions
11
presentation/src/main/java/com/architectcoders/presentation/event/EventObserver.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.architectcoders.presentation.event | ||
|
|
||
| import androidx.lifecycle.Observer | ||
|
|
||
| class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> { | ||
| override fun onChanged(event: Event<T>?) { | ||
| event?.getContentIfNotHandled()?.let { value -> | ||
| onEventUnhandledContent(value) | ||
| } | ||
| } | ||
| } |
17 changes: 0 additions & 17 deletions
17
presentation/src/test/java/com/architectcoders/presentation/ExampleUnitTest.kt
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
presentation/src/test/java/com/architectcoders/presentation/viewmodels/MovieViewModelTest.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package com.architectcoders.presentation.viewmodels | ||
|
|
||
| import androidx.arch.core.executor.testing.InstantTaskExecutorRule | ||
| import androidx.lifecycle.Observer | ||
| import com.gabriel.usecases.GetFavoriteMoviesUseCase | ||
| import com.gabriel.usecases.GetPopularMoviesUseCase | ||
| import com.gabriel.usecases.GetSearchMoviesUseCase | ||
| import com.gabriel.usecases.GetTopRatedMoviesUseCase | ||
| import kotlinx.coroutines.Dispatchers | ||
| import org.junit.Before | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.mockito.Mock | ||
| import org.mockito.Mockito.verify | ||
| import org.mockito.junit.MockitoJUnitRunner | ||
|
|
||
| @RunWith(MockitoJUnitRunner::class) | ||
| class MovieViewModelTest { | ||
|
|
||
| @get:Rule | ||
| val rule = InstantTaskExecutorRule() | ||
|
|
||
| @Mock | ||
| lateinit var getPopularMoviesUseCase: GetPopularMoviesUseCase | ||
|
|
||
| @Mock | ||
| lateinit var getTopRatedMoviesUseCase: GetTopRatedMoviesUseCase | ||
|
|
||
| @Mock | ||
| lateinit var getSearchMoviesUseCase: GetSearchMoviesUseCase | ||
|
|
||
| @Mock | ||
| lateinit var getFavoriteMoviesUseCase: GetFavoriteMoviesUseCase | ||
|
|
||
| @Mock | ||
| lateinit var observer: Observer<MovieViewModel.UiModel> | ||
|
|
||
| private lateinit var vm: MovieViewModel | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| vm = MovieViewModel( | ||
| getPopularMoviesUseCase, | ||
| getTopRatedMoviesUseCase, | ||
| getSearchMoviesUseCase, | ||
| getFavoriteMoviesUseCase, | ||
| Dispatchers.Unconfined | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `Observing LiveData launches request movies`() { | ||
| vm.model.observeForever(observer) | ||
|
|
||
| verify(observer).onChanged(MovieViewModel.UiModel.RequestMovies) | ||
| } | ||
|
|
||
| // @Test | ||
| // fun `After requesting the permission, loading is shown`() { | ||
| // runBlocking { | ||
| // val movies = listOf(mockedMovie.copy(id = 1)) | ||
| // whenever(getPopularMoviesUseCase.useCaseExecution(null)).thenReturn( | ||
| // DataState.Success( | ||
| // movies | ||
| // ) | ||
| // ) | ||
| // | ||
| // vm.onRequestPopularMovies() | ||
| // | ||
| // verify(observer).onChanged(MovieViewModel.UiModel.Content(movies)) | ||
| // } | ||
| // } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| include ':app', ':presentation', ':domain', ':data', ':generic', ':usecases' | ||
| rootProject.name='equipocinco' | ||
| include ':testShared' |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| apply plugin: 'java-library' | ||
| apply plugin: 'kotlin' | ||
|
|
||
| dependencies { | ||
| implementation project(":domain") | ||
|
|
||
| implementation jetBrainsDependencies.values() | ||
| implementation coroutinesDependencies.values() | ||
| } |
17 changes: 17 additions & 0 deletions
17
testShared/src/main/java/com/architectcoders/testshared/Mocks.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.architectcoders.testshared | ||
|
|
||
| import com.architectcoders.domain.model.Movie | ||
|
|
||
| val mockedMovie = Movie( | ||
| 0, | ||
| "Title", | ||
| "Overview", | ||
| "01/01/2025", | ||
| "", | ||
| "", | ||
| "EN", | ||
| "Title", | ||
| 5.0, | ||
| 5.1, | ||
| false | ||
| ) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imagino que estos comentarios están ahí para acabarlo en otro momento. Te comento una cosa molona que tiene github, por si no lo conocías: a la hora de crear una PR puedes marcarla como WIP, de forma que hasta que no confirmes que el trabajo ya está acabado no se pueda mergear ni se solicita review a los reviewers.
Weeeeeeeeeeeee!!! Primer test funcionandoooooooo!! =D=D
Grande Gabi! =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mola lo de WIP! No lo conocía. Lo de mergear está guay, pero sí que me hace falta review... jajaja