Skip to content

Commit f346bdb

Browse files
committed
Extracted duplicated stubbings in ClientTest into a helper
1 parent 99cec1b commit f346bdb

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎src/test/java/com/bitpay/sdk/ClientTest.java‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,7 @@ public void it_should_create_refund() throws BitPayApiException, BitPayGenericEx
663663
Mockito.when(this.bitPayClient.post("refunds/", createRefundJsonRequest, true))
664664
.thenReturn(
665665
this.getHttpResponseWithSpecificBody(getPreparedJsonDataFromFile("createRefundResponse.json")));
666-
Mockito.when(this.guidGenerator.execute()).thenReturn(EXAMPLE_UUID);
667-
Mockito.when(this.accessTokens.getAccessToken(Facade.MERCHANT)).thenReturn(merchantToken);
666+
setupTokenContainerGetAccessTokenAndExecuteStubs(Facade.MERCHANT, merchantToken);
668667
Client testedClass = this.getTestedClass();
669668

670669
// when
@@ -1556,8 +1555,7 @@ public void it_should_test_updatePayoutRecipient() throws BitPayApiException, Bi
15561555
payoutRecipient.setLabel(label);
15571556
payoutRecipient.setToken(PAYOUT_ACCESS_TOKEN);
15581557

1559-
Mockito.when(this.guidGenerator.execute()).thenReturn(EXAMPLE_UUID);
1560-
Mockito.when(this.accessTokens.getAccessToken(Facade.PAYOUT)).thenReturn(PAYOUT_ACCESS_TOKEN);
1558+
setupTokenContainerGetAccessTokenAndExecuteStubs(Facade.PAYOUT, PAYOUT_ACCESS_TOKEN);
15611559
Mockito.when(this.bitPayClient.update(
15621560
"recipients/" + RECIPIENT_ID,
15631561
getPreparedJsonDataFromFile("updatePayoutRecipientRequest.json")
@@ -2104,4 +2102,12 @@ private Client getTestedClass() {
21042102
this.guidGenerator
21052103
);
21062104
}
2105+
2106+
private void setupTokenContainerGetAccessTokenAndExecuteStubs(
2107+
Facade getAccessTokenArg1,
2108+
String getAccessTokenReturnValue
2109+
) throws BitPayGenericException {
2110+
Mockito.when(this.guidGenerator.execute()).thenReturn(EXAMPLE_UUID);
2111+
Mockito.when(this.accessTokens.getAccessToken(getAccessTokenArg1)).thenReturn(getAccessTokenReturnValue);
2112+
}
21072113
}

0 commit comments

Comments
 (0)