test_class.declarator: BRE = "BRE"
test_class.modifier: private static final
test_class.original_string: private static final String BRE = "BRE";
test_class.type: String
test_class.var_name: BRE
test_class.declarator: latestRepo
test_class.modifier: @Autowired
  	private
test_class.original_string: @Autowired
  	private LatestRateRepository latestRepo;
test_class.type: LatestRateRepository
test_class.var_name: latestRepo
test_class.declarator: rateUpdaterService
test_class.modifier: @Autowired
  	private
test_class.original_string: @Autowired
  	private RateUpdaterService rateUpdaterService;
test_class.type: RateUpdaterService
test_class.var_name: rateUpdaterService
test_class.declarator: histoRepo
test_class.modifier: @Autowired
  	private
test_class.original_string: @Autowired
  	private HistoricalRateRepository histoRepo;
test_class.type: HistoricalRateRepository
test_class.var_name: histoRepo
test_class.declarator: activeMQConfig
test_class.modifier: @MockBean
  	private
test_class.original_string: @MockBean
  	private ActiveMQConfig activeMQConfig;
test_class.type: ActiveMQConfig
test_class.var_name: activeMQConfig
test_class.file: trading-data-collect/src/test/java/fr/ymanvieu/trading/datacollect/rate/RateUpdaterServiceTest.java
test_class.identifier: RateUpdaterServiceTest
test_case.body: @Test
  	public void testUpdateRates() {
  		// given
  		List<Quote> quotes = getBrentQuotes();
  
  		HistoricalRate expected1 = new HistoricalRate(BRE, USD, new BigDecimal("55.18"), parse("2015-04-02T02:00:00"));
  		HistoricalRate expected2 = new HistoricalRate(BRE, USD, new BigDecimal("56.72"), parse("2015-04-03T02:00:00"));
  		HistoricalRate expected3 = new HistoricalRate(BRE, USD, new BigDecimal("55.18"), parse("2015-04-07T02:00:00"));
  		HistoricalRate expected4 = new HistoricalRate(BRE, USD, new BigDecimal("57.8"), parse("2015-04-08T02:00:00"));
  		HistoricalRate expected5 = new HistoricalRate(BRE, USD, new BigDecimal("58.3"), parse("2015-04-09T02:00:00"));
  		LatestRate expected6 = new LatestRate(BRE, USD, new BigDecimal("58.3"), parse("2015-04-09T02:00:00"));
  
  		// when
  		rateUpdaterService.updateRates(quotes);
  
  		// then
  		List<HistoricalRate> hRates = new ArrayList<>(histoRepo.findAll());
  		List<LatestRate> lRates = new ArrayList<>(latestRepo.findAll());
  
  		assertThat(hRates).containsExactlyInAnyOrder(expected1, expected2, expected3, expected4, expected5);
  
  		assertThat(lRates).containsExactly(expected6);
  
  		verify(activeMQConfig).send(any());
  	}
test_case.class_method_signature: RateUpdaterServiceTest.testUpdateRates()
test_case.full_signature: @Test public void testUpdateRates()
test_case.identifier: testUpdateRates
test_case.invocations: getBrentQuotes parse parse parse parse parse parse updateRates findAll findAll containsExactlyInAnyOrder assertThat containsExactly assertThat send verify any
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testUpdateRates()
focal_class.declarator: latestRepo
focal_class.modifier: @Autowired
  	private
focal_class.original_string: @Autowired
  	private LatestRateRepository latestRepo;
focal_class.type: LatestRateRepository
focal_class.var_name: latestRepo
focal_class.declarator: symbolRepo
focal_class.modifier: @Autowired
  	private
focal_class.original_string: @Autowired
  	private SymbolRepository symbolRepo;
focal_class.type: SymbolRepository
focal_class.var_name: symbolRepo
focal_class.declarator: rateService
focal_class.modifier: @Autowired
  	private
focal_class.original_string: @Autowired
  	private RateService rateService;
focal_class.type: RateService
focal_class.var_name: rateService
focal_class.declarator: bus
focal_class.modifier: @Autowired
  	private
focal_class.original_string: @Autowired
  	private ApplicationEventPublisher bus;
focal_class.type: ApplicationEventPublisher
focal_class.var_name: bus
focal_class.declarator: rateMapper
focal_class.modifier: @Autowired
  	private
focal_class.original_string: @Autowired
  	private RateMapper rateMapper;
