Skip to content

Commit

Permalink
Merge pull request #435 from Adyen/android_refactoring
Browse files Browse the repository at this point in the history
Reformat android code
  • Loading branch information
descorp authored May 3, 2024
2 parents c7d135e + 5c6a28c commit e0100aa
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 65 deletions.
1 change: 0 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,5 @@ dependencies {
//Tests
testImplementation testLibraries.json
testImplementation testLibraries.junit5
testImplementation testLibraries.kotlinCoroutines
testImplementation testLibraries.mockito
}
33 changes: 0 additions & 33 deletions android/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,27 @@ ext {
// Code quality
jacoco_version = '0.8.9'

// Android Dependencies
coroutines_version = "1.6.4"
lifecycle_version = "2.5.1"
material_version = "1.10.0"

// Adyen Dependencies
adyen_version = "5.3.1"

// Tests
arch_core_testing_version = "2.2.0"
espresso_version = "3.5.0"
json_version = '20231013'
junit_jupiter_version = "5.9.1"
mockito_kotlin_version = "4.1.0"
mockito_version = "4.9.0"
robolectric_version = "4.11.1"
test_ext_version = "1.1.4"
test_rules_version = "1.5.0"
turbine_version = "0.12.1"
uiautomator_version = "2.2.0"

testLibraries = [
androidTest : [
"androidx.test:rules:$test_rules_version",
"androidx.test.ext:junit-ktx:$test_ext_version",
"androidx.test.uiautomator:uiautomator:$uiautomator_version"
],
androidx : [
lifecycle: "androidx.arch.core:core-testing:$arch_core_testing_version"
],
espresso : [
"androidx.test.espresso:espresso-contrib:$espresso_version",
"androidx.test.espresso:espresso-core:$espresso_version",
"androidx.test.espresso:espresso-intents:$espresso_version"
],
json : "org.json:json:$json_version",
junit5 : [
"org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version",
"org.junit.jupiter:junit-jupiter-engine:$junit_jupiter_version",
"org.junit.jupiter:junit-jupiter-params:$junit_jupiter_version",
"org.junit.vintage:junit-vintage-engine:$junit_jupiter_version",
],
kotlinCoroutines: [
"org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version",
"app.cash.turbine:turbine:$turbine_version"
],
mockito : [
"org.mockito:mockito-junit-jupiter:$mockito_version",
"org.mockito:mockito-inline:$mockito_version",
"org.mockito.kotlin:mockito-kotlin:$mockito_kotlin_version"
],
mockitoAndroid : [
"org.mockito:mockito-android:$mockito_version",
"org.mockito.kotlin:mockito-kotlin:$mockito_kotlin_version"
],
]
}
2 changes: 1 addition & 1 deletion android/jacoco.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (project.hasProperty('android')) {

project.afterEvaluate {
jacoco {
toolVersion = "0.8.12"
toolVersion = "$jacoco_version"
}

tasks.withType(Test).configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

package com.adyenreactnativesdk.component.applepay

import com.adyen.checkout.components.core.CheckoutConfiguration
import com.adyen.checkout.core.exception.MethodNotImplementedException
import com.adyenreactnativesdk.component.base.BaseModule
import com.adyenreactnativesdk.component.base.ModuleException
import com.facebook.react.bridge.ReactApplicationContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class CardConfigurationParser(config: ReadableMap, private val countryCode: Stri
config.getArray(SUPPORTED_COUNTRY_LIST_KEY)?.toArrayList()?.map { it.toString() }
} else null

private val kcpVisibility: KCPAuthVisibility?
private val kcpVisibility: KCPAuthVisibility?
get() {
return if (config.hasKey(KCP_VISIBILITY_KEY)) {
val value = config.getString(KCP_VISIBILITY_KEY)!!
Expand Down Expand Up @@ -118,10 +118,10 @@ class CardConfigurationParser(config: ReadableMap, private val countryCode: Stri
?.toArrayList()
?.map { it.toString() }
?.mapNotNull { txVariant ->
CardType.getByBrandName(txVariant)?.let {
CardBrand(it)
CardType.getByBrandName(txVariant)?.let {
CardBrand(it)
}
}
}
else null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.junit.Test
class AnalyticsParserTest {

@Test
fun applyConfigurationOnSubDictionary() {
fun testConfigurationOnSubDictionary() {
// GIVEN
val config = WritableMapMock()
val analyticsConfig = WritableMapMock()
Expand Down Expand Up @@ -35,7 +35,6 @@ class AnalyticsParserTest {
// THEN
Assert.assertSame(analyticsParser.analytics.level, AnalyticsLevel.ALL)
Assert.assertFalse(analyticsParser.verboseLogs)

}

@Test
Expand All @@ -51,7 +50,5 @@ class AnalyticsParserTest {
// THEN
Assert.assertSame(analyticsParser.analytics.level, AnalyticsLevel.NONE)
Assert.assertTrue(analyticsParser.verboseLogs)

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.mockito.kotlin.any
class CardConfigurationParserTest {

@Test
fun applyConfigurationOnSubDictionary() {
fun testConfigurationOnSubDictionary() {
// GIVEN
val config = WritableMapMock()
val cardConfig = WritableMapMock()
Expand Down Expand Up @@ -61,7 +61,13 @@ class CardConfigurationParserTest {
// THEN
assertTrue(cardParser.addressVisibility is AddressConfiguration.FullAddress)
assertTrue((cardParser.addressVisibility as AddressConfiguration.FullAddress).defaultCountryCode == "US")
assertTrue((cardParser.addressVisibility as AddressConfiguration.FullAddress).supportedCountryCodes == listOf("US", "GB", "NL"))
assertTrue(
(cardParser.addressVisibility as AddressConfiguration.FullAddress).supportedCountryCodes == listOf(
"US",
"GB",
"NL"
)
)
}

@Test
Expand All @@ -82,14 +88,22 @@ class CardConfigurationParserTest {
// GIVEN
val config = WritableMapMock()
val mockArray = mock(ReadableArray::class.java)
`when`(mockArray.toArrayList()).thenReturn(arrayListOf("mc", "visa", "maestro", "wrong_value"))
`when`(mockArray.toArrayList()).thenReturn(
arrayListOf(
"mc",
"visa",
"maestro",
"wrong_value"
)
)
config.putArray(CardConfigurationParser.SUPPORTED_CARD_TYPES_KEY, mockArray)

// WHEN
val cardParser = CardConfigurationParser(config, "US")

// THEN
val map = cardParser.supportedCardTypes.orEmpty().map { CardType.getByBrandName(it.txVariant) }
val map =
cardParser.supportedCardTypes.orEmpty().map { CardType.getByBrandName(it.txVariant) }
assertEquals(listOf(CardType.MASTERCARD, CardType.VISA, CardType.MAESTRO), map)
}

Expand All @@ -106,7 +120,14 @@ class CardConfigurationParserTest {
config.putString(CardConfigurationParser.SOCIAL_SECURITY_VISIBILITY_KEY, "show")

val supportedCardsArray = mock(ReadableArray::class.java)
`when`(supportedCardsArray.toArrayList()).thenReturn(arrayListOf("mc", "visa", "maestro", "wrong_value"))
`when`(supportedCardsArray.toArrayList()).thenReturn(
arrayListOf(
"mc",
"visa",
"maestro",
"wrong_value"
)
)
config.putArray(CardConfigurationParser.SUPPORTED_CARD_TYPES_KEY, supportedCardsArray)

// WHEN
Expand All @@ -119,9 +140,17 @@ class CardConfigurationParserTest {
verify(mockBuilder, times(1)).setHideCvc(true)
verify(mockBuilder, times(1)).setHideCvcStoredCard(true)
verify(mockBuilder, times(1)).setKcpAuthVisibility(KCPAuthVisibility.SHOW)
verify(mockBuilder, times(1)).setAddressConfiguration(org.mockito.kotlin.any())
verify(mockBuilder, times(1)).setSocialSecurityNumberVisibility(SocialSecurityNumberVisibility.SHOW)
verify(mockBuilder, times(1)).setSupportedCardTypes(*arrayOf(CardBrand("mc"), CardBrand("visa"), CardBrand("maestro")))
verify(mockBuilder, times(1)).setAddressConfiguration(any())
verify(mockBuilder, times(1)).setSocialSecurityNumberVisibility(
SocialSecurityNumberVisibility.SHOW
)
verify(mockBuilder, times(1)).setSupportedCardTypes(
*arrayOf(
CardBrand("mc"),
CardBrand("visa"),
CardBrand("maestro")
)
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.mockito.kotlin.any
class DropInConfigurationParserTest {

@Test
fun applyConfigurationOnSubDictionary() {
fun testConfigurationOnSubDictionary() {
// GIVEN
val mockBuilder = mock(DropInConfiguration.Builder::class.java)
val config = WritableMapMock()
Expand All @@ -32,7 +32,10 @@ class DropInConfigurationParserTest {
val mockBuilder = mock(DropInConfiguration.Builder::class.java)
val config = WritableMapMock()
config.putBoolean(DropInConfigurationParser.SKIP_LIST_WHEN_SINGLE_PAYMENT_METHOD_KEY, false)
config.putBoolean(DropInConfigurationParser.SHOW_PRESELECTED_STORED_PAYMENT_METHOD_KEY, false)
config.putBoolean(
DropInConfigurationParser.SHOW_PRESELECTED_STORED_PAYMENT_METHOD_KEY,
false
)

// WHEN
val sut = DropInConfigurationParser(config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.mockito.kotlin.any
class GooglePayConfigurationParserTest {

@Test
fun applyConfigurationOnSubDictionary() {
fun testConfigurationOnSubDictionary() {
// GIVEN
val mockBuilder = mock(GooglePayConfiguration.Builder::class.java)
val config = WritableMapMock()
Expand Down Expand Up @@ -61,16 +61,35 @@ class GooglePayConfigurationParserTest {
config.putArray(GooglePayConfigurationParser.ALLOWED_AUTH_METHODS_KEY, allowedAuthArray)

val allowedCardArray = mock(ReadableArray::class.java)
`when`(allowedCardArray.toArrayList()).thenReturn(arrayListOf("MASTERCARD", "VISA", "amex", "wrong_value"))
`when`(allowedCardArray.toArrayList()).thenReturn(
arrayListOf(
"MASTERCARD",
"VISA",
"amex",
"wrong_value"
)
)
config.putArray(GooglePayConfigurationParser.ALLOWED_CARD_NETWORKS_KEY, allowedCardArray)

// WHEN
val sut = GooglePayConfigurationParser(config)
sut.applyConfiguration(mockBuilder)

// THEN
verify(mockBuilder, times(1)).setAllowedAuthMethods(arrayListOf("PAN_ONLY", "CRYPTOGRAM_3DS"))
verify(mockBuilder, times(1)).setAllowedCardNetworks(arrayListOf("MASTERCARD", "VISA", "amex", "wrong_value"))
verify(mockBuilder, times(1)).setAllowedAuthMethods(
arrayListOf(
"PAN_ONLY",
"CRYPTOGRAM_3DS"
)
)
verify(mockBuilder, times(1)).setAllowedCardNetworks(
arrayListOf(
"MASTERCARD",
"VISA",
"amex",
"wrong_value"
)
)
verify(mockBuilder, times(1)).setAllowCreditCards(true)
verify(mockBuilder, times(1)).setAllowPrepaidCards(true)
verify(mockBuilder, times(1)).setEmailRequired(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RootConfigurationParserTest {

// THEN
Assert.assertNotNull(rootParser.amount)
Assert.assertEquals(rootParser.amount?.value, 123456.toLong() )
Assert.assertEquals(rootParser.amount?.value, 123456.toLong())
Assert.assertEquals(rootParser.amount?.currency, "USD")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.mockito.kotlin.any
class ThreeDSConfigurationParserTest {

@Test
fun applyConfigurationOnSubDictionary() {
fun testConfigurationOnSubDictionary() {
// GIVEN
val mockBuilder = mock(Adyen3DS2Configuration.Builder::class.java)
val config = WritableMapMock()
Expand All @@ -23,15 +23,17 @@ class ThreeDSConfigurationParserTest {

// THEN
verify(mockBuilder, times(0)).setThreeDSRequestorAppURL(any())

}

@Test
fun testApplyThreeDSConfiguration() {
// GIVEN
val mockBuilder = mock(Adyen3DS2Configuration.Builder::class.java)
val config = WritableMapMock()
config.putString(ThreeDSConfigurationParser.THREEDS2_REQUESTOR_APP_URL_KEY , "https://testing.com")
config.putString(
ThreeDSConfigurationParser.THREEDS2_REQUESTOR_APP_URL_KEY,
"https://testing.com"
)

// WHEN
val sut = ThreeDSConfigurationParser(config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.facebook.react.bridge.ReadableMapKeySetIterator
import com.facebook.react.bridge.ReadableType
import com.facebook.react.bridge.WritableMap

class WritableMapMock: WritableMap, ReadableMapKeySetIterator {
class WritableMapMock : WritableMap, ReadableMapKeySetIterator {

private val map: MutableMap<String, Any?> = mutableMapOf()
private lateinit var iterator: MutableIterator<MutableMap.MutableEntry<String, Any>>
Expand Down Expand Up @@ -65,7 +65,7 @@ class WritableMapMock: WritableMap, ReadableMapKeySetIterator {
is Float -> ReadableType.Number
is Int -> ReadableType.Number
is Long -> ReadableType.Number
is Map<*,*> -> ReadableType.Map
is Map<*, *> -> ReadableType.Map
is Boolean -> ReadableType.Boolean
is Array<*> -> ReadableType.Array
else -> ReadableType.Null
Expand Down

0 comments on commit e0100aa

Please sign in to comment.