Search in sources :

Example 6 with OpenOfferManager

use of bisq.core.offer.OpenOfferManager in project bisq-desktop by bisq-network.

the class OfferBookViewModelTest method testMaxCharactersForVolumeRange.

@Test
public void testMaxCharactersForVolumeRange() {
    OfferBook offerBook = mock(OfferBook.class);
    OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    offerBookListItems.addAll(make(OfferBookListItemMaker.btcItemWithRange));
    when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
    final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, null, null, null, null, new BSFormatter());
    model.activate();
    assertEquals(15, model.maxPlacesForVolume.intValue());
    offerBookListItems.addAll(make(btcItemWithRange.but(with(amount, 2000000000L))));
    assertEquals(17, model.maxPlacesForVolume.intValue());
    offerBookListItems.addAll(make(btcItemWithRange.but(with(minAmount, 30000000000L), with(amount, 30000000000L))));
    assertEquals(25, model.maxPlacesForVolume.intValue());
}
Also used : OpenOfferManager(bisq.core.offer.OpenOfferManager) BSFormatter(bisq.desktop.util.BSFormatter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with OpenOfferManager

use of bisq.core.offer.OpenOfferManager in project bisq-desktop by bisq-network.

the class OfferBookViewModelTest method testGetPrice.

@Test
public void testGetPrice() {
    OfferBook offerBook = mock(OfferBook.class);
    OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
    PriceFeedService priceFeedService = mock(PriceFeedService.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
    when(priceFeedService.getMarketPrice(anyString())).thenReturn(new MarketPrice("USD", 12684.0450, Instant.now().getEpochSecond(), true));
    final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, null, null, null, null, new BSFormatter());
    final OfferBookListItem item = make(btcItem.but(with(useMarketBasedPrice, true), with(marketPriceMargin, -0.12)));
    final OfferBookListItem lowItem = make(btcItem.but(with(useMarketBasedPrice, true), with(marketPriceMargin, 0.01)));
    final OfferBookListItem fixedItem = make(btcItem);
    item.getOffer().setPriceFeedService(priceFeedService);
    lowItem.getOffer().setPriceFeedService(priceFeedService);
    offerBookListItems.addAll(lowItem, fixedItem);
    model.activate();
    assertEquals("12557.2046 (1.00%)", model.getPrice(lowItem));
    assertEquals("   10.0000        ", model.getPrice(fixedItem));
    offerBookListItems.addAll(item);
    assertEquals("14206.1304 (-12.00%)", model.getPrice(item));
    assertEquals("12557.2046   (1.00%)", model.getPrice(lowItem));
}
Also used : OpenOfferManager(bisq.core.offer.OpenOfferManager) MarketPrice(bisq.core.provider.price.MarketPrice) PriceFeedService(bisq.core.provider.price.PriceFeedService) BSFormatter(bisq.desktop.util.BSFormatter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

OpenOfferManager (bisq.core.offer.OpenOfferManager)7 BSFormatter (bisq.desktop.util.BSFormatter)7 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 PriceFeedService (bisq.core.provider.price.PriceFeedService)2 MarketPrice (bisq.core.provider.price.MarketPrice)1 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)1