-
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.
Make PurchasesError java.io.Serializable
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
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,37 @@ | ||
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 { | ||
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