diff --git a/app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/network/service/CiphersServiceTest.kt b/app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/network/service/CiphersServiceTest.kt index 39cf65156a..e8134e0162 100644 --- a/app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/network/service/CiphersServiceTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/network/service/CiphersServiceTest.kt @@ -311,7 +311,7 @@ class CiphersServiceTest : BaseServiceTest() { ) assertEquals( createMockAttachment(number = 1), - result.getOrThrow(), + result.testGetOrThrow(), ) } @@ -336,6 +336,25 @@ private fun setupMockUri( return mockUri } +/** + * A helper method to attempt validate that the the value is being boxed and causing test to + * inconsistently fail. + * + * This was modified from the code found here: + * * https://github.com/mockk/mockk/issues/485#issuecomment-1973170516 + */ +@Suppress("INVISIBLE_REFERENCE", "UNCHECKED_CAST") +private fun Result.testGetOrThrow(): T = + when (val unboxed: Any? = value) { + is Result.Failure -> throw unboxed.exception + !is Result<*> -> unboxed as T + else -> { + // This means the result is boxed, we could make this recursive to address the issue. + println("Unboxed value = $unboxed") + unboxed as T + } + } + private const val CREATE_ATTACHMENT_SUCCESS_JSON = """ { "attachmentId":"mockAttachmentId-1",