Skip to content

Commit b09ed95

Browse files
authored
Convert PayPalPaymentResourceUnitTest from Java to Kotlin (#1393)
* convert tests * organize imports
1 parent 8a68c49 commit b09ed95

File tree

3 files changed

+65
-61
lines changed

3 files changed

+65
-61
lines changed

PayPal/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ dependencies {
5252
testImplementation libs.json.assert
5353
testImplementation libs.mockito.core
5454
testImplementation libs.mockk
55+
testImplementation libs.kotlin.test
5556
testImplementation libs.test.parameter.injector
5657
testImplementation project(':TestUtils')
5758
}

PayPal/src/test/java/com/braintreepayments/api/paypal/PayPalPaymentResourceUnitTest.java

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.braintreepayments.api.paypal
2+
3+
import org.json.JSONObject
4+
import org.junit.runner.RunWith
5+
import org.robolectric.RobolectricTestParameterInjector
6+
import kotlin.test.Test
7+
import kotlin.test.assertEquals
8+
import kotlin.test.assertFalse
9+
import kotlin.test.assertTrue
10+
11+
@RunWith(RobolectricTestParameterInjector::class)
12+
class PayPalPaymentResourceUnitTest {
13+
14+
@Test
15+
fun `fromJson parses redirectUrl from one-time PaymentResource app switch flow`() {
16+
val oneTimePaymentJson = JSONObject()
17+
.put("paymentResource", JSONObject()
18+
.put("redirectUrl", "www.example.com/redirect")
19+
.put("launchPayPalApp", true)
20+
).toString()
21+
22+
val sut = PayPalPaymentResource.fromJson(oneTimePaymentJson)
23+
assertEquals("www.example.com/redirect", sut.redirectUrl)
24+
assertTrue(sut.isAppSwitchFlow)
25+
}
26+
27+
@Test
28+
fun `fromJson parses redirectUrl from one-time PaymentResource fallback flow`() {
29+
val oneTimePaymentJson = JSONObject()
30+
.put("paymentResource", JSONObject()
31+
.put("redirectUrl", "www.example.com/redirect")
32+
.put("launchPayPalApp", false)
33+
).toString()
34+
35+
val sut = PayPalPaymentResource.fromJson(oneTimePaymentJson)
36+
assertEquals("www.example.com/redirect", sut.redirectUrl)
37+
assertFalse(sut.isAppSwitchFlow)
38+
}
39+
40+
@Test
41+
fun `fromJson parses redirectUrl from billingAgreement PaymentResource`() {
42+
val billingAgreementJson = JSONObject()
43+
.put("agreementSetup", JSONObject()
44+
.put("approvalUrl", "www.example.com/redirect")
45+
).toString()
46+
47+
val sut = PayPalPaymentResource.fromJson(billingAgreementJson)
48+
assertEquals("www.example.com/redirect", sut.redirectUrl)
49+
assertFalse(sut.isAppSwitchFlow)
50+
}
51+
52+
@Test
53+
fun `fromJson parses redirectUrl from billingAgreement PaymentResource returns PayPalRedirectUrl`() {
54+
val billingAgreementJson = JSONObject()
55+
.put("agreementSetup", JSONObject()
56+
.put("approvalUrl", "www.example.com/redirect")
57+
.put("paypalAppApprovalUrl", "www.paypal.example.com/redirect")
58+
).toString()
59+
60+
val sut = PayPalPaymentResource.fromJson(billingAgreementJson)
61+
assertEquals("www.paypal.example.com/redirect", sut.redirectUrl)
62+
assertTrue(sut.isAppSwitchFlow)
63+
}
64+
}

0 commit comments

Comments
 (0)