mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-13 10:45:51 +00:00
Make sure exchange rates are well defined.
This commit is contained in:
parent
81f2303434
commit
cc0a00fbdd
@ -33,14 +33,16 @@ public class ExchangeRate implements Serializable {
|
|||||||
|
|
||||||
/** Construct exchange rate. This amount of coin is worth that amount of fiat. */
|
/** Construct exchange rate. This amount of coin is worth that amount of fiat. */
|
||||||
public ExchangeRate(Coin coin, Fiat fiat) {
|
public ExchangeRate(Coin coin, Fiat fiat) {
|
||||||
|
checkArgument(coin.isPositive());
|
||||||
|
checkArgument(fiat.isPositive());
|
||||||
|
checkArgument(fiat.currencyCode != null, "currency code required");
|
||||||
this.coin = coin;
|
this.coin = coin;
|
||||||
this.fiat = fiat;
|
this.fiat = fiat;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Construct exchange rate. One coin is worth this amount of fiat. */
|
/** Construct exchange rate. One coin is worth this amount of fiat. */
|
||||||
public ExchangeRate(Fiat fiat) {
|
public ExchangeRate(Fiat fiat) {
|
||||||
this.coin = Coin.COIN;
|
this(Coin.COIN, fiat);
|
||||||
this.fiat = fiat;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,4 +74,19 @@ public class ExchangeRateTest {
|
|||||||
ExchangeRate rate = new ExchangeRate(Fiat.parseFiat("XXX", "1000000000"));
|
ExchangeRate rate = new ExchangeRate(Fiat.parseFiat("XXX", "1000000000"));
|
||||||
rate.coinToFiat(Coin.parseCoin("-1000000"));
|
rate.coinToFiat(Coin.parseCoin("-1000000"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void constructMissingCurrencyCode() {
|
||||||
|
new ExchangeRate(Fiat.valueOf(null, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void constructNegativeCoin() {
|
||||||
|
new ExchangeRate(Coin.valueOf(-1), Fiat.valueOf("EUR", 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void constructFiatCoin() {
|
||||||
|
new ExchangeRate(Fiat.valueOf("EUR", -1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user