Skip to content

Commit 96eea61

Browse files
Use regular java test instead of connected tests
1 parent ee49df9 commit 96eea61

22 files changed

+172
-190
lines changed

android/build.gradle

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ android {
9595
versionCode 1
9696
versionName "1.0"
9797
vectorDrawables.useSupportLibrary = true
98-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
9998
consumerProguardFiles 'proguard-rules.txt'
10099
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
101100

@@ -131,6 +130,16 @@ android {
131130
}
132131
}
133132
}
133+
134+
// When running tests on bitrise we need to make sure that the test artifacts are inside
135+
// the root project directory (in that case example/android), or it won't be picked up.
136+
testOptions {
137+
unitTests.all { Test test ->
138+
def outputRoot = rootProject.layout.buildDirectory.get().asFile
139+
test.reports.junitXml.outputLocation.set(new File(outputRoot, "test-results/${test.name}"))
140+
test.reports.html.outputLocation.set(new File(outputRoot, "reports/tests/${test.name}"))
141+
}
142+
}
134143
}
135144

136145
repositories {
@@ -229,10 +238,10 @@ dependencies {
229238
// Users need to declare this dependency on their own, otherwise all methods are a no-op
230239
compileOnly 'com.stripe:stripe-android-issuing-push-provisioning:1.1.0'
231240

232-
androidTestImplementation "junit:junit:4.13"
233-
androidTestImplementation "androidx.test:core:1.4.0"
234-
androidTestImplementation 'androidx.test:runner:1.1.0'
235-
androidTestImplementation "org.mockito:mockito-core:3.+"
241+
testImplementation "junit:junit:4.13"
242+
testImplementation "org.mockito:mockito-core:3.+"
243+
testImplementation "org.robolectric:robolectric:4.10"
244+
testImplementation "androidx.test:core:1.4.0"
236245

237246
implementation "androidx.compose.ui:ui:1.7.8"
238247
implementation "androidx.compose.foundation:foundation-layout:1.7.8"

android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetManager.kt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.facebook.react.bridge.ReactApplicationContext
66
import com.facebook.react.bridge.ReadableArray
77
import com.facebook.react.bridge.WritableArray
88
import com.facebook.react.bridge.WritableMap
9-
import com.facebook.react.bridge.WritableNativeMap
109
import com.reactnativestripesdk.utils.ErrorType
1110
import com.reactnativestripesdk.utils.StripeUIManager
1211
import com.reactnativestripesdk.utils.createError
@@ -105,7 +104,7 @@ class FinancialConnectionsSheetManager(
105104

106105
is FinancialConnectionsSheetResult.Completed -> {
107106
promise?.resolve(
108-
WritableNativeMap().also {
107+
Arguments.createMap().also {
109108
it.putMap("session", mapFromSession(result.financialConnectionsSession))
110109
},
111110
)
@@ -115,13 +114,13 @@ class FinancialConnectionsSheetManager(
115114

116115
companion object {
117116
private fun createTokenResult(result: FinancialConnectionsSheetForTokenResult.Completed): WritableMap =
118-
WritableNativeMap().also {
117+
Arguments.createMap().also {
119118
it.putMap("session", mapFromSession(result.financialConnectionsSession))
120119
it.putMap("token", mapFromToken(result.token))
121120
}
122121

123122
private fun mapFromSession(financialConnectionsSession: FinancialConnectionsSession): WritableMap {
124-
val session = WritableNativeMap()
123+
val session = Arguments.createMap()
125124
session.putString("id", financialConnectionsSession.id)
126125
session.putString("clientSecret", financialConnectionsSession.clientSecret)
127126
session.putBoolean("livemode", financialConnectionsSession.livemode)
@@ -132,7 +131,7 @@ class FinancialConnectionsSheetManager(
132131
private fun mapFromAccountsList(accounts: FinancialConnectionsAccountList): ReadableArray {
133132
val results: WritableArray = Arguments.createArray()
134133
for (account in accounts.data) {
135-
val map = WritableNativeMap()
134+
val map = Arguments.createMap()
136135
map.putString("id", account.id)
137136
map.putBoolean("livemode", account.livemode)
138137
map.putString("displayName", account.displayName)
@@ -166,10 +165,10 @@ class FinancialConnectionsSheetManager(
166165
if (balance == null) {
167166
return null
168167
}
169-
val map = WritableNativeMap()
168+
val map = Arguments.createMap()
170169
map.putDouble("asOf", balance.asOf * 1000.0)
171170
map.putString("type", mapFromBalanceType(balance.type))
172-
WritableNativeMap().also {
171+
Arguments.createMap().also {
173172
for (entry in balance.current.entries) {
174173
it.putInt(entry.key, entry.value)
175174
}
@@ -181,9 +180,9 @@ class FinancialConnectionsSheetManager(
181180
return map
182181
}
183182

184-
private fun mapFromCashAvailable(balance: Balance): WritableNativeMap =
185-
WritableNativeMap().also { cashMap ->
186-
WritableNativeMap().also { availableMap ->
183+
private fun mapFromCashAvailable(balance: Balance): WritableMap =
184+
Arguments.createMap().also { cashMap ->
185+
Arguments.createMap().also { availableMap ->
187186
balance.cash?.available?.entries?.let { entries ->
188187
for (entry in entries) {
189188
availableMap.putInt(entry.key, entry.value)
@@ -193,9 +192,9 @@ class FinancialConnectionsSheetManager(
193192
}
194193
}
195194

196-
private fun mapFromCreditUsed(balance: Balance): WritableNativeMap =
197-
WritableNativeMap().also { creditMap ->
198-
WritableNativeMap().also { usedMap ->
195+
private fun mapFromCreditUsed(balance: Balance): WritableMap =
196+
Arguments.createMap().also { creditMap ->
197+
Arguments.createMap().also { usedMap ->
199198
balance.credit?.used?.entries?.let { entries ->
200199
for (entry in entries) {
201200
usedMap.putInt(entry.key, entry.value)
@@ -209,7 +208,7 @@ class FinancialConnectionsSheetManager(
209208
if (balanceRefresh == null) {
210209
return null
211210
}
212-
val map = WritableNativeMap()
211+
val map = Arguments.createMap()
213212
map.putString("status", mapFromBalanceRefreshStatus(balanceRefresh.status))
214213
map.putDouble("lastAttemptedAt", balanceRefresh.lastAttemptedAt * 1000.0)
215214
return map

android/src/main/java/com/reactnativestripesdk/GooglePayRequestHelper.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package com.reactnativestripesdk
33
import android.app.Activity
44
import android.content.Intent
55
import androidx.fragment.app.FragmentActivity
6+
import com.facebook.react.bridge.Arguments
67
import com.facebook.react.bridge.Promise
78
import com.facebook.react.bridge.ReadableMap
8-
import com.facebook.react.bridge.WritableNativeMap
99
import com.google.android.gms.tasks.Task
1010
import com.google.android.gms.wallet.AutoResolveHelper
1111
import com.google.android.gms.wallet.PaymentData
@@ -165,7 +165,7 @@ class GooglePayRequestHelper {
165165
promise: Promise,
166166
) {
167167
val paymentInformation = JSONObject(paymentData.toJson())
168-
val promiseResult = WritableNativeMap()
168+
val promiseResult = Arguments.createMap()
169169
stripe.createPaymentMethod(
170170
PaymentMethodCreateParams.createFromGooglePay(paymentInformation),
171171
callback =
@@ -193,7 +193,7 @@ class GooglePayRequestHelper {
193193
) {
194194
val paymentInformation = JSONObject(paymentData.toJson())
195195
val googlePayResult = GooglePayResult.fromJson(paymentInformation)
196-
val promiseResult = WritableNativeMap()
196+
val promiseResult = Arguments.createMap()
197197
googlePayResult.token?.let {
198198
promiseResult.putMap("token", mapFromToken(it))
199199
if (googlePayResult.shippingInformation != null) {

android/src/main/java/com/reactnativestripesdk/PaymentSheetManager.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import com.facebook.react.bridge.Promise
2020
import com.facebook.react.bridge.ReactApplicationContext
2121
import com.facebook.react.bridge.ReadableMap
2222
import com.facebook.react.bridge.WritableMap
23-
import com.facebook.react.bridge.WritableNativeMap
2423
import com.reactnativestripesdk.addresssheet.AddressSheetView
2524
import com.reactnativestripesdk.utils.ErrorType
2625
import com.reactnativestripesdk.utils.KeepJsAwakeTask
@@ -145,7 +144,7 @@ class PaymentSheetManager(
145144
paymentOptionResult.paymentOption?.let {
146145
val bitmap = getBitmapFromDrawable(it.icon())
147146
val imageString = getBase64FromBitmap(bitmap)
148-
val option: WritableMap = WritableNativeMap()
147+
val option: WritableMap = Arguments.createMap()
149148
option.putString("label", it.label)
150149
option.putString("image", imageString)
151150
val additionalFields: Map<String, Any> = mapOf("didCancel" to paymentOptionResult.didCancel)
@@ -190,7 +189,7 @@ class PaymentSheetManager(
190189
}
191190

192191
is PaymentSheetResult.Completed -> {
193-
resolvePaymentResult(WritableNativeMap())
192+
resolvePaymentResult(Arguments.createMap())
194193
paymentSheet = null
195194
flowController = null
196195
}
@@ -326,7 +325,7 @@ class PaymentSheetManager(
326325
.confirmCustomPaymentMethodCallback(this)
327326
.build(activity, signal)
328327
}
329-
initPromise.resolve(WritableNativeMap())
328+
initPromise.resolve(Arguments.createMap())
330329
}
331330
}
332331

@@ -418,11 +417,11 @@ class PaymentSheetManager(
418417
flowController?.getPaymentOption()?.let {
419418
val bitmap = getBitmapFromDrawable(it.icon())
420419
val imageString = getBase64FromBitmap(bitmap)
421-
val option: WritableMap = WritableNativeMap()
420+
val option: WritableMap = Arguments.createMap()
422421
option.putString("label", it.label)
423422
option.putString("image", imageString)
424423
createResult("paymentOption", option)
425-
} ?: run { WritableNativeMap() }
424+
} ?: run { Arguments.createMap() }
426425
initPromise.resolve(result)
427426
}
428427

android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import com.facebook.react.bridge.ReadableArray
1818
import com.facebook.react.bridge.ReadableMap
1919
import com.facebook.react.bridge.UiThreadUtil
2020
import com.facebook.react.bridge.WritableMap
21-
import com.facebook.react.bridge.WritableNativeMap
2221
import com.facebook.react.module.annotations.ReactModule
2322
import com.reactnativestripesdk.addresssheet.AddressLauncherManager
2423
import com.reactnativestripesdk.customersheet.CustomerSheetManager
@@ -502,7 +501,7 @@ class StripeSdkModule(
502501
object : ApiResultCallback<Token> {
503502
override fun onSuccess(result: Token) {
504503
val tokenId = result.id
505-
val res = WritableNativeMap()
504+
val res = Arguments.createMap()
506505
res.putString("tokenId", tokenId)
507506
promise.resolve(res)
508507
}
@@ -779,7 +778,7 @@ class StripeSdkModule(
779778
expand = listOf("payment_method"),
780779
object : ApiResultCallback<PaymentIntent> {
781780
override fun onError(e: Exception) {
782-
promise.resolve(createResult("paymentIntent", WritableNativeMap()))
781+
promise.resolve(createResult("paymentIntent", Arguments.createMap()))
783782
}
784783

785784
override fun onSuccess(result: PaymentIntent) {
@@ -799,7 +798,7 @@ class StripeSdkModule(
799798
expand = listOf("payment_method"),
800799
object : ApiResultCallback<SetupIntent> {
801800
override fun onError(e: Exception) {
802-
promise.resolve(createResult("setupIntent", WritableNativeMap()))
801+
promise.resolve(createResult("setupIntent", Arguments.createMap()))
803802
}
804803

805804
override fun onSuccess(result: SetupIntent) {
@@ -909,7 +908,7 @@ class StripeSdkModule(
909908
PushProvisioningProxy.isCardInWallet(it, last4) { isCardInWallet, token, error ->
910909
val result: WritableMap =
911910
error ?: run {
912-
val map = WritableNativeMap()
911+
val map = Arguments.createMap()
913912
map.putBoolean("isInWallet", isCardInWallet)
914913
map.putMap("token", token)
915914
map

android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package com.reactnativestripesdk.addresssheet
33
import android.annotation.SuppressLint
44
import android.util.Log
55
import android.widget.FrameLayout
6+
import com.facebook.react.bridge.Arguments
67
import com.facebook.react.bridge.ReadableMap
78
import com.facebook.react.bridge.WritableMap
8-
import com.facebook.react.bridge.WritableNativeMap
99
import com.facebook.react.uimanager.ThemedReactContext
1010
import com.facebook.react.uimanager.UIManagerHelper
1111
import com.reactnativestripesdk.buildPaymentSheetAppearance
@@ -172,14 +172,14 @@ class AddressSheetView(
172172
}
173173

174174
internal fun buildResult(addressDetails: AddressDetails): WritableMap =
175-
WritableNativeMap().apply {
175+
Arguments.createMap().apply {
176176
putMap(
177177
"result",
178-
WritableNativeMap().apply {
178+
Arguments.createMap().apply {
179179
putString("name", addressDetails.name)
180180
putMap(
181181
"address",
182-
WritableNativeMap().apply {
182+
Arguments.createMap().apply {
183183
putString("city", addressDetails.address?.city)
184184
putString("country", addressDetails.address?.country)
185185
putString("line1", addressDetails.address?.line1)

android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetManager.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import com.facebook.react.bridge.Promise
1212
import com.facebook.react.bridge.ReactApplicationContext
1313
import com.facebook.react.bridge.ReadableMap
1414
import com.facebook.react.bridge.WritableMap
15-
import com.facebook.react.bridge.WritableNativeMap
1615
import com.reactnativestripesdk.ReactNativeCustomerAdapter
1716
import com.reactnativestripesdk.ReactNativeCustomerSessionProvider
1817
import com.reactnativestripesdk.buildBillingDetails
@@ -157,7 +156,7 @@ class CustomerSheetManager(
157156

158157
customerSheet?.configure(configuration.build())
159158

160-
initPromise.resolve(WritableNativeMap())
159+
initPromise.resolve(Arguments.createMap())
161160
}
162161

163162
private fun handleResult(result: CustomerSheetResult) {

android/src/main/java/com/reactnativestripesdk/pushprovisioning/TapAndPayProxy.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package com.reactnativestripesdk.pushprovisioning
22

33
import android.app.Activity
44
import android.util.Log
5+
import com.facebook.react.bridge.Arguments
56
import com.facebook.react.bridge.ReadableMap
67
import com.facebook.react.bridge.WritableMap
7-
import com.facebook.react.bridge.WritableNativeMap
88
import com.google.android.gms.tasks.Task
99
import com.reactnativestripesdk.utils.createError
1010

@@ -108,7 +108,7 @@ object TapAndPayProxy {
108108
}
109109

110110
private fun mapFromTokenInfo(token: Any?): WritableMap {
111-
val result = WritableNativeMap()
111+
val result = Arguments.createMap()
112112
token?.let {
113113
try {
114114
val tokenInfoClass = Class.forName("com.google.android.gms.tapandpay.issuer.TokenInfo")

android/src/main/java/com/reactnativestripesdk/utils/Errors.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.reactnativestripesdk.utils
22

3+
import com.facebook.react.bridge.Arguments
34
import com.facebook.react.bridge.WritableMap
4-
import com.facebook.react.bridge.WritableNativeMap
55
import com.stripe.android.core.exception.APIException
66
import com.stripe.android.core.exception.AuthenticationException
77
import com.stripe.android.core.exception.InvalidRequestException
@@ -66,8 +66,8 @@ internal fun mapError(
6666
type: String?,
6767
stripeErrorCode: String?,
6868
): WritableMap {
69-
val map: WritableMap = WritableNativeMap()
70-
val details: WritableMap = WritableNativeMap()
69+
val map: WritableMap = Arguments.createMap()
70+
val details: WritableMap = Arguments.createMap()
7171
details.putString("code", code)
7272
details.putString("message", message)
7373
details.putString("localizedMessage", localizedMessage)

0 commit comments

Comments
 (0)