mirror of
https://github.com/bitwarden/android.git
synced 2026-08-29 10:17:56 -05:00
Add logic to identify root cause of flakey test (#4056)
This commit is contained in:
+20
-1
@@ -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 <T> Result<T>.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",
|
||||
|
||||
Reference in New Issue
Block a user