StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.
Kotlin iptv-player
feat: Refactor markAsWatched method to use invoke syntax and add unit test for delegation
David Nashash6141e48a7ce7
diff --git a/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerHistoryCoordinator.kt b/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerHistoryCoordinator.ktindex 5415c0f4..d3820424 100644--- a/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerHistoryCoordinator.kt+++ b/feature/playback/src/main/java/com/streamvault/feature/playback/player/PlayerHistoryCoordinator.kt@@ -38,7 +38,7 @@ class PlayerHistoryCoordinator @Inject constructor(repository.recordPlayback(history)internal suspend fun markAsWatched(history: PlaybackHistory): Result<Unit> =- markAsWatched(history)+ markAsWatched.invoke(history)internal suspend fun updateResumePosition(history: PlaybackHistory): Result<Unit> =repository.updateResumePosition(history)diff --git a/feature/playback/src/test/java/com/streamvault/feature/playback/player/PlayerHistoryCoordinatorTest.kt b/feature/playback/src/test/java/com/streamvault/feature/playback/player/PlayerHistoryCoordinatorTest.ktnew file mode 100644index 00000000..b7b55a5e--- /dev/null+++ b/feature/playback/src/test/java/com/streamvault/feature/playback/player/PlayerHistoryCoordinatorTest.kt@@ -0,0 +1,44 @@+package com.streamvault.feature.playback.player++import com.google.common.truth.Truth.assertThat+import com.streamvault.domain.model.ContentType+import com.streamvault.domain.model.PlaybackHistory+import com.streamvault.domain.model.Result+import com.streamvault.domain.repository.PlaybackHistoryRepository+import com.streamvault.domain.usecase.MarkAsWatched+import com.streamvault.feature.playback.api.PlaybackSurfaceRefreshPort+import kotlinx.coroutines.test.runTest+import org.junit.Test+import org.mockito.kotlin.eq+import org.mockito.kotlin.mock+import org.mockito.kotlin.verify+import org.mockito.kotlin.whenever++class PlayerHistoryCoordinatorTest {++ @Test+ fun `markAsWatched delegates to the use case`() = runTest {+ val repository = mock<PlaybackHistoryRepository>()+ val history = PlaybackHistory(+ contentId = 1L,+ contentType = ContentType.MOVIE,+ providerId = 1L,+ title = "Movie",+ streamUrl = "https://example.com/movie.mkv",+ resumePositionMs = 40_000L,+ totalDurationMs = 100_000L+ )+ val expected = Result.success(Unit)+ whenever(repository.markAsWatched(history)).thenReturn(expected)+ val coordinator = PlayerHistoryCoordinator(+ repository = repository,+ playbackSurfaceRefreshPort = mock<PlaybackSurfaceRefreshPort>(),+ markAsWatched = MarkAsWatched(repository)+ )++ val result = coordinator.markAsWatched(history)++ assertThat(result).isEqualTo(expected)+ verify(repository).markAsWatched(eq(history))+ }+}