Search in sources :

Example 1 with OpenOfferManager

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

the class OfferBookViewModelTest method testMaxCharactersForAmountRange.

@Test
public void testMaxCharactersForAmountRange() {
    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.maxPlacesForAmount.intValue());
    offerBookListItems.addAll(make(btcItemWithRange.but(with(amount, 2000000000L))));
    assertEquals(16, model.maxPlacesForAmount.intValue());
    offerBookListItems.addAll(make(btcItemWithRange.but(with(minAmount, 30000000000L), with(amount, 30000000000L))));
    assertEquals(19, model.maxPlacesForAmount.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 2 with OpenOfferManager

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

the class OfferBookViewModelTest method testMaxCharactersForVolume.

@Test
public void testMaxCharactersForVolume() {
    OfferBook offerBook = mock(OfferBook.class);
    OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    offerBookListItems.addAll(make(OfferBookListItemMaker.btcItem));
    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(8, model.maxPlacesForVolume.intValue());
    offerBookListItems.addAll(make(btcItem.but(with(amount, 2000000000L))));
    assertEquals(10, 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 3 with OpenOfferManager

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

the class OfferBookViewModelTest method testMaxCharactersForAmount.

@Test
public void testMaxCharactersForAmount() {
    OfferBook offerBook = mock(OfferBook.class);
    OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    offerBookListItems.addAll(make(OfferBookListItemMaker.btcItem));
    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(6, model.maxPlacesForAmount.intValue());
    offerBookListItems.addAll(make(btcItem.but(with(amount, 2000000000L))));
    assertEquals(7, model.maxPlacesForAmount.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 4 with OpenOfferManager

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

the class OfferBookViewModelTest method testMaxCharactersForPriceDistance.

@Test
public void testMaxCharactersForPriceDistance() {
    OfferBook offerBook = mock(OfferBook.class);
    OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
    PriceFeedService priceFeedService = mock(PriceFeedService.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    final Maker<OfferBookListItem> item = btcItem.but(with(useMarketBasedPrice, true));
    when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
    when(priceFeedService.getMarketPrice(anyString())).thenReturn(null);
    when(priceFeedService.updateCounterProperty()).thenReturn(new SimpleIntegerProperty());
    final OfferBookListItem item1 = make(item);
    item1.getOffer().setPriceFeedService(priceFeedService);
    final OfferBookListItem item2 = make(item.but(with(marketPriceMargin, 0.0197)));
    item2.getOffer().setPriceFeedService(priceFeedService);
    final OfferBookListItem item3 = make(item.but(with(marketPriceMargin, 0.1)));
    item3.getOffer().setPriceFeedService(priceFeedService);
    final OfferBookListItem item4 = make(item.but(with(marketPriceMargin, -0.1)));
    item4.getOffer().setPriceFeedService(priceFeedService);
    offerBookListItems.addAll(item1, item2);
    final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, priceFeedService, null, null, null, null, null, new BSFormatter());
    model.activate();
    // " (1.97%)"
    assertEquals(8, model.maxPlacesForMarketPriceMargin.intValue());
    offerBookListItems.addAll(item3);
    // " (10.00%)"
    assertEquals(9, model.maxPlacesForMarketPriceMargin.intValue());
    offerBookListItems.addAll(item4);
    // " (-10.00%)"
    assertEquals(10, model.maxPlacesForMarketPriceMargin.intValue());
}
Also used : OpenOfferManager(bisq.core.offer.OpenOfferManager) PriceFeedService(bisq.core.provider.price.PriceFeedService) BSFormatter(bisq.desktop.util.BSFormatter) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with OpenOfferManager

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

the class OfferBookViewModelTest method testMaxCharactersForPrice.

@Test
public void testMaxCharactersForPrice() {
    OfferBook offerBook = mock(OfferBook.class);
    OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    offerBookListItems.addAll(make(OfferBookListItemMaker.btcItem));
    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(7, model.maxPlacesForPrice.intValue());
    // 14955.8240
    offerBookListItems.addAll(make(btcItem.but(with(price, 149558240L))));
    assertEquals(10, model.maxPlacesForPrice.intValue());
    // 1495.58240
    offerBookListItems.addAll(make(btcItem.but(with(price, 14955824L))));
    assertEquals(10, model.maxPlacesForPrice.intValue());
}
Also used : OpenOfferManager(bisq.core.offer.OpenOfferManager) 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