Skip to content

Commit

Permalink
processed review feedback (bunq#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
tubbynl committed Jun 17, 2018
1 parent 714d486 commit 20c7811
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/bunq/sdk/context/UserContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void initUser(User user) {
}

private void initMainMonetaryAccount(MonetaryAccountBank monetaryAccountBank) {
if(monetaryAccountBank==null) {
if(monetaryAccountBank == null) {
throw new BunqException(ERROR_NO_ACTIVE_MONETARY_ACCOUNT_FOUND);
}
this.primaryMonetaryAccountBank = monetaryAccountBank;
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/com/bunq/sdk/model/core/UserContextHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

public class UserContextHelper extends BunqModel {
private static final String MONETARY_ACCOUNT_STATUS_ACTIVE = "ACTIVE";
private static final int INDEX_FIRST = 0;
private static final String USER_ENDPOINT_URL_LISTING = "user";
private static final String MONETARY_ENDPOINT_URL_READ = "user/%s/monetary-account-bank/%s";

private final ApiClient apiClient;

Expand All @@ -24,20 +25,21 @@ private BunqResponseRaw getRawResponse(String url) {
}

public User getFirstUser() {
BunqResponseRaw responseRaw = getRawResponse("user");
BunqResponseRaw responseRaw = getRawResponse(USER_ENDPOINT_URL_LISTING);
BunqResponse<List<User>> response = fromJsonList(User.class, responseRaw);
return response.getValue().get(INDEX_FIRST);


return response.getValue().stream().findFirst().orElse(null);
}

public MonetaryAccountBank getFirstActiveMonetaryAccountBank(Integer userId) {
BunqResponseRaw responseRaw = getRawResponse(String.format("user/%s/monetary-account-bank", userId));
BunqResponseRaw responseRaw = getRawResponse(String.format(MONETARY_ENDPOINT_URL_READ, userId));
BunqResponse<List<MonetaryAccountBank>> response = fromJsonList(MonetaryAccountBank.class, responseRaw, MonetaryAccountBank.class.getSimpleName());
for (MonetaryAccountBank monetaryAccountBank : response.getValue()) {
if (monetaryAccountBank.getStatus().equals(MONETARY_ACCOUNT_STATUS_ACTIVE)) {
return monetaryAccountBank;
}
}
return null;

return response.getValue().stream()
.filter(monetaryAccountBank->monetaryAccountBank.getStatus().equals(MONETARY_ACCOUNT_STATUS_ACTIVE))
.findFirst()
.orElse(null);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/bunq/sdk/context/UserContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.bunq.sdk.BunqSdkTestBase;
import org.junit.Test;

import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;

public class UserContextTest extends BunqSdkTestBase {

Expand All @@ -16,4 +16,4 @@ public void testConstruct() {
assertNotNull(sut.getUserId());
assertNotNull(sut.getMainMonetaryAccountId());
}
}
}

0 comments on commit 20c7811

Please sign in to comment.