Skip to content

Commit

Permalink
test: ajustes nos testes devido a refatoração de objeto
Browse files Browse the repository at this point in the history
  • Loading branch information
JorgeTranin committed Jun 19, 2024
1 parent 1e52bfe commit 93e5147
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import com.petjournal.database.converter.Converter.toModel
import com.petjournal.database.database.dao.GuardianProfileDao
import com.petjournal.database.database.entity.GuardianProfile
import com.petjournal.setup.CAT
import com.petjournal.setup.DOG
import com.petjournal.setup.petRace
import com.petjournal.setup.petSize
import com.petjournal.setup.listPetRace
import com.petjournal.setup.listPetSizes
import com.petjournal.setup.newPetInformation
import com.petjournal.setup.petInformation
import com.petjournal.setup.profile
import io.mockk.Runs
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.just
import io.mockk.mockk
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
Expand All @@ -31,10 +32,10 @@ class GuardianProfileDaoTest {
coEvery { guardianProfileDao.getPetInformation(1) } returns petInformation.toModel()
coEvery { guardianProfileDao.getPetInformation(2) } returns newPetInformation.toModel()
coEvery { guardianProfileDao.updatePetInformation(newPetInformation) }
coEvery { guardianProfileDao.getListPetSizes(CAT) } returns petSize
coEvery { guardianProfileDao.insertListPetSizes(any()) } returns 1L
coEvery { guardianProfileDao.getListPetRaces(DOG) } returns petRace
coEvery { guardianProfileDao.insertListPetRaces(any()) } returns 1L
coEvery { guardianProfileDao.getListPetSizes(CAT) } returns listPetSizes
coEvery { guardianProfileDao.insertListPetSizes(any()) }
coEvery { guardianProfileDao.getListPetRaces(CAT) } returns listPetRace
coEvery { guardianProfileDao.insertListPetRaces(any()) }
}

@Test
Expand Down Expand Up @@ -85,35 +86,46 @@ class GuardianProfileDaoTest {
fun `get list pet sizes must be the same`() = runBlocking {
val getListPetSizes = guardianProfileDao.getListPetSizes(CAT)
coEvery { guardianProfileDao.getListPetSizes(CAT) }
assertEquals(petSize.listPetSizes, getListPetSizes?.listPetSizes)
assertEquals(listPetSizes, getListPetSizes)
}

@Test
fun `insert and get list Pet Sizes`() = runBlocking {
val insertListPetSizes = guardianProfileDao.insertListPetSizes(petSize)
coEvery { guardianProfileDao.insertListPetSizes(petSize) }
assertEquals(1L, insertListPetSizes)
coEvery { guardianProfileDao.insertListPetSizes(any()) } just Runs

guardianProfileDao.insertListPetSizes(listPetSizes)

coEvery { guardianProfileDao.getListPetSizes(CAT) } returns listPetSizes

val retrievedListPetSizes = guardianProfileDao.getListPetSizes(CAT)

coVerify { guardianProfileDao.insertListPetSizes(listPetSizes) }
coVerify { guardianProfileDao.getListPetSizes(CAT) }
assertEquals(petSize, retrievedListPetSizes)

assertEquals(listPetSizes, retrievedListPetSizes)
}

@Test
fun `get list pet races must be the same`() = runBlocking {
val getListPetRaces = guardianProfileDao.getListPetRaces(DOG)
coEvery { guardianProfileDao.getListPetRaces(DOG) }
assertEquals(petRace.listPetRaces, getListPetRaces?.listPetRaces)
val getListPetRaces = guardianProfileDao.getListPetRaces(CAT)
coEvery { guardianProfileDao.getListPetRaces(CAT) }
assertEquals(listPetRace, getListPetRaces)
}

@Test
fun `insert and get list Pet Races`() = runBlocking {
val insertListPetRaces = guardianProfileDao.insertListPetRaces(petRace)
coEvery { guardianProfileDao.insertListPetRaces(petRace) }
assertEquals(1L, insertListPetRaces)
coEvery { guardianProfileDao.insertListPetRaces(any()) } just Runs

guardianProfileDao.insertListPetRaces(listPetRace)

coEvery { guardianProfileDao.getListPetRaces(CAT) } returns listPetRace

val retrievedListPetRaces = guardianProfileDao.getListPetRaces(CAT)

coVerify { guardianProfileDao.insertListPetRaces(listPetRace) }
coVerify { guardianProfileDao.getListPetRaces(CAT) }

assertEquals(listPetRace, retrievedListPetRaces)

val retrievedListPetRaces = guardianProfileDao.getListPetRaces(DOG)
coVerify { guardianProfileDao.getListPetRaces(DOG) }
assertEquals(petRace.listPetRaces, retrievedListPetRaces?.listPetRaces)
}
}
69 changes: 34 additions & 35 deletions petJournal/database/src/test/java/com/petjournal/setup/FormMock.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.petjournal.setup

