-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99eacfc
commit 9b6c667
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
app/src/androidTest/java/es/unex/giss/asee/ghiblitrunk/MovieViewModelTest.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,63 @@ | ||
package es.unex.giss.asee.ghiblitrunk | ||
|
||
import android.content.Context | ||
import es.unex.giss.asee.ghiblitrunk.data.Repository | ||
import es.unex.giss.asee.ghiblitrunk.view.home.MovieViewModel | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import androidx.test.core.app.ApplicationProvider | ||
import es.unex.giss.asee.ghiblitrunk.data.models.Movie | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.runBlocking | ||
|
||
class MovieViewModelTest { | ||
|
||
private lateinit var context: Context | ||
private lateinit var repository: Repository | ||
private lateinit var movieViewModel: MovieViewModel | ||
private lateinit var movie: Movie | ||
|
||
@Before | ||
fun setup() { | ||
context = ApplicationProvider.getApplicationContext() | ||
repository = TestRepository(context) | ||
movieViewModel = MovieViewModel(repository) | ||
|
||
movie = Movie().apply { | ||
title = "Title" | ||
description = "Description" | ||
director = "Director" | ||
isFavourite = false | ||
producer = "Producer" | ||
release_date = "Release Date" | ||
} | ||
} | ||
|
||
@Test | ||
fun testSetSearchFilter() = runBlocking { | ||
val filter = "Search by Title" | ||
|
||
movieViewModel.setSearchFilter(filter) | ||
delay(100) | ||
|
||
assertEquals(filter, "Search by Title") | ||
} | ||
|
||
@Test | ||
fun testOnToastShown() = runBlocking { | ||
movieViewModel.onToastShown() | ||
|
||
assertEquals(movieViewModel.toast.value, null) | ||
} | ||
|
||
@Test | ||
fun testSetMovieDetail() = runBlocking { | ||
movieViewModel.setMovieDetail(movie) | ||
|
||
delay(100) | ||
|
||
assertEquals(movieViewModel.movieDetail.value, movie) | ||
} | ||
|
||
} |