focal_class.type: RateMapper
focal_class.var_name: rateMapper
focal_class.file: trading-data-collect/src/main/java/fr/ymanvieu/trading/datacollect/rate/RateUpdaterService.java
focal_class.identifier: RateUpdaterService
focal_class.class_method_signature: RateUpdaterService.updateRates(List<Quote> quotes)
focal_class.full_signature: @Transactional public void updateRates(List<Quote> quotes)
focal_class.identifier: updateRates
focal_class.modifiers: @Transactional public
focal_class.parameters: (List<Quote> quotes)
focal_class.return: void
focal_class.signature: void updateRates(List<Quote> quotes)
focal_class.class_method_signature: RateUpdaterService.getFromList(List<LatestRate> ratesList, Quote q)
focal_class.full_signature: private LatestRate getFromList(List<LatestRate> ratesList, Quote q)
focal_class.identifier: getFromList
focal_class.modifiers: private
focal_class.parameters: (List<LatestRate> ratesList, Quote q)
focal_class.return: LatestRate
focal_class.signature: LatestRate getFromList(List<LatestRate> ratesList, Quote q)
focal_class.class_method_signature: RateUpdaterService.getFromList(List<SymbolEntity> symbols, String code)
focal_class.full_signature: private SymbolEntity getFromList(List<SymbolEntity> symbols, String code)
focal_class.identifier: getFromList
focal_class.modifiers: private
focal_class.parameters: (List<SymbolEntity> symbols, String code)
focal_class.return: SymbolEntity
focal_class.signature: SymbolEntity getFromList(List<SymbolEntity> symbols, String code)
focal_method.body: @Transactional
  	public void updateRates(List<Quote> quotes) {
  
  		List<Quote> quotesList = new ArrayList<>(quotes);
  
  		Collections.sort(quotesList, (o1, o2) -> o1.getTime().compareTo(o2.getTime()));
  
  		List<LatestRate> existingLatestRates = latestRepo.findAll();
  
  		List<LatestRate> newLatestRates = new ArrayList<>();
  		List<Quote> newHistoricalRates = new ArrayList<>();
  
  		List<SymbolEntity> symbols = symbolRepo.findAll();
  
  		for (Quote quote : quotesList) {
  			LatestRate existingLatestRate = getFromList(existingLatestRates, quote);
  
  			if (existingLatestRate == null) {
  
  				SymbolEntity fromcur = getFromList(symbols, quote.getCode());
  				
  				if(fromcur == null) {
  					log.warn("Cannot find symbol '{}' in DB, skipping it.", quote.getCode());
  					continue;
  				}
  
  				SymbolEntity tocur = getFromList(symbols, quote.getCurrency());
  
  				if(tocur == null) {
  					log.warn("Cannot find symbol '{}' in DB, skipping it.", quote.getCurrency());
  					continue;
  				}
  				
  				LatestRate newLatestRate = new LatestRate(fromcur, tocur, quote.getPrice(), quote.getTime());
  
  				newLatestRates.add(newLatestRate);
  				existingLatestRates.add(newLatestRate);
  
  			} else if (quote.getTime().isAfter(existingLatestRate.getDate())) {
  				existingLatestRate.setDate(quote.getTime());
  				existingLatestRate.setValue(quote.getPrice());
  
  				if (!newLatestRates.contains(existingLatestRate)) {
  					newLatestRates.add(existingLatestRate);
  				}
  			}
  			
  			newHistoricalRates.add(quote);
  		}
  
  		latestRepo.saveAll(newLatestRates);
  
  		rateService.addHistoricalRates(newHistoricalRates);
  
  		if (!newLatestRates.isEmpty()) {
  			bus.publishEvent(new RatesUpdatedEvent().setRates(rateMapper.mapToRates(newLatestRates)));
  		}
  	}
focal_method.class_method_signature: RateUpdaterService.updateRates(List<Quote> quotes)
focal_method.full_signature: @Transactional public void updateRates(List<Quote> quotes)
focal_method.identifier: updateRates
focal_method.invocations: sort compareTo getTime getTime findAll findAll getFromList getFromList getCode warn getCode getFromList getCurrency warn getCurrency getPrice getTime add add isAfter getTime getDate setDate getTime setValue getPrice contains add add saveAll addHistoricalRates isEmpty publishEvent setRates mapToRates
focal_method.modifiers: @Transactional public
focal_method.parameters: (List<Quote> quotes)
focal_method.return: void
focal_method.signature: void updateRates(List<Quote> quotes)