YahooQuoteToIndexConverter implements Converter<YahooQuote, Index> { @Override public Index convert(YahooQuote yahooQuote) { Index index = indexRepository.findOne(yahooQuote.getId()); if(index == null){ index = new Index(); index.setId(yahooQuote.getId()); } index.setName(yahooQuote.getName()); index.setOpen(BigDecimal.valueOf(yahooQuote.getOpen())); index.setHigh(BigDecimal.valueOf(yahooQuote.getHigh())); index.setLow(BigDecimal.valueOf(yahooQuote.getLow())); index.setDailyLatestChange(BigDecimal.valueOf(yahooQuote.getLastChange())); index.setDailyLatestChangePercent(BigDecimal.valueOf(yahooQuote.getLastChangePercent())); index.setDailyLatestValue(BigDecimal.valueOf(yahooQuote.getLast())); index.setPreviousClose(BigDecimal.valueOf(yahooQuote.getPreviousClose())); index.setComponents(Sets.newHashSet()); if(!StringUtils.isEmpty(yahooQuote.getExchange())){ index.setExchange(exchangeService.get(yahooQuote.getExchange())); } return index; }  @Override Index convert(YahooQuote yahooQuote);  }
@Test public void essentialDataTransfered(){ when(IndexRepository.findOne(any(String.class))).thenReturn(new Index(ID_VALUE)); when(exchangeService.get(EXCHANGE_VALUE)).thenReturn(new Exchange(EXCHANGE_VALUE)); validateResult(converter.convert(buildYahooQuoteInstance())); verify(IndexRepository, times(1)).findOne(any(String.class)); verify(exchangeService, times(1)).get(any(String.class)); }
@Test public void producesNewIndexIfNoneFound(){ when(IndexRepository.findOne(any(String.class))).thenReturn(null); when(exchangeService.get(EXCHANGE_VALUE)).thenReturn(new Exchange(EXCHANGE_VALUE)); validateResult(converter.convert(buildYahooQuoteInstance())); verify(IndexRepository, times(1)).findOne(any(String.class)); verify(exchangeService, times(1)).get(any(String.class)); }