@Test public void pipetteValueIsOnePipetteMultipliedByExchangeRateOfQuoteToAccountCurrencyWhenSymbolDoesNotContainAccountCurrency() { when(exchangeRateStore.getExchangeRate(Currency.getInstance("AUD"), Currency.getInstance("CAD"))).thenReturn(Optional.of(new AccuratePrice(1.8))); assertThat(cut.calculatePipetteValue(currency("CAD"), new ForexSymbol("EURAUD"), new Price(1.2))).isEqualTo(new AccuratePrice(0.000018), ALLOWED_OFFSET); when(exchangeRateStore.getExchangeRate(Currency.getInstance("USD"), Currency.getInstance("CHF"))).thenReturn(Optional.of(new AccuratePrice(1.358))); assertThat(cut.calculatePipetteValue(currency("CHF"), new ForexSymbol("GBPUSD"), new Price(1.9))).isEqualTo(new AccuratePrice(0.00001358), ALLOWED_OFFSET); }
public AccuratePrice calculatePipetteValue(final Currency accountCurrency, final ForexSymbol tradedSymbol, final Price tradeSymbolPrice) { if (accountCurrency.equals(tradedSymbol.getBaseCurrency())) { return new AccuratePrice(0.00001 / tradeSymbolPrice.asDouble()); } else if (accountCurrency.equals(tradedSymbol.getQuoteCurrency())) { return PIPETTE; } final Optional<AccuratePrice> exchangeRate = exchangeRateStore.getExchangeRate(tradedSymbol.getQuoteCurrency(), accountCurrency); return exchangeRate.map(rate -> new AccuratePrice(0.00001 * exchangeRate.get().asRawValue())) .orElseThrow(() -> createIlegalArgumentsException(accountCurrency, tradedSymbol)); }
PipetteValueCalculator { public AccuratePrice calculatePipetteValue(final Currency accountCurrency, final ForexSymbol tradedSymbol, final Price tradeSymbolPrice) { if (accountCurrency.equals(tradedSymbol.getBaseCurrency())) { return new AccuratePrice(0.00001 / tradeSymbolPrice.asDouble()); } else if (accountCurrency.equals(tradedSymbol.getQuoteCurrency())) { return PIPETTE; } final Optional<AccuratePrice> exchangeRate = exchangeRateStore.getExchangeRate(tradedSymbol.getQuoteCurrency(), accountCurrency); return exchangeRate.map(rate -> new AccuratePrice(0.00001 * exchangeRate.get().asRawValue())) .orElseThrow(() -> createIlegalArgumentsException(accountCurrency, tradedSymbol)); } }
PipetteValueCalculator { public AccuratePrice calculatePipetteValue(final Currency accountCurrency, final ForexSymbol tradedSymbol, final Price tradeSymbolPrice) { if (accountCurrency.equals(tradedSymbol.getBaseCurrency())) { return new AccuratePrice(0.00001 / tradeSymbolPrice.asDouble()); } else if (accountCurrency.equals(tradedSymbol.getQuoteCurrency())) { return PIPETTE; } final Optional<AccuratePrice> exchangeRate = exchangeRateStore.getExchangeRate(tradedSymbol.getQuoteCurrency(), accountCurrency); return exchangeRate.map(rate -> new AccuratePrice(0.00001 * exchangeRate.get().asRawValue())) .orElseThrow(() -> createIlegalArgumentsException(accountCurrency, tradedSymbol)); } PipetteValueCalculator(final ExchangeRateStore exchangeRateStore); }
PipetteValueCalculator { public AccuratePrice calculatePipetteValue(final Currency accountCurrency, final ForexSymbol tradedSymbol, final Price tradeSymbolPrice) { if (accountCurrency.equals(tradedSymbol.getBaseCurrency())) { return new AccuratePrice(0.00001 / tradeSymbolPrice.asDouble()); } else if (accountCurrency.equals(tradedSymbol.getQuoteCurrency())) { return PIPETTE; } final Optional<AccuratePrice> exchangeRate = exchangeRateStore.getExchangeRate(tradedSymbol.getQuoteCurrency(), accountCurrency); return exchangeRate.map(rate -> new AccuratePrice(0.00001 * exchangeRate.get().asRawValue())) .orElseThrow(() -> createIlegalArgumentsException(accountCurrency, tradedSymbol)); } PipetteValueCalculator(final ExchangeRateStore exchangeRateStore); AccuratePrice calculatePipetteValue(final Currency accountCurrency, final ForexSymbol tradedSymbol,
            final Price tradeSymbolPrice); }
PipetteValueCalculator { public AccuratePrice calculatePipetteValue(final Currency accountCurrency, final ForexSymbol tradedSymbol, final Price tradeSymbolPrice) { if (accountCurrency.equals(tradedSymbol.getBaseCurrency())) { return new AccuratePrice(0.00001 / tradeSymbolPrice.asDouble()); } else if (accountCurrency.equals(tradedSymbol.getQuoteCurrency())) { return PIPETTE; } final Optional<AccuratePrice> exchangeRate = exchangeRateStore.getExchangeRate(tradedSymbol.getQuoteCurrency(), accountCurrency); return exchangeRate.map(rate -> new AccuratePrice(0.00001 * exchangeRate.get().asRawValue())) .orElseThrow(() -> createIlegalArgumentsException(accountCurrency, tradedSymbol)); } PipetteValueCalculator(final ExchangeRateStore exchangeRateStore); AccuratePrice calculatePipetteValue(final Currency accountCurrency, final ForexSymbol tradedSymbol,
            final Price tradeSymbolPrice);  }