@@ -35,28 +35,6 @@ class BraintreeGraphQLClientUnitTest {
3535 configuration = Configuration .fromJson(Fixtures .CONFIGURATION_WITH_GRAPHQL )
3636 }
3737
38- @Test
39- @Throws(MalformedURLException ::class , URISyntaxException ::class )
40- fun post_withPathAndDataAndConfigurationAndCallback_sendsHttpRequest () {
41- val httpRequestSlot = slot<HttpRequest >()
42- every {
43- httpClient.sendRequest(capture(httpRequestSlot), httpResponseCallback)
44- } returns Unit
45-
46- val sut = BraintreeGraphQLClient (httpClient)
47- sut.post(" sample/path" , " data" , configuration, authorization, httpResponseCallback)
48-
49- val httpRequest = httpRequestSlot.captured
50- assertEquals(URL (" https://example-graphql.com/graphql/sample/path" ), httpRequest.url)
51- assertEquals(" data" , String (httpRequest.data, StandardCharsets .UTF_8 ))
52- assertEquals(" POST" , httpRequest.method)
53-
54- val headers = httpRequest.headers
55- assertEquals(" braintree/android/" + BuildConfig .VERSION_NAME , headers[" User-Agent" ])
56- assertEquals(" Bearer encoded_auth_fingerprint" , headers[" Authorization" ])
57- assertEquals(" 2024-08-23" , headers[" Braintree-Version" ])
58- }
59-
6038 @Test
6139 @Throws(MalformedURLException ::class , URISyntaxException ::class )
6240 fun post_withDataAndConfigurationAndCallback_sendsHttpRequest () {
@@ -70,7 +48,7 @@ class BraintreeGraphQLClientUnitTest {
7048
7149 val httpRequest = httpRequestSlot.captured
7250 assertEquals(URL (" https://example-graphql.com/graphql" ), httpRequest.url)
73- assertEquals(" data" , String (httpRequest.data, StandardCharsets .UTF_8 ))
51+ assertEquals(" data" , String (httpRequest.data ? : ByteArray ( 0 ) , StandardCharsets .UTF_8 ))
7452 assertEquals(" POST" , httpRequest.method)
7553
7654 val headers = httpRequest.headers
@@ -79,43 +57,6 @@ class BraintreeGraphQLClientUnitTest {
7957 assertEquals(" 2024-08-23" , headers[" Braintree-Version" ])
8058 }
8159
82- @Test
83- @Throws(Exception ::class )
84- fun post_withPathAndDataAndConfiguration_sendsHttpRequest () {
85- val httpRequestSlot = slot<HttpRequest >()
86- every { httpClient.sendRequest(capture(httpRequestSlot)) } returns " sample response"
87-
88- val sut = BraintreeGraphQLClient (httpClient)
89- val result = sut.post(" sample/path" , " data" , configuration, authorization)
90- assertEquals(" sample response" , result)
91-
92- val httpRequest = httpRequestSlot.captured
93- assertEquals(URL (" https://example-graphql.com/graphql/sample/path" ), httpRequest.url)
94- assertEquals(" data" , String (httpRequest.data, StandardCharsets .UTF_8 ))
95- assertEquals(" POST" , httpRequest.method)
96-
97- val headers = httpRequest.headers
98- assertEquals(" braintree/android/" + BuildConfig .VERSION_NAME , headers[" User-Agent" ])
99- assertEquals(" Bearer encoded_auth_fingerprint" , headers[" Authorization" ])
100- assertEquals(" 2024-08-23" , headers[" Braintree-Version" ])
101- }
102-
103- @Test
104- fun post_withPathAndDataAndConfigurationAndCallback_withInvalidToken_forwardsExceptionToCallback () {
105- val authorization = InvalidAuthorization (" invalid" , " token invalid" )
106-
107- val exceptionSlot = slot<BraintreeException >()
108- every {
109- httpResponseCallback.onResult(null , capture(exceptionSlot))
110- } returns Unit
111-
112- val sut = BraintreeGraphQLClient (httpClient)
113- sut.post(" sample/path" , " data" , configuration, authorization, httpResponseCallback)
114-
115- val exception = exceptionSlot.captured
116- assertEquals(" token invalid" , exception.message)
117- }
118-
11960 @Test
12061 fun post_withDataAndConfigurationAndCallback_withInvalidToken_forwardsExceptionToCallback () {
12162 val authorization = InvalidAuthorization (" invalid" , " token invalid" )
@@ -131,16 +72,4 @@ class BraintreeGraphQLClientUnitTest {
13172 val exception = exceptionSlot.captured
13273 assertEquals(" token invalid" , exception.message)
13374 }
134-
135- @Test
136- @Throws(Exception ::class )
137- fun post_withPathAndDataAndConfiguration_withInvalidToken_throwsBraintreeException () {
138- val authorization = InvalidAuthorization (" invalid" , " token invalid" )
139- val sut = BraintreeGraphQLClient (httpClient)
140- try {
141- sut.post(" sample/path" , " data" , configuration, authorization)
142- } catch (e: BraintreeException ) {
143- assertEquals(" token invalid" , e.message)
144- }
145- }
14675}
0 commit comments