fix: fix broken tests
Some checks failed
Android Unit Tests / tests (push) Failing after 5m29s

This commit is contained in:
Leonardo Murça 2025-07-19 22:18:58 -03:00
parent 3ae6acecf4
commit f10e0b60c7

View file

@ -1,5 +1,9 @@
package xyz.leomurca.csgomatches.utils package xyz.leomurca.csgomatches.utils
import android.content.Context
import io.mockk.every
import io.mockk.mockk
import xyz.leomurca.csgomatches.R
import java.time.Clock import java.time.Clock
import java.time.DayOfWeek import java.time.DayOfWeek
import java.time.ZoneId import java.time.ZoneId
@ -10,15 +14,16 @@ import kotlin.test.assertEquals
class ExtensionsTest { class ExtensionsTest {
private fun now(): ZonedDateTime = ZonedDateTime.now(fixedClock) private val context: Context = mockk(relaxed = true)
@Test @Test
fun `toFormattedMatchTime - returns Hoje when date is today`() { fun `toFormattedMatchTime - returns Hoje when date is today`() {
// Arrange // Arrange
val date = now().withHour(18).withMinute(30) val date = now().withHour(18).withMinute(30)
every { context.getString(R.string.match_time_today, any()) } returns "Hoje, 18:30"
// Act // Act
val result = date.toFormattedMatchTime() val result = date.toFormattedMatchTime(context)
// Assert // Assert
assertEquals("Hoje, 18:30", result) assertEquals("Hoje, 18:30", result)
@ -28,12 +33,12 @@ class ExtensionsTest {
fun `toFormattedMatchTime - returns weekday in Portuguese when date is this week`() { fun `toFormattedMatchTime - returns weekday in Portuguese when date is this week`() {
// Arrange // Arrange
val tuesday = now().with(DayOfWeek.TUESDAY).withHour(22).withMinute(0) val tuesday = now().with(DayOfWeek.TUESDAY).withHour(22).withMinute(0)
every { context.getString(R.string.match_time_weekday, any(), any()) } returns "Ter, 22:00"
// Act // Act
val result = tuesday.toFormattedMatchTime() val result = tuesday.toFormattedMatchTime(context)
// Assert // Assert
// "Ter" is the abbreviation for "Terça-feira"
assertEquals("Ter, 22:00", result) assertEquals("Ter, 22:00", result)
} }
@ -43,7 +48,7 @@ class ExtensionsTest {
val future = now().plusWeeks(2).withHour(15).withMinute(0) val future = now().plusWeeks(2).withHour(15).withMinute(0)
// Act // Act
val result = future.toFormattedMatchTime() val result = future.toFormattedMatchTime(context)
// Assert // Assert
val expected = future.format(DateTimeFormatter.ofPattern("dd.MM HH:mm")) val expected = future.format(DateTimeFormatter.ofPattern("dd.MM HH:mm"))
@ -54,14 +59,17 @@ class ExtensionsTest {
fun `toFormattedMatchTime - returns A definir when date is null`() { fun `toFormattedMatchTime - returns A definir when date is null`() {
// Arrange // Arrange
val date: ZonedDateTime? = null val date: ZonedDateTime? = null
every { context.getString(R.string.match_time_tbd) } returns "A definir"
// Act // Act
val result = date.toFormattedMatchTime() val result = date.toFormattedMatchTime(context)
// Assert // Assert
assertEquals("A definir", result) assertEquals("A definir", result)
} }
private fun now(): ZonedDateTime = ZonedDateTime.now(fixedClock)
companion object { companion object {
private val fixedClock = Clock.fixed( private val fixedClock = Clock.fixed(
ZonedDateTime.of(2025, 7, 19, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")).toInstant(), ZonedDateTime.of(2025, 7, 19, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")).toInstant(),