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);
}
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.");
}
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());
}
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));
}
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());
}
Aggregations