Move FakeBugReporterMode to FakeBugReporter.Mode

This commit is contained in:
Benoit Marty 2024-05-23 10:55:22 +02:00 committed by Benoit Marty
parent 1459ff0f77
commit 9ddefc08c5
2 changed files with 13 additions and 13 deletions

View file

@ -144,7 +144,7 @@ class BugReportPresenterTest {
@Test @Test
fun `present - send success`() = runTest { fun `present - send success`() = runTest {
val presenter = createPresenter( val presenter = createPresenter(
FakeBugReporter(mode = FakeBugReporterMode.Success), FakeBugReporter(mode = FakeBugReporter.Mode.Success),
FakeCrashDataStore(crashData = A_CRASH_DATA, appHasCrashed = true), FakeCrashDataStore(crashData = A_CRASH_DATA, appHasCrashed = true),
FakeScreenshotHolder(screenshotUri = A_SCREENSHOT_URI), FakeScreenshotHolder(screenshotUri = A_SCREENSHOT_URI),
) )
@ -170,7 +170,7 @@ class BugReportPresenterTest {
@Test @Test
fun `present - send failure`() = runTest { fun `present - send failure`() = runTest {
val presenter = createPresenter( val presenter = createPresenter(
FakeBugReporter(mode = FakeBugReporterMode.Failure), FakeBugReporter(mode = FakeBugReporter.Mode.Failure),
FakeCrashDataStore(crashData = A_CRASH_DATA, appHasCrashed = true), FakeCrashDataStore(crashData = A_CRASH_DATA, appHasCrashed = true),
FakeScreenshotHolder(screenshotUri = A_SCREENSHOT_URI), FakeScreenshotHolder(screenshotUri = A_SCREENSHOT_URI),
) )
@ -219,7 +219,7 @@ class BugReportPresenterTest {
@Test @Test
fun `present - send cancel`() = runTest { fun `present - send cancel`() = runTest {
val presenter = createPresenter( val presenter = createPresenter(
FakeBugReporter(mode = FakeBugReporterMode.Cancel), FakeBugReporter(mode = FakeBugReporter.Mode.Cancel),
FakeCrashDataStore(crashData = A_CRASH_DATA, appHasCrashed = true), FakeCrashDataStore(crashData = A_CRASH_DATA, appHasCrashed = true),
FakeScreenshotHolder(screenshotUri = A_SCREENSHOT_URI), FakeScreenshotHolder(screenshotUri = A_SCREENSHOT_URI),
) )

View file

@ -22,7 +22,13 @@ import io.element.android.libraries.matrix.test.A_FAILURE_REASON
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import java.io.File import java.io.File
class FakeBugReporter(val mode: FakeBugReporterMode = FakeBugReporterMode.Success) : BugReporter { class FakeBugReporter(val mode: Mode = Mode.Success) : BugReporter {
enum class Mode {
Success,
Failure,
Cancel
}
override suspend fun sendBugReport( override suspend fun sendBugReport(
withDevicesLogs: Boolean, withDevicesLogs: Boolean,
withCrashLogs: Boolean, withCrashLogs: Boolean,
@ -37,12 +43,12 @@ class FakeBugReporter(val mode: FakeBugReporterMode = FakeBugReporterMode.Succes
listener?.onProgress(50) listener?.onProgress(50)
delay(100) delay(100)
when (mode) { when (mode) {
FakeBugReporterMode.Success -> Unit Mode.Success -> Unit
FakeBugReporterMode.Failure -> { Mode.Failure -> {
listener?.onUploadFailed(A_FAILURE_REASON) listener?.onUploadFailed(A_FAILURE_REASON)
return return
} }
FakeBugReporterMode.Cancel -> { Mode.Cancel -> {
listener?.onUploadCancelled() listener?.onUploadCancelled()
return return
} }
@ -64,9 +70,3 @@ class FakeBugReporter(val mode: FakeBugReporterMode = FakeBugReporterMode.Succes
// No op // No op
} }
} }
enum class FakeBugReporterMode {
Success,
Failure,
Cancel
}