From 0ac0bbb37af6db22e68cfb05abcd20aee0e8c417 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 23 May 2023 12:25:07 +0200 Subject: [PATCH 1/2] Create the mockked Bitmap in the constructor, to remove increased time out. --- .../detection/RageshakeDetectionPresenterTest.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/detection/RageshakeDetectionPresenterTest.kt b/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/detection/RageshakeDetectionPresenterTest.kt index 869f0412cd..55482c2526 100644 --- a/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/detection/RageshakeDetectionPresenterTest.kt +++ b/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/detection/RageshakeDetectionPresenterTest.kt @@ -32,9 +32,11 @@ import io.mockk.mockk import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest import org.junit.Test -import kotlin.time.Duration.Companion.seconds class RageshakeDetectionPresenterTest { + + private val aBitmap: Bitmap = mockk() + @Test fun `present - initial state`() = runTest { val screenshotHolder = FakeScreenshotHolder(screenshotUri = null) @@ -85,7 +87,7 @@ class RageshakeDetectionPresenterTest { } @Test - fun `present - screenshot with success then dismiss`() = runTest(timeout = 30.seconds) { + fun `present - screenshot with success then dismiss`() = runTest { val screenshotHolder = FakeScreenshotHolder(screenshotUri = null) val rageshake = FakeRageShake(isAvailableValue = true) val rageshakeDataStore = FakeRageshakeDataStore(isEnabled = true) @@ -108,7 +110,7 @@ class RageshakeDetectionPresenterTest { rageshake.triggerPhoneRageshake() assertThat(awaitItem().takeScreenshot).isTrue() initialState.eventSink.invoke( - RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Success(aBitmap())) + RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Success(aBitmap)) ) assertThat(awaitItem().showDialog).isTrue() initialState.eventSink.invoke(RageshakeDetectionEvents.Dismiss) @@ -153,7 +155,7 @@ class RageshakeDetectionPresenterTest { } @Test - fun `present - screenshot then disable`() = runTest(timeout = 1.seconds) { + fun `present - screenshot then disable`() = runTest { val screenshotHolder = FakeScreenshotHolder(screenshotUri = null) val rageshake = FakeRageShake(isAvailableValue = true) val rageshakeDataStore = FakeRageshakeDataStore(isEnabled = true) @@ -176,7 +178,7 @@ class RageshakeDetectionPresenterTest { rageshake.triggerPhoneRageshake() assertThat(awaitItem().takeScreenshot).isTrue() initialState.eventSink.invoke( - RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Success(aBitmap())) + RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Success(aBitmap)) ) assertThat(awaitItem().showDialog).isTrue() initialState.eventSink.invoke(RageshakeDetectionEvents.Disable) @@ -187,5 +189,3 @@ class RageshakeDetectionPresenterTest { } } -private fun aBitmap(): Bitmap = mockk() - From 5cf17a432f344e56755957a9f4185e03265aedaa Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 23 May 2023 12:46:05 +0200 Subject: [PATCH 2/2] Init the mockked Bitmap only once. --- .../impl/detection/RageshakeDetectionPresenterTest.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/detection/RageshakeDetectionPresenterTest.kt b/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/detection/RageshakeDetectionPresenterTest.kt index 55482c2526..eb49eb450e 100644 --- a/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/detection/RageshakeDetectionPresenterTest.kt +++ b/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/detection/RageshakeDetectionPresenterTest.kt @@ -31,11 +31,20 @@ import io.element.android.libraries.matrix.test.AN_EXCEPTION import io.mockk.mockk import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest +import org.junit.BeforeClass import org.junit.Test class RageshakeDetectionPresenterTest { - private val aBitmap: Bitmap = mockk() + companion object { + private lateinit var aBitmap: Bitmap + + @BeforeClass + @JvmStatic + fun initBitmap() { + aBitmap = mockk() + } + } @Test fun `present - initial state`() = runTest {