AccountInfoService { public Collection<K> findAccountsToTrade() { List<Account<K>> accounts = Lists.newArrayList(getAllAccounts()); Collection<K> accountsFound = Lists.newArrayList(); Collections.sort(accounts, accountComparator); for (Account<K> account : accounts) { if (account.getAmountAvailableRatio() >= baseTradingConfig.getMinReserveRatio() && account.getNetAssetValue() >= baseTradingConfig.getMinAmountRequired()) { accountsFound.add(account.getAccountId()); } } return accountsFound; } AccountInfoService(AccountDataProvider<K> accountDataProvider,
			CurrentPriceInfoProvider<N> currentPriceInfoProvider, BaseTradingConfig baseTradingConfig,
			ProviderHelper providerHelper); Collection<Account<K>> getAllAccounts(); Account<K> getAccountInfo(K accountId); Collection<K> findAccountsToTrade(); @SuppressWarnings("unchecked") double calculateMarginForTrade(Account<K> accountInfo, TradeableInstrument<N> instrument, int units); double calculateMarginForTrade(K accountId, TradeableInstrument<N> instrument, int units);  }
@Test public void accountsToTradeTest() { BaseTradingConfig baseTradingConfig = mock(BaseTradingConfig.class); when(baseTradingConfig.getMinReserveRatio()).thenReturn(0.2); when(baseTradingConfig.getMinAmountRequired()).thenReturn(200.00); AccountDataProvider<Long> accountDataProvider = mock(AccountDataProvider.class); AccountInfoService<Long, String> accInfoService = new AccountInfoService<Long, String>(accountDataProvider, null, baseTradingConfig, null); List<Account<Long>> accounts = createAccounts(); when(accountDataProvider.getLatestAccountInfo()).thenReturn(accounts); Collection<Long> eligibleAccounts = accInfoService.findAccountsToTrade(); assertEquals(1, eligibleAccounts.size()); long eligibleAccount = eligibleAccounts.iterator().next(); assertEquals(1001L, eligibleAccount); }