Search in sources :

Example 96 with CurrencyUnit

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

the class BuildableCurrencyUnitTest method testSerialization.

/**
 * Tests that currencies built by {@link CurrencyUnitBuilder} are serializable.
 */
@Test
public void testSerialization() throws ClassNotFoundException, IOException {
    CurrencyUnit currencyUnit = CurrencyUnitBuilder.of("SDR", "serialization-test").setDefaultFractionDigits(3).build(false);
    CurrencyUnit copy = (CurrencyUnit) deserailize(serailize(currencyUnit));
    assertEquals(currencyUnit, copy);
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) Test(org.testng.annotations.Test)

Example 97 with CurrencyUnit

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

the class CurrenciesTest method testToString.

/**
 * Test method for {@link CurrencyUnit#toString()}
 * .
 */
@Test
public void testToString() {
    CurrencyUnit cur1 = Monetary.getCurrency("USD");
    String toString = cur1.toString();
    assertNotNull(toString);
    assertTrue(toString.contains("USD"), "Does not contain currency code.");
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) Test(org.testng.annotations.Test)

Example 98 with CurrencyUnit

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

the class CurrenciesTest method testCurrencyValues.

/**
 * Test method for
 * {@link javax.money.Monetary#getCurrency(java.lang.String, String...)} .
 */
@Test
public void testCurrencyValues() {
    Currency jdkCurrency = Currency.getInstance("CHF");
    CurrencyUnit cur = Monetary.getCurrency("CHF");
    assertNotNull(cur);
    assertEquals(jdkCurrency.getCurrencyCode(), cur.getCurrencyCode());
    assertEquals(jdkCurrency.getNumericCode(), cur.getNumericCode());
    assertEquals(jdkCurrency.getDefaultFractionDigits(), cur.getDefaultFractionDigits());
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) Currency(java.util.Currency) Test(org.testng.annotations.Test)

Example 99 with CurrencyUnit

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

the class CurrenciesTest method testCompareTo.

/**
 * Test Comparable method for
 * {@link javax.money.CurrencyUnit}s.
 */
@Test
public void testCompareTo() {
    CurrencyUnit cur1 = Monetary.getCurrency("USD");
    CurrencyUnit cur2 = Monetary.getCurrency("EUR");
    assertNotNull(cur1);
    assertNotNull(cur2);
    assertTrue(0 < cur1.compareTo(cur2));
    assertTrue(0 > cur2.compareTo(cur1));
    assertEquals(0, cur1.compareTo(cur1));
    assertEquals(0, cur2.compareTo(cur2));
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) Test(org.testng.annotations.Test)

Example 100 with CurrencyUnit

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

the class CurrenciesTest method testGetCurrencyLocale.

/**
 * Test method for
 * {@link javax.money.Monetary#getCurrencies(java.util.Locale, String...)}.
 */
@Test
public void testGetCurrencyLocale() {
    Set<CurrencyUnit> cur = Monetary.getCurrencies(Locale.US);
    assertNotNull(cur);
    assertTrue(cur.size() == 1);
    Currency jdkCurrency = Currency.getInstance(Locale.US);
    CurrencyUnit unit = cur.iterator().next();
    assertEquals(jdkCurrency.getCurrencyCode(), unit.getCurrencyCode());
    assertEquals(jdkCurrency.getNumericCode(), unit.getNumericCode());
    assertEquals(jdkCurrency.getDefaultFractionDigits(), unit.getDefaultFractionDigits());
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) Currency(java.util.Currency) 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