Search in sources :

Example 71 with CurrencyUnit

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

the class MonetaryAmountFormatSymbolsTest method shouldReturnMonetaryAmountDecimalSymbols.

@Test
public void shouldReturnMonetaryAmountDecimalSymbols() {
    CurrencyUnit dollar = Monetary.getCurrency(Locale.US);
    MonetaryAmountSymbols symbols = new MonetaryAmountSymbols();
    symbols.setCurrency(dollar);
    MonetaryAmountFormatSymbols monetaryFormat = MonetaryAmountFormatSymbols.of(symbols, new MoneyProducer());
    money = Money.of(number, dollar);
    String format = monetaryFormat.format(money);
    MonetaryAmount amount = monetaryFormat.parse(format);
    assertEquals(amount.getCurrency(), dollar);
    assertEquals(amount.getNumber().numberValue(Long.class), number);
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) MonetaryAmount(javax.money.MonetaryAmount) MoneyProducer(org.javamoney.moneta.spi.MoneyProducer) Test(org.testng.annotations.Test)

Example 72 with CurrencyUnit

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

the class ConvertMinorPartQueryTest method shouldReturnWhenTheValueIsBiggerThanLong.

@Test(expectedExceptions = ArithmeticException.class)
public void shouldReturnWhenTheValueIsBiggerThanLong() {
    CurrencyUnit real = Monetary.getCurrency("BRL");
    MonetaryAmount monetaryAmount = Money.of(Long.MAX_VALUE, real);
    query.queryFrom(monetaryAmount.add(Money.of(10, real)));
    fail();
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 73 with CurrencyUnit

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

the class ExtractorMajorPartQueryTest method shouldReturnWhenTheValueIsBiggerThanLong.

@Test(expectedExceptions = ArithmeticException.class)
public void shouldReturnWhenTheValueIsBiggerThanLong() {
    CurrencyUnit real = Monetary.getCurrency("BRL");
    MonetaryAmount monetaryAmount = Money.of(Long.MAX_VALUE, real);
    query.queryFrom(monetaryAmount.add(Money.of(10, real)));
    fail();
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 74 with CurrencyUnit

use of javax.money.CurrencyUnit in project jsr354-ri 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);
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 75 with CurrencyUnit

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

the class ExtractorMajorPartOperatorTest method shouldReturnNegativeValue.

@Test
public void shouldReturnNegativeValue() {
    CurrencyUnit currency = Monetary.getCurrency("BHD");
    MonetaryAmount money = Money.parse("BHD -1.345");
    MonetaryAmount result = operator.apply(money);
    assertEquals(result.getCurrency(), currency);
    assertEquals(result.getNumber().doubleValue(), -1.0);
}
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