diff --git a/vector/src/test/java/im/vector/app/features/media/domain/usecase/DownloadMediaUseCaseTest.kt b/vector/src/test/java/im/vector/app/features/media/domain/usecase/DownloadMediaUseCaseTest.kt index bb05357cb2..d45e6e7ce1 100644 --- a/vector/src/test/java/im/vector/app/features/media/domain/usecase/DownloadMediaUseCaseTest.kt +++ b/vector/src/test/java/im/vector/app/features/media/domain/usecase/DownloadMediaUseCaseTest.kt @@ -23,6 +23,7 @@ import com.airbnb.mvrx.test.MvRxTestRule import im.vector.app.core.intent.getMimeTypeFromUri import im.vector.app.core.utils.saveMedia import im.vector.app.features.notifications.NotificationUtils +import im.vector.app.test.fakes.FakeClock import im.vector.app.test.fakes.FakeFile import im.vector.app.test.fakes.FakeSession import io.mockk.MockKAnnotations @@ -57,6 +58,8 @@ class DownloadMediaUseCaseTest { @MockK lateinit var notificationUtils: NotificationUtils + private val clock = FakeClock() + private val file = FakeFile() @OverrideMockKs @@ -85,7 +88,8 @@ class DownloadMediaUseCaseTest { every { getMimeTypeFromUri(appContext, uri) } returns mimeType file.givenName(name) file.givenUri(uri) - coEvery { saveMedia(any(), any(), any(), any(), any()) } just runs + clock.givenEpoch(123) + coEvery { saveMedia(any(), any(), any(), any(), any(), any()) } just runs // When val result = downloadMediaUseCase.execute(file.instance) @@ -100,7 +104,7 @@ class DownloadMediaUseCaseTest { getMimeTypeFromUri(appContext, uri) } coVerify { - saveMedia(appContext, file.instance, name, mimeType, notificationUtils) + saveMedia(appContext, file.instance, name, mimeType, notificationUtils, 123) } } @@ -113,8 +117,9 @@ class DownloadMediaUseCaseTest { val error = Throwable() file.givenName(name) file.givenUri(uri) + clock.givenEpoch(345) every { getMimeTypeFromUri(appContext, uri) } returns mimeType - coEvery { saveMedia(any(), any(), any(), any(), any()) } throws error + coEvery { saveMedia(any(), any(), any(), any(), any(), any()) } throws error // When val result = downloadMediaUseCase.execute(file.instance) @@ -129,7 +134,7 @@ class DownloadMediaUseCaseTest { getMimeTypeFromUri(appContext, uri) } coVerify { - saveMedia(appContext, file.instance, name, mimeType, notificationUtils) + saveMedia(appContext, file.instance, name, mimeType, notificationUtils, 345) } } } diff --git a/vector/src/test/java/im/vector/app/test/fakes/FakeClock.kt b/vector/src/test/java/im/vector/app/test/fakes/FakeClock.kt new file mode 100644 index 0000000000..1d531f147f --- /dev/null +++ b/vector/src/test/java/im/vector/app/test/fakes/FakeClock.kt @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.test.fakes + +import im.vector.app.core.time.Clock +import io.mockk.every +import io.mockk.mockk + +class FakeClock : Clock by mockk() { + fun givenEpoch(epoch: Long) { + every { epochMillis() } returns epoch + } +}