@Test public void testUpdateMultiDisabledBank() throws Exception { Bank bank = Mockito.mock(Bank.class); Mockito.when(bank.isDisabled()).thenReturn(true); TestableDataRetrieverTask testMe = new TestableDataRetrieverTask(new Bank[]{bank}); testMe.doInBackground(); Mockito.verify(bank, Mockito.never()).update(); }
@Override protected Void doInBackground(final String... args) { errors = new ArrayList<>(); List<Bank> banks; if (bankId != -1) { banks = new ArrayList<>(); banks.add(getBankFromDb(bankId, parent)); } else { banks = getBanksFromDb(parent); } getDialog().setMax(banks.size()); int i = 0; for (final Bank bank : banks) { publishProgress(i, bank); if (isListingAllBanks() && bank.isDisabled()) { LoggingUtils.logDisabledBank(bank); continue; } try { bank.update(); bank.updateAllTransactions(); bank.closeConnection(); saveBank(bank, parent); i++; LoggingUtils.logBankUpdate(bank, true); } catch (final BankException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); Timber.e(e, "Could not update bank."); } catch (final LoginException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); DBAdapter.disable(bank, parent); } catch (BankChoiceException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); } catch (IOException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); if (NetworkUtils.isInternetAvailable()) { Timber.e(e, "IO error talking to bank"); } } if (isContentProviderEnabled()) { final ArrayList<Account> accounts = bank.getAccounts(); for (final Account account : accounts) { AutoRefreshService.broadcastTransactionUpdate(parent, bank.getDbId(), account.getId()); } } } publishProgress(i, null); return null; }
DataRetrieverTask extends AsyncTask<String, String, Void> { @Override protected Void doInBackground(final String... args) { errors = new ArrayList<>(); List<Bank> banks; if (bankId != -1) { banks = new ArrayList<>(); banks.add(getBankFromDb(bankId, parent)); } else { banks = getBanksFromDb(parent); } getDialog().setMax(banks.size()); int i = 0; for (final Bank bank : banks) { publishProgress(i, bank); if (isListingAllBanks() && bank.isDisabled()) { LoggingUtils.logDisabledBank(bank); continue; } try { bank.update(); bank.updateAllTransactions(); bank.closeConnection(); saveBank(bank, parent); i++; LoggingUtils.logBankUpdate(bank, true); } catch (final BankException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); Timber.e(e, "Could not update bank."); } catch (final LoginException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); DBAdapter.disable(bank, parent); } catch (BankChoiceException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); } catch (IOException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); if (NetworkUtils.isInternetAvailable()) { Timber.e(e, "IO error talking to bank"); } } if (isContentProviderEnabled()) { final ArrayList<Account> accounts = bank.getAccounts(); for (final Account account : accounts) { AutoRefreshService.broadcastTransactionUpdate(parent, bank.getDbId(), account.getId()); } } } publishProgress(i, null); return null; } }
DataRetrieverTask extends AsyncTask<String, String, Void> { @Override protected Void doInBackground(final String... args) { errors = new ArrayList<>(); List<Bank> banks; if (bankId != -1) { banks = new ArrayList<>(); banks.add(getBankFromDb(bankId, parent)); } else { banks = getBanksFromDb(parent); } getDialog().setMax(banks.size()); int i = 0; for (final Bank bank : banks) { publishProgress(i, bank); if (isListingAllBanks() && bank.isDisabled()) { LoggingUtils.logDisabledBank(bank); continue; } try { bank.update(); bank.updateAllTransactions(); bank.closeConnection(); saveBank(bank, parent); i++; LoggingUtils.logBankUpdate(bank, true); } catch (final BankException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); Timber.e(e, "Could not update bank."); } catch (final LoginException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); DBAdapter.disable(bank, parent); } catch (BankChoiceException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); } catch (IOException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); if (NetworkUtils.isInternetAvailable()) { Timber.e(e, "IO error talking to bank"); } } if (isContentProviderEnabled()) { final ArrayList<Account> accounts = bank.getAccounts(); for (final Account account : accounts) { AutoRefreshService.broadcastTransactionUpdate(parent, bank.getDbId(), account.getId()); } } } publishProgress(i, null); return null; } DataRetrieverTask(final MainActivity parent);  DataRetrieverTask(final MainActivity parent, final long bankId); }
DataRetrieverTask extends AsyncTask<String, String, Void> { @Override protected Void doInBackground(final String... args) { errors = new ArrayList<>(); List<Bank> banks; if (bankId != -1) { banks = new ArrayList<>(); banks.add(getBankFromDb(bankId, parent)); } else { banks = getBanksFromDb(parent); } getDialog().setMax(banks.size()); int i = 0; for (final Bank bank : banks) { publishProgress(i, bank); if (isListingAllBanks() && bank.isDisabled()) { LoggingUtils.logDisabledBank(bank); continue; } try { bank.update(); bank.updateAllTransactions(); bank.closeConnection(); saveBank(bank, parent); i++; LoggingUtils.logBankUpdate(bank, true); } catch (final BankException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); Timber.e(e, "Could not update bank."); } catch (final LoginException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); DBAdapter.disable(bank, parent); } catch (BankChoiceException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); } catch (IOException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); if (NetworkUtils.isInternetAvailable()) { Timber.e(e, "IO error talking to bank"); } } if (isContentProviderEnabled()) { final ArrayList<Account> accounts = bank.getAccounts(); for (final Account account : accounts) { AutoRefreshService.broadcastTransactionUpdate(parent, bank.getDbId(), account.getId()); } } } publishProgress(i, null); return null; } DataRetrieverTask(final MainActivity parent);  DataRetrieverTask(final MainActivity parent, final long bankId);  }
DataRetrieverTask extends AsyncTask<String, String, Void> { @Override protected Void doInBackground(final String... args) { errors = new ArrayList<>(); List<Bank> banks; if (bankId != -1) { banks = new ArrayList<>(); banks.add(getBankFromDb(bankId, parent)); } else { banks = getBanksFromDb(parent); } getDialog().setMax(banks.size()); int i = 0; for (final Bank bank : banks) { publishProgress(i, bank); if (isListingAllBanks() && bank.isDisabled()) { LoggingUtils.logDisabledBank(bank); continue; } try { bank.update(); bank.updateAllTransactions(); bank.closeConnection(); saveBank(bank, parent); i++; LoggingUtils.logBankUpdate(bank, true); } catch (final BankException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); Timber.e(e, "Could not update bank."); } catch (final LoginException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); DBAdapter.disable(bank, parent); } catch (BankChoiceException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); } catch (IOException e) { this.errors.add(bank.getName() + " (" + bank.getUsername() + ")"); if (NetworkUtils.isInternetAvailable()) { Timber.e(e, "IO error talking to bank"); } } if (isContentProviderEnabled()) { final ArrayList<Account> accounts = bank.getAccounts(); for (final Account account : accounts) { AutoRefreshService.broadcastTransactionUpdate(parent, bank.getDbId(), account.getId()); } } } publishProgress(i, null); return null; } DataRetrieverTask(final MainActivity parent);  DataRetrieverTask(final MainActivity parent, final long bankId);   }