### Question:
CurrencyList { public void updateWithCurrencies(List<TradeCurrency> currencies, @Nullable CurrencyListItem first) { List<CurrencyListItem> result = Lists.newLinkedList(); Optional.ofNullable(first).ifPresent(result::add); result.addAll(getPartitionedSortedItems(currencies)); delegate.clear(); delegate.addAll(result); } CurrencyList(Preferences preferences);  CurrencyList(List<CurrencyListItem> delegate, Preferences preferences, CurrencyPredicates predicates); ObservableList<CurrencyListItem> getObservableList(); void updateWithCurrencies(List<TradeCurrency> currencies, @Nullable CurrencyListItem first);  }### Answer:
@Test public void testUpdateWhenSortNumerically() { when(preferences.isSortMarketCurrenciesNumerically()).thenReturn(true); List<TradeCurrency> currencies = Lists.newArrayList(USD, RUR, USD, ETH, ETH, BTC); testedEntity.updateWithCurrencies(currencies, null); List<CurrencyListItem> expected = Lists.newArrayList( new CurrencyListItem(USD, 2), new CurrencyListItem(RUR, 1), new CurrencyListItem(ETH, 2), new CurrencyListItem(BTC, 1)); assertEquals(expected, delegate); }
@Test public void testUpdateWhenNotSortNumerically() { when(preferences.isSortMarketCurrenciesNumerically()).thenReturn(false); List<TradeCurrency> currencies = Lists.newArrayList(USD, RUR, USD, ETH, ETH, BTC); testedEntity.updateWithCurrencies(currencies, null); List<CurrencyListItem> expected = Lists.newArrayList( new CurrencyListItem(RUR, 1), new CurrencyListItem(USD, 2), new CurrencyListItem(BTC, 1), new CurrencyListItem(ETH, 2)); assertEquals(expected, delegate); }
@Test public void testUpdateWhenSortNumericallyAndFirstSpecified() { when(preferences.isSortMarketCurrenciesNumerically()).thenReturn(true); List<TradeCurrency> currencies = Lists.newArrayList(USD, RUR, USD, ETH, ETH, BTC); CurrencyListItem first = new CurrencyListItem(BSQ, 5); testedEntity.updateWithCurrencies(currencies, first); List<CurrencyListItem> expected = Lists.newArrayList( first, new CurrencyListItem(USD, 2), new CurrencyListItem(RUR, 1), new CurrencyListItem(ETH, 2), new CurrencyListItem(BTC, 1)); assertEquals(expected, delegate); }