use of bisq.desktop.util.BSFormatter 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));
}
use of bisq.desktop.util.BSFormatter in project bisq-desktop by bisq-network.
the class BtcValidatorTest method testIsValid.
@Test
public void testIsValid() {
BtcValidator validator = new BtcValidator(new BSFormatter());
assertTrue(validator.validate("1").isValid);
assertTrue(validator.validate("0,1").isValid);
assertTrue(validator.validate("0.1").isValid);
assertTrue(validator.validate(",1").isValid);
assertTrue(validator.validate(".1").isValid);
assertTrue(validator.validate("0.12345678").isValid);
// below dust
assertFalse(validator.validate(Coin.SATOSHI.toPlainString()).isValid);
assertFalse(validator.validate(null).isValid);
assertFalse(validator.validate("").isValid);
assertFalse(validator.validate("0").isValid);
assertFalse(validator.validate("0.0").isValid);
assertFalse(validator.validate("0,1,1").isValid);
assertFalse(validator.validate("0.1.1").isValid);
assertFalse(validator.validate("0,000.1").isValid);
assertFalse(validator.validate("0.000,1").isValid);
assertFalse(validator.validate("0.123456789").isValid);
assertFalse(validator.validate("-1").isValid);
// assertFalse(validator.validate(NetworkParameters.MAX_MONEY.toPlainString()).isValid);
}
Aggregations