-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Description This was requested in #2006
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
purchases/src/androidTest/kotlin/com/revenuecat/purchases/ErrorsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.revenuecat.purchases | ||
|
||
import android.os.Bundle | ||
import android.os.Parcel | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class ErrorsTest { | ||
|
||
@Test | ||
fun errorIsSerializable() { | ||
val purchasesError = PurchasesError( | ||
PurchasesErrorCode.ConfigurationError, | ||
"Underlying error message", | ||
) | ||
val purchasesException = PurchasesException(purchasesError) | ||
val bundle = Bundle().apply { | ||
putSerializable("exception", purchasesException) | ||
} | ||
val parcel = Parcel.obtain() | ||
val readBundle: Bundle? | ||
try { | ||
// Write the bundle to a parcel in order to actually perform the serialization. Without this, | ||
// the bundle will not be serialized and the test will be successful while not actually being serializable. | ||
parcel.writeBundle(bundle) | ||
parcel.setDataPosition(0) | ||
readBundle = parcel.readBundle(javaClass.classLoader)!! | ||
} finally { | ||
parcel.recycle() | ||
} | ||
assertThat(readBundle).isNotNull | ||
val serializedException = readBundle!!.getSerializable("exception", PurchasesException::class.java) | ||
assertThat(serializedException!!.code).isEqualTo(purchasesException.code) | ||
assertThat(serializedException.underlyingErrorMessage).isEqualTo(purchasesException.underlyingErrorMessage) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters