YahooQuoteToCurrencyExchangeConverter implements Converter<YahooQuote, CurrencyExchange> { @Override public CurrencyExchange convert(YahooQuote yahooQuote) { CurrencyExchange currencyExchange = currencyExchangeRepository.findOne(yahooQuote.getId()); if(currencyExchange == null){ currencyExchange = new CurrencyExchange(); currencyExchange.setId(yahooQuote.getId()); } currencyExchange.setName(yahooQuote.getName()); currencyExchange.setBid(BigDecimal.valueOf(yahooQuote.getBid())); currencyExchange.setAsk(BigDecimal.valueOf(yahooQuote.getAsk())); currencyExchange.setDailyLatestChange(BigDecimal.valueOf(yahooQuote.getLastChange())); currencyExchange.setDailyLatestChangePercent(BigDecimal.valueOf(yahooQuote.getLastChangePercent())); currencyExchange.setDailyLatestValue(BigDecimal.valueOf(yahooQuote.getLast())); currencyExchange.setPreviousClose(BigDecimal.valueOf(yahooQuote.getPreviousClose())); currencyExchange.setOpen(BigDecimal.valueOf(yahooQuote.getOpen())); return currencyExchange; }  @Override CurrencyExchange convert(YahooQuote yahooQuote);  }
@Test public void transferCriticalData(){ when(currencyExchangeRepository.findOne(any(String.class))).thenReturn(new CurrencyExchange(ID_VALUE)); validateResult(converter.convert(buildYahooQuoteInstance())); verify(currencyExchangeRepository, times(1)).findOne(any(String.class)); }
@Test public void producesNewCurrencyExchangeIfNoneFound(){ when(currencyExchangeRepository.findOne(any(String.class))).thenReturn(null); validateResult(converter.convert(buildYahooQuoteInstance())); verify(currencyExchangeRepository, times(1)).findOne(any(String.class)); }