use of javax.money.CurrencyUnit in project jsr354-ri-bp by JavaMoney.
the class RoudingMonetaryAmountOperatorTest method shouldReturnNegativeValue.
@Test
public void shouldReturnNegativeValue() {
CurrencyUnit currency = Monetary.getCurrency("BHD");
MonetaryAmount money = Money.parse("BHD -1.34534432");
MonetaryAmount result = operator.apply(money);
assertEquals(result.getCurrency(), currency);
assertEquals(result.getNumber().doubleValue(), -1.345);
}
use of javax.money.CurrencyUnit in project jsr354-ri-bp by JavaMoney.
the class RoudingMonetaryAmountOperatorTest method shouldReturnPositiveValueUsingRoudingType.
@Test
public void shouldReturnPositiveValueUsingRoudingType() {
operator = new RoudingMonetaryAmountOperator(RoundingMode.HALF_EVEN);
CurrencyUnit currency = Monetary.getCurrency("EUR");
MonetaryAmount money = Money.parse("EUR 2.3523");
MonetaryAmount result = operator.apply(money);
assertEquals(result.getCurrency(), currency);
assertEquals(result.getNumber().doubleValue(), 2.35);
}
use of javax.money.CurrencyUnit in project jsr354-ri-bp by JavaMoney.
the class ScaleRoundedOperatorTest method shouldRoundedMonetaryOperatorWhenTheImplementationIsMoney.
@Test
public void shouldRoundedMonetaryOperatorWhenTheImplementationIsMoney() {
int scale = 4;
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = Money.of(BigDecimal.valueOf(35.34567), real);
ScaleRoundedOperator monetaryOperator = ScaleRoundedOperator.of(scale, RoundingMode.HALF_EVEN);
MonetaryAmount result = monetaryOperator.apply(money);
assertTrue(RoundedMoney.class.isInstance(result));
assertEquals(result.getCurrency(), real);
assertEquals(result.getNumber().getScale(), scale);
assertEquals(BigDecimal.valueOf(35.3457), result.getNumber().numberValue(BigDecimal.class));
}
use of javax.money.CurrencyUnit in project jsr354-ri-bp by JavaMoney.
the class TestCurrency method of.
public static CurrencyUnit of(Currency currency) {
String key = ISO_NAMESPACE + ':' + currency.getCurrencyCode();
CurrencyUnit cachedItem = CACHED.get(key);
if (cachedItem == null) {
cachedItem = new JDKCurrencyAdapter(currency);
CACHED.put(key, cachedItem);
}
return cachedItem;
}
use of javax.money.CurrencyUnit in project jsr354-ri-bp by JavaMoney.
the class ExtractorMajorPartOperatorTest method shouldReturnPositiveValue.
@Test
public void shouldReturnPositiveValue() {
CurrencyUnit currency = Monetary.getCurrency("EUR");
MonetaryAmount money = Money.parse("EUR 2.35");
MonetaryAmount result = operator.apply(money);
assertEquals(result.getCurrency(), currency);
assertEquals(result.getNumber().doubleValue(), 2.0);
}
Aggregations