Search in sources :

Example 21 with CurrencyUnit

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

the class CurrenciesTest method testGetDifferentCurrencyCodes.

/**
 * Test method for
 * {@link javax.money.Monetary#getCurrency(java.lang.String, String...)}.
 */
@Test
public void testGetDifferentCurrencyCodes() {
    CurrencyUnit cur = Monetary.getCurrency("USD");
    assertEquals("USD", cur.getCurrencyCode());
    cur = Monetary.getCurrency("EUR");
    assertEquals("EUR", cur.getCurrencyCode());
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) Test(org.testng.annotations.Test)

Example 22 with CurrencyUnit

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

the class CurrenciesTest method testGetCurrencyString.

/**
 * Test method for
 * {@link javax.money.Monetary#getCurrency(java.lang.String, String...)} .
 */
@Test
public void testGetCurrencyString() {
    CurrencyUnit cur = Monetary.getCurrency("CHF");
    assertNotNull(cur);
    Currency jdkCurrency = Currency.getInstance("CHF");
    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 23 with CurrencyUnit

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

the class CurrenciesTest method testGetMultipleInstancesString.

/**
 * Test method for
 * {@link javax.money.Monetary#getCurrency(java.lang.String, String...)}.
 * .
 */
@Test
public void testGetMultipleInstancesString() {
    CurrencyUnit cur = Monetary.getCurrency("USD");
    CurrencyUnit cur2 = Monetary.getCurrency("USD");
    assertNotNull(cur2);
    assertTrue(cur == cur2);
    Currency jdkCurrency = Currency.getInstance("USD");
    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 24 with CurrencyUnit

use of javax.money.CurrencyUnit in project jsr354-ri 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 25 with CurrencyUnit

use of javax.money.CurrencyUnit in project jsr354-ri 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)

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