Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed May 3, 2022
1 parent 2f0e4e4 commit 8602cbb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,6 +58,8 @@ class DownloadMediaUseCaseTest {
@MockK
lateinit var notificationUtils: NotificationUtils

private val clock = FakeClock()

private val file = FakeFile()

@OverrideMockKs
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}

Expand All @@ -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)
Expand All @@ -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)
}
}
}
27 changes: 27 additions & 0 deletions vector/src/test/java/im/vector/app/test/fakes/FakeClock.kt
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 8602cbb

Please sign in to comment.