@Test public void getBalance_HttpResponseError_OperationFailedException() throws Exception { mockWebServer.enqueue(new MockResponse() .setResponseCode(500) ); expectedEx.expect(OperationFailedException.class); expectedEx.expectCause(Matchers.<Throwable>instanceOf(HttpResponseException.class)); getBalance(ACCOUNT_ID); }
Balance getBalance(@NonNull String accountId) throws OperationFailedException { Utils.checkNotNull(accountId, "account"); Balance balance = null; try { AccountResponse accountResponse = server.accounts().account(KeyPair.fromAccountId(accountId)); if (accountResponse == null) { throw new OperationFailedException("can't retrieve data for account " + accountId); } for (AccountResponse.Balance assetBalance : accountResponse.getBalances()) { if (assetBalance.getAsset().getType().equalsIgnoreCase("native")) { balance = new BalanceImpl(new BigDecimal(assetBalance.getBalance())); } } } catch (HttpResponseException httpError) { if (httpError.getStatusCode() == 404) { throw new AccountNotFoundException(accountId); } else { throw new OperationFailedException(httpError); } } catch (IOException e) { throw new OperationFailedException(e); } if (balance == null) { throw new OperationFailedException(accountId); } return balance; }
AccountInfoRetriever { Balance getBalance(@NonNull String accountId) throws OperationFailedException { Utils.checkNotNull(accountId, "account"); Balance balance = null; try { AccountResponse accountResponse = server.accounts().account(KeyPair.fromAccountId(accountId)); if (accountResponse == null) { throw new OperationFailedException("can't retrieve data for account " + accountId); } for (AccountResponse.Balance assetBalance : accountResponse.getBalances()) { if (assetBalance.getAsset().getType().equalsIgnoreCase("native")) { balance = new BalanceImpl(new BigDecimal(assetBalance.getBalance())); } } } catch (HttpResponseException httpError) { if (httpError.getStatusCode() == 404) { throw new AccountNotFoundException(accountId); } else { throw new OperationFailedException(httpError); } } catch (IOException e) { throw new OperationFailedException(e); } if (balance == null) { throw new OperationFailedException(accountId); } return balance; } }
AccountInfoRetriever { Balance getBalance(@NonNull String accountId) throws OperationFailedException { Utils.checkNotNull(accountId, "account"); Balance balance = null; try { AccountResponse accountResponse = server.accounts().account(KeyPair.fromAccountId(accountId)); if (accountResponse == null) { throw new OperationFailedException("can't retrieve data for account " + accountId); } for (AccountResponse.Balance assetBalance : accountResponse.getBalances()) { if (assetBalance.getAsset().getType().equalsIgnoreCase("native")) { balance = new BalanceImpl(new BigDecimal(assetBalance.getBalance())); } } } catch (HttpResponseException httpError) { if (httpError.getStatusCode() == 404) { throw new AccountNotFoundException(accountId); } else { throw new OperationFailedException(httpError); } } catch (IOException e) { throw new OperationFailedException(e); } if (balance == null) { throw new OperationFailedException(accountId); } return balance; } AccountInfoRetriever(Server server); }
AccountInfoRetriever { Balance getBalance(@NonNull String accountId) throws OperationFailedException { Utils.checkNotNull(accountId, "account"); Balance balance = null; try { AccountResponse accountResponse = server.accounts().account(KeyPair.fromAccountId(accountId)); if (accountResponse == null) { throw new OperationFailedException("can't retrieve data for account " + accountId); } for (AccountResponse.Balance assetBalance : accountResponse.getBalances()) { if (assetBalance.getAsset().getType().equalsIgnoreCase("native")) { balance = new BalanceImpl(new BigDecimal(assetBalance.getBalance())); } } } catch (HttpResponseException httpError) { if (httpError.getStatusCode() == 404) { throw new AccountNotFoundException(accountId); } else { throw new OperationFailedException(httpError); } } catch (IOException e) { throw new OperationFailedException(e); } if (balance == null) { throw new OperationFailedException(accountId); } return balance; } AccountInfoRetriever(Server server);  }
AccountInfoRetriever { Balance getBalance(@NonNull String accountId) throws OperationFailedException { Utils.checkNotNull(accountId, "account"); Balance balance = null; try { AccountResponse accountResponse = server.accounts().account(KeyPair.fromAccountId(accountId)); if (accountResponse == null) { throw new OperationFailedException("can't retrieve data for account " + accountId); } for (AccountResponse.Balance assetBalance : accountResponse.getBalances()) { if (assetBalance.getAsset().getType().equalsIgnoreCase("native")) { balance = new BalanceImpl(new BigDecimal(assetBalance.getBalance())); } } } catch (HttpResponseException httpError) { if (httpError.getStatusCode() == 404) { throw new AccountNotFoundException(accountId); } else { throw new OperationFailedException(httpError); } } catch (IOException e) { throw new OperationFailedException(e); } if (balance == null) { throw new OperationFailedException(accountId); } return balance; } AccountInfoRetriever(Server server);   }