-
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 9306aa6
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
app/src/androidTest/java/es/unex/giss/asee/ghiblitrunk/CharacterViewModelTest.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,55 @@ | ||
package es.unex.giss.asee.ghiblitrunk | ||
|
||
import android.content.Context | ||
import androidx.test.core.app.ApplicationProvider | ||
import es.unex.giss.asee.ghiblitrunk.data.Repository | ||
import es.unex.giss.asee.ghiblitrunk.data.models.Character | ||
import es.unex.giss.asee.ghiblitrunk.view.home.CharacterViewModel | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class CharacterViewModelTest { | ||
|
||
private lateinit var context: Context | ||
private lateinit var repository: Repository | ||
private lateinit var characterViewModel: CharacterViewModel | ||
private lateinit var character: Character | ||
|
||
@Before | ||
fun setup() { | ||
context = ApplicationProvider.getApplicationContext() | ||
repository = TestRepository(context) | ||
characterViewModel = CharacterViewModel(repository) | ||
|
||
character = Character().apply { | ||
name = "Name" | ||
gender = "Gender" | ||
age = "Age" | ||
eye_color = "Eye color" | ||
hair_color = "Hair color" | ||
} | ||
|
||
} | ||
|
||
@Test | ||
fun testOnToastShown() = runBlocking { | ||
characterViewModel.onToastShown() | ||
|
||
delay(100) | ||
|
||
assertEquals(characterViewModel.toast.value, null) | ||
} | ||
|
||
@Test | ||
fun testSetCharacterDetail() = runBlocking { | ||
characterViewModel.setCharacterDetail(character) | ||
|
||
delay(100) | ||
|
||
assertEquals(characterViewModel.characterDetail.value, character) | ||
} | ||
|
||
} |