From 7b8c8a5b2e1db494099013e76b84adbf15665198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Mur=C3=A7a?= Date: Sat, 19 Jul 2025 16:31:48 -0300 Subject: [PATCH] test: add unit tests to MatchMapper.kt --- .../data/mapper/MatchMapperTest.kt | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 app/src/test/java/xyz/leomurca/csgomatches/data/mapper/MatchMapperTest.kt diff --git a/app/src/test/java/xyz/leomurca/csgomatches/data/mapper/MatchMapperTest.kt b/app/src/test/java/xyz/leomurca/csgomatches/data/mapper/MatchMapperTest.kt new file mode 100644 index 0000000..192970e --- /dev/null +++ b/app/src/test/java/xyz/leomurca/csgomatches/data/mapper/MatchMapperTest.kt @@ -0,0 +1,131 @@ +package xyz.leomurca.csgomatches.data.mapper + +import xyz.leomurca.csgomatches.data.model.LeagueDto +import xyz.leomurca.csgomatches.data.model.MatchDto +import xyz.leomurca.csgomatches.data.model.OpponentDto +import xyz.leomurca.csgomatches.data.model.OpponentRecord +import xyz.leomurca.csgomatches.data.model.PlayerDto +import xyz.leomurca.csgomatches.data.model.SerieDto +import xyz.leomurca.csgomatches.data.model.TeamDetailsDto +import xyz.leomurca.csgomatches.domain.model.MatchStatus +import java.time.ZonedDateTime +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull + +class MatchMapperTest { + + @Test + fun `MatchDto - toDomain converts correctly with all fields`() { + // Arrange + val beginAt = ZonedDateTime.parse("2025-07-19T10:00:00Z") + val dto = MatchDto( + beginAt = beginAt, + opponents = listOf( + OpponentDto( + type = "Team", + opponent = OpponentRecord(id = 1, name = "Team A", imageUrl = "urlA") + ), + OpponentDto( + type = "Team", + opponent = OpponentRecord(id = 2, name = "Team B", imageUrl = "urlB") + ) + ), + league = LeagueDto(id = 10, name = "CS League", imageUrl = "leagueUrl"), + serie = SerieDto(id = 20, fullName = "Serie X"), + status = "running" + ) + + // Act + val domain = dto.toDomain() + + // Assert + assertEquals(beginAt, domain.beginAt) + assertEquals(2, domain.opponents.size) + assertEquals("Team A", domain.opponents[0].name) + assertEquals("CS League", domain.league.name) + assertEquals("Serie X", domain.serie.name) + assertEquals(MatchStatus.LIVE, domain.matchStatus) + } + + @Test + fun `MatchDto - toDomain handles nulls gracefully`() { + // Arrange + val dto = MatchDto( + beginAt = null, + opponents = listOf( + OpponentDto(type = "Team", OpponentRecord(id = 1, name = null, imageUrl = null)) + ), + league = LeagueDto(id = 11, name = null, imageUrl = null), + serie = SerieDto(id = 22, fullName = null), + status = null + ) + + // Act + val domain = dto.toDomain() + + // Assert + assertNull(domain.beginAt) + assertEquals("", domain.opponents[0].name) + assertEquals("", domain.opponents[0].imageUrl) + assertEquals("", domain.league.name) + assertEquals("", domain.league.imageUrl) + assertEquals("", domain.serie.name) + assertEquals(MatchStatus.UNKNOWN, domain.matchStatus) + } + + @Test + fun `TeamDetailsDto - toDomain maps all players`() { + // Arrange + val dto = TeamDetailsDto( + id = 101, + name = "My Team", + imageUrl = "team.png", + players = listOf( + PlayerDto( + id = 1, + name = "nick", + firstName = "John", + lastName = "Doe", + imageUrl = "img1.png" + ), + PlayerDto( + id = 2, + name = "nick2", + firstName = "Jane", + lastName = "Smith", + imageUrl = "img2.png" + ) + ) + ) + + // Act + val domain = dto.toDomain() + + // Assert + assertEquals(101, domain.id) + assertEquals("My Team", domain.name) + assertEquals(2, domain.players.size) + assertEquals("John", domain.players[0].firstName) + assertEquals("Smith", domain.players[1].lastName) + } + + @Test + fun `TeamDetailsDto - toDomain with empty player list`() { + // Arrange + val dto = TeamDetailsDto( + id = 200, + name = "No Players", + imageUrl = null, + players = emptyList() + ) + + // Act + val domain = dto.toDomain() + + // Assert + assertEquals(0, domain.players.size) + assertEquals("No Players", domain.name) + assertEquals(null, domain.imageUrl) + } +}