Search in sources :

Example 56 with CurrencyUnit

use of javax.money.CurrencyUnit in project jsr354-ri by JavaMoney.

the class RoudingMonetaryAmountOperatorTest method shouldReturnNegativeValueUsingRoudingType.

@Test
public void shouldReturnNegativeValueUsingRoudingType() {
    operator = new RoudingMonetaryAmountOperator(RoundingMode.HALF_EVEN);
    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);
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 57 with CurrencyUnit

use of javax.money.CurrencyUnit in project jsr354-ri by JavaMoney.

the class RoudingMonetaryAmountOperatorTest method shouldReturnNegativeValueUsingRoudingTypeAndScale.

@Test
public void shouldReturnNegativeValueUsingRoudingTypeAndScale() {
    operator = new RoudingMonetaryAmountOperator(RoundingMode.HALF_EVEN, 4);
    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.3453);
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 58 with CurrencyUnit

use of javax.money.CurrencyUnit in project jsr354-ri by JavaMoney.

the class MonetaryOperatorsTest method shouldRouding.

@Test
public void shouldRouding() {
    CurrencyUnit euro = Monetary.getCurrency("EUR");
    MonetaryAmount money = Money.parse("EUR 2.355432");
    MonetaryAmount result = MonetaryOperators.rounding().apply(money);
    assertNotNull(result);
    assertEquals(result.getCurrency(), euro);
    assertEquals(Double.valueOf(2.36), result.getNumber().doubleValue());
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 59 with CurrencyUnit

use of javax.money.CurrencyUnit in project jsr354-ri by JavaMoney.

the class PercentOperatorTest method shouldReturnPositiveValue.

@Test
public void shouldReturnPositiveValue() {
    CurrencyUnit currency = Monetary.getCurrency("EUR");
    MonetaryAmount money = Money.parse("EUR 200.0");
    MonetaryAmount result = operator.apply(money);
    assertEquals(result.getCurrency(), currency);
    assertEquals(result.getNumber().doubleValue(), 20.0);
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 60 with CurrencyUnit

use of javax.money.CurrencyUnit in project jsr354-ri by JavaMoney.

the class PermilOperatorTest 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(), 0.0235);
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Aggregations

CurrencyUnit (javax.money.CurrencyUnit)116 Test (org.testng.annotations.Test)78 MonetaryAmount (javax.money.MonetaryAmount)57 BigDecimal (java.math.BigDecimal)14 Currency (java.util.Currency)8 MonetaryException (javax.money.MonetaryException)6 ExchangeRate (javax.money.convert.ExchangeRate)6 RoundedMoney (org.javamoney.moneta.RoundedMoney)6 IOException (java.io.IOException)5 MathContext (java.math.MathContext)5 MonetaryParseException (javax.money.format.MonetaryParseException)5 Money (org.javamoney.moneta.Money)4 ExchangeRateBuilder (org.javamoney.moneta.convert.ExchangeRateBuilder)3 DefaultNumberValue (org.javamoney.moneta.spi.DefaultNumberValue)3 Test (org.junit.Test)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 LocalDate (java.time.LocalDate)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2