From 9b6c6673cc1276f01c37ff0e4e2173bd747095e4 Mon Sep 17 00:00:00 2001 From: lee_chong Date: Fri, 15 Dec 2023 20:52:43 +0100 Subject: [PATCH] =?UTF-8?q?GB04-33=20Realizaci=C3=B3n=20de=20pruebas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../asee/ghiblitrunk/MovieViewModelTest.kt | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 app/src/androidTest/java/es/unex/giss/asee/ghiblitrunk/MovieViewModelTest.kt diff --git a/app/src/androidTest/java/es/unex/giss/asee/ghiblitrunk/MovieViewModelTest.kt b/app/src/androidTest/java/es/unex/giss/asee/ghiblitrunk/MovieViewModelTest.kt new file mode 100644 index 0000000..3150dae --- /dev/null +++ b/app/src/androidTest/java/es/unex/giss/asee/ghiblitrunk/MovieViewModelTest.kt @@ -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) + } + +}