mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 07:07:43 +01:00
Add isRange method
This commit is contained in:
parent
def3970e09
commit
a6ff095234
4 changed files with 49 additions and 24 deletions
|
@ -270,6 +270,10 @@ public class Offer implements NetworkPayload, PersistablePayload {
|
|||
return Coin.valueOf(offerPayload.getMinAmount());
|
||||
}
|
||||
|
||||
public boolean isRange() {
|
||||
return offerPayload.getAmount() != offerPayload.getMinAmount();
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return new Date(offerPayload.getDate());
|
||||
}
|
||||
|
|
36
core/src/test/java/io/bisq/core/offer/OfferTest.java
Normal file
36
core/src/test/java/io/bisq/core/offer/OfferTest.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package io.bisq.core.offer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(OfferPayload.class)
|
||||
public class OfferTest {
|
||||
|
||||
@Test
|
||||
public void testHasNoRange() {
|
||||
OfferPayload payload = mock(OfferPayload.class);
|
||||
when(payload.getMinAmount()).thenReturn(1000L);
|
||||
when(payload.getAmount()).thenReturn(1000L);
|
||||
|
||||
Offer offer = new Offer(payload);
|
||||
assertFalse(offer.isRange());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasRange() {
|
||||
OfferPayload payload = mock(OfferPayload.class);
|
||||
when(payload.getMinAmount()).thenReturn(1000L);
|
||||
when(payload.getAmount()).thenReturn(2000L);
|
||||
|
||||
Offer offer = new Offer(payload);
|
||||
assertTrue(offer.isRange());
|
||||
}
|
||||
}
|
|
@ -303,16 +303,7 @@ public class BSFormatter {
|
|||
}
|
||||
|
||||
public String formatMinVolumeAndVolume(Offer offer) {
|
||||
String volume = "";
|
||||
|
||||
if (offer.getMinVolume() != null) {
|
||||
if (offer.getMinVolume().equals(offer.getVolume())) {
|
||||
volume = formatVolume(offer.getVolume());
|
||||
} else {
|
||||
volume = formatVolume(offer.getMinVolume()) + " - " + formatVolume(offer.getVolume());
|
||||
}
|
||||
}
|
||||
return volume;
|
||||
return offer.isRange() ? formatVolume(offer.getMinVolume()) + " - " + formatVolume(offer.getVolume()) : formatVolume(offer.getVolume());
|
||||
}
|
||||
|
||||
|
||||
|
@ -325,16 +316,7 @@ public class BSFormatter {
|
|||
}
|
||||
|
||||
public String formatAmountWithMinAmount(Offer offer) {
|
||||
String amount = "";
|
||||
|
||||
if (offer.getMinAmount() != null) {
|
||||
if (offer.getMinAmount().equals(offer.getAmount())) {
|
||||
amount = formatCoin(offer.getAmount());
|
||||
} else {
|
||||
amount = formatCoin(offer.getMinAmount()) + " - " + formatCoin(offer.getAmount());
|
||||
}
|
||||
}
|
||||
return amount;
|
||||
return offer.isRange() ? formatCoin(offer.getMinAmount()) + " - " + formatCoin(offer.getAmount()) : formatCoin(offer.getAmount());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ package io.bisq.gui.util;
|
|||
import io.bisq.common.locale.Res;
|
||||
import io.bisq.common.monetary.Volume;
|
||||
import io.bisq.core.offer.Offer;
|
||||
import io.bisq.core.offer.OfferPayload;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -36,7 +37,7 @@ import static org.mockito.Mockito.mock;
|
|||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(Offer.class)
|
||||
@PrepareForTest({Offer.class,OfferPayload.class})
|
||||
public class BSFormatterTest {
|
||||
|
||||
private BSFormatter formatter;
|
||||
|
@ -93,6 +94,7 @@ public class BSFormatterTest {
|
|||
Offer offer = mock(Offer.class);
|
||||
Volume btcMin = Volume.parse("0.10", "BTC");
|
||||
Volume btcMax = Volume.parse("0.25", "BTC");
|
||||
when(offer.isRange()).thenReturn(true);
|
||||
when(offer.getMinVolume()).thenReturn(btcMin);
|
||||
when(offer.getVolume()).thenReturn(btcMax);
|
||||
|
||||
|
@ -119,9 +121,10 @@ public class BSFormatterTest {
|
|||
|
||||
@Test
|
||||
public void testFormatDifferentAmount() {
|
||||
Offer offer = mock(Offer.class);
|
||||
when(offer.getMinAmount()).thenReturn(Coin.valueOf(10000000));
|
||||
when(offer.getAmount()).thenReturn(Coin.valueOf(20000000));
|
||||
OfferPayload offerPayload = mock(OfferPayload.class);
|
||||
Offer offer = new Offer(offerPayload);
|
||||
when(offerPayload.getMinAmount()).thenReturn(10000000L);
|
||||
when(offerPayload.getAmount()).thenReturn(20000000L);
|
||||
|
||||
assertEquals("0.10 - 0.20", formatter.formatAmountWithMinAmount(offer));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue