From f10e0b60c789ffc206ccb43ef9b65d6f9a200516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Mur=C3=A7a?= Date: Sat, 19 Jul 2025 22:18:58 -0300 Subject: [PATCH] fix: fix broken tests --- .../csgomatches/utils/ExtensionsTest.kt | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/test/java/xyz/leomurca/csgomatches/utils/ExtensionsTest.kt b/app/src/test/java/xyz/leomurca/csgomatches/utils/ExtensionsTest.kt index 2f6555c..2ae33f7 100644 --- a/app/src/test/java/xyz/leomurca/csgomatches/utils/ExtensionsTest.kt +++ b/app/src/test/java/xyz/leomurca/csgomatches/utils/ExtensionsTest.kt @@ -1,5 +1,9 @@ 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.DayOfWeek import java.time.ZoneId @@ -10,15 +14,16 @@ import kotlin.test.assertEquals class ExtensionsTest { - private fun now(): ZonedDateTime = ZonedDateTime.now(fixedClock) + private val context: Context = mockk(relaxed = true) @Test fun `toFormattedMatchTime - returns Hoje when date is today`() { // Arrange val date = now().withHour(18).withMinute(30) + every { context.getString(R.string.match_time_today, any()) } returns "Hoje, 18:30" // Act - val result = date.toFormattedMatchTime() + val result = date.toFormattedMatchTime(context) // Assert assertEquals("Hoje, 18:30", result) @@ -28,12 +33,12 @@ class ExtensionsTest { fun `toFormattedMatchTime - returns weekday in Portuguese when date is this week`() { // Arrange 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 - val result = tuesday.toFormattedMatchTime() + val result = tuesday.toFormattedMatchTime(context) // Assert - // "Ter" is the abbreviation for "Terça-feira" assertEquals("Ter, 22:00", result) } @@ -43,7 +48,7 @@ class ExtensionsTest { val future = now().plusWeeks(2).withHour(15).withMinute(0) // Act - val result = future.toFormattedMatchTime() + val result = future.toFormattedMatchTime(context) // Assert 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`() { // Arrange val date: ZonedDateTime? = null + every { context.getString(R.string.match_time_tbd) } returns "A definir" // Act - val result = date.toFormattedMatchTime() + val result = date.toFormattedMatchTime(context) // Assert assertEquals("A definir", result) } + private fun now(): ZonedDateTime = ZonedDateTime.now(fixedClock) + companion object { private val fixedClock = Clock.fixed( ZonedDateTime.of(2025, 7, 19, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")).toInstant(),