mirror of
https://github.com/element-hq/element-android
synced 2024-11-23 18:05:36 +03:00
Fix test
This commit is contained in:
parent
2f0e4e4f3d
commit
8602cbba7a
2 changed files with 36 additions and 4 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
27
vector/src/test/java/im/vector/app/test/fakes/FakeClock.kt
Normal file
27
vector/src/test/java/im/vector/app/test/fakes/FakeClock.kt
Normal file
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue