I'm using wrapper for BillingClient and after migration from Billing Library 4.0 to 5.0 there is an issue with unit testing of specific builder - BillingFlowParams.SubscriptionUpdateParams
builder.
Specific wrapper's method that is having issue looks like this:
fun upgradeSubscription(sub: Purchase, product: Product, activity: Activity) {
val newOfferToken = product.productDetails.getOffer()?.offerToken ?: return
val updateParams = BillingFlowParams.SubscriptionUpdateParams.newBuilder()
.setOldPurchaseToken(sub.purchaseToken)
.setReplaceProrationMode(MODE)
.build()
val productDetailsParamsList = listOf(
ProductDetailsParams.newBuilder()
.setProductDetails(product.productDetails)
.setOfferToken(newOfferToken)
.build()
)
val billingFlowParams = BillingFlowParams.newBuilder()
.setProductDetailsParamsList(productDetailsParamsList)
.setSubscriptionUpdateParams(updateParams)
.build()
client.launchBillingFlow(activity, billingFlowParams)
}
and my test method looks like this:
@Test
fun `should test upgradeSubscription`() {
mockkStatic(BillingFlowParams::class)
val params = slot<BillingFlowParams>()
val activity = mockkClass(Activity::class)
val sub = getMockedPurchase()
billingWrapper.upgradeSubscription(sub, product, activity)
verify { client.launchBillingFlow(storeActivity, capture(params)) }
}
Test fails at .build()
line of BillingFlowParams.SubscriptionUpdateParams
's builder with such exception:
java.lang.IllegalArgumentException: Please provide Old SKU purchase information(token/id) or original external transaction id, not both.
Meanwhile in real-life usage it works fine. So I'm wondering how to fix this problem with the unit test.
I've found the same question, but unfortunately it still has no answer and no solution.