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
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(),