Skip to content

Commit

Permalink
100% Subaccounts test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Jan 21, 2025
1 parent 1c1fdd8 commit 3e9172c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ public void testConstructNoName() {
}

@Test
public void testConstructShortSecret() {
public void testConstructSecretLength() {
CreateSubaccountRequest.Builder builder = CreateSubaccountRequest.builder().name("Department C");
assertThrows(IllegalArgumentException.class, () -> builder.secret("A1b23c5").build());
String min = "*A1b23c5", max = "A1b2*".repeat(5);
assertEquals(min, builder.secret(min).build().getSecret());
assertEquals(max, builder.secret(max).build().getSecret());
assertThrows(IllegalArgumentException.class, () -> builder.secret(min.substring(1)).build());
assertThrows(IllegalArgumentException.class, () -> builder.secret(max + "T").build());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ public void testListCreditTransfers() throws Exception {
assertNotNull(response.get(2));
assertEqualsExpectedMoneyTransfer(response.get(1));
assertNotNull(stubResponseAndGet(responseJson, client::listCreditTransfers));
assertNull(stubResponseAndGet("{}", client::listCreditTransfers));
stubResponseAndAssertThrows(200, () -> client.listCreditTransfers(null), NullPointerException.class);
stubResponseAndAssertThrows(401, () -> client.listCreditTransfers(request), SubaccountsResponseException.class);
assert403ResponseException(client::listCreditTransfers);
Expand Down Expand Up @@ -370,6 +371,7 @@ public void testListBalanceTransfers() throws Exception {
assertNotNull(response.get(2));
assertEqualsExpectedMoneyTransfer(response.get(1));
assertNotNull(stubResponseAndGet(responseJson, client::listBalanceTransfers));
assertNull(stubResponseAndGet("{}", client::listBalanceTransfers));
stubResponseAndAssertThrows(200, () -> client.listBalanceTransfers(null), NullPointerException.class);
stubResponseAndAssertThrows(401, () -> client.listBalanceTransfers(request), SubaccountsResponseException.class);
assert403ResponseException(client::listBalanceTransfers);
Expand Down Expand Up @@ -513,6 +515,9 @@ public void testTransferNumber() throws Exception {
.from(request.getFrom()).to(request.getTo()).number(request.getNumber())
.country("United Kingdom").build()
);
assertThrows(IllegalArgumentException.class, () -> NumberTransfer.builder()
.from(request.getFrom()).to(request.getTo()).number(request.getNumber()).build()
);

new SubaccountsEndpointTestSpec<NumberTransfer, NumberTransfer>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ public void testSerializeAllParameters() {

@Test
public void testSerializeRequiredParameters() {
UpdateSubaccountRequest.Builder builder = UpdateSubaccountRequest.builder("abc6123f");
var builder = UpdateSubaccountRequest.builder("abc6123f");
assertThrows(IllegalStateException.class, builder::build);
assertEquals("{\"suspended\":false}", builder.suspended(false).build().toJson());
builder.usePrimaryAccountBalance(true);
assertEquals("{\"use_primary_account_balance\":true,\"suspended\":false}", builder.build().toJson());
}

@Test
Expand Down

0 comments on commit 3e9172c

Please sign in to comment.