import com.petjournal.database.database.entity.GuardianProfile
import com.petjournal.database.database.entity.PetInformation
import com.petjournal.database.database.entity.PetRace
import com.petjournal.database.database.entity.PetSize
import com.petjournal.database.database.entity.PetInformation
import com.soujunior.domain.model.request.PetRaceItemModel
import com.soujunior.domain.model.request.PetSizeItemModel

const val DOG = "Dog"
const val CAT = "Cat"
Expand All @@ -29,68 +27,69 @@ val newPetInformation = PetInformation(
)


val listPetRaceModel = listOf(
PetRaceItemModel(
val listPetRace = listOf(
PetRace(
"99c18d37-d7ba-4e53-88c8-eddbe82f0063",
"Curl Americano de Pelo Longo",
"a0f385f5-c0b4-4f85-8d06-cf2a4f698f93"
"a0f385f5-c0b4-4f85-8d06-cf2a4f698f93",
tag = "Cat"
),
PetRaceItemModel(
PetRace(
"eed1adba-dfb1-4b0d-a4bc-5cd64a13b4a5",
"Siamês",
"a0f385f5-c0b4-4f85-8d06-cf2a4f698f93"
"a0f385f5-c0b4-4f85-8d06-cf2a4f698f93",
tag = "Cat"
),
PetRaceItemModel(
PetRace(
"dc60facc-17a6-4db5-a85b-fcb32bcb0ea0",
"Khao Manee",
"a0f385f5-c0b4-4f85-8d06-cf2a4f698f93"
"a0f385f5-c0b4-4f85-8d06-cf2a4f698f93",
tag = "Cat"
),
PetRaceItemModel(
PetRace(
"93d619b2-0e0c-4a87-8099-8f2edc38363a",
"Doméstico de Pelo Longo",
"a0f385f5-c0b4-4f85-8d06-cf2a4f698f93"
"a0f385f5-c0b4-4f85-8d06-cf2a4f698f93",
tag = "Cat"
),
PetRaceItemModel(
PetRace(
"ac18cda1-ead9-402b-8abf-24b76e271b5b",
"Ashera",
"a0f385f5-c0b4-4f85-8d06-cf2a4f698f93"
"a0f385f5-c0b4-4f85-8d06-cf2a4f698f93",
tag = "Cat"
),
PetRaceItemModel(
PetRace(
"c553a6d5-5956-4176-8a15-4c51d9ddf523",
"Chartreux",
"a0f385f5-c0b4-4f85-8d06-cf2a4f698f93"
"a0f385f5-c0b4-4f85-8d06-cf2a4f698f93",
tag = "Cat"
),
PetRaceItemModel(
PetRace(
"7bdcf272-d1f1-4419-bb9b-4c7afb7f4f5e",
"Mekong Bobtail",
"a0f385f5-c0b4-4f85-8d06-cf2a4f698f93"
),
"a0f385f5-c0b4-4f85-8d06-cf2a4f698f93",
tag = "Cat"
)
)

val listPetSizesModel = listOf(
PetSizeItemModel(
val listPetSizes = listOf(
PetSize(
id = "649a616b-3b02-4d47-95c0-dd7224760f01",
name = "Grande (25 à 45Kg)",
specieId = "a0f385f5-c0b4-4f85-8d06-cf2a4f698f93"
specieId = "a0f385f5-c0b4-4f85-8d06-cf2a4f698f93",
tag = "Cat"
),
PetSizeItemModel(
PetSize(
id = "fa6a7d4c-f93d-44c5-9c14-42dbf4bf16b4",
name = "Médio (11 à 24Kg)",
specieId = "a0f385f5-c0b4-4f85-8d06-cf2a4f698f93"
specieId = "a0f385f5-c0b4-4f85-8d06-cf2a4f698f93",
tag = "Cat"
),
PetSizeItemModel(
PetSize(
id = "35ca78d5-f012-4048-9334-6836a3e82ecc",
name = "Pequeno (Até 10Kg)",
specieId = "a0f385f5-c0b4-4f85-8d06-cf2a4f698f93"
specieId = "a0f385f5-c0b4-4f85-8d06-cf2a4f698f93",
tag = "Cat"
)
)
val petSize = PetSize(
id = "Dog",
listPetSizes = listPetSizesModel
)

val petRace = PetRace(
id = "Dog",
listPetRaces = listPetRaceModel
)

0 comments on commit 93e5147

Please sign in to comment.