Search in sources :

Example 6 with MonetaryAmountFormat

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

the class ToStringMonetaryAmountFormatTest method testBulgarianLev.

/**
 * Test related to {@see https://java.net/jira/browse/JAVAMONEY-151}.
 */
@Test
public void testBulgarianLev() {
    MonetaryAmount money = Money.of(1123000.50, "BGN");
    Locale locale = new Locale("", "BG");
    MonetaryAmountFormat format = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder.of(locale).set(CurrencyStyle.SYMBOL).build());
    assertEquals(format.format(money), "1 123 000,50 лв");
    format = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder.of(locale).set(CurrencyStyle.CODE).build());
    assertEquals(format.format(money), "1 123 000,50 BGN");
}
Also used : Locale(java.util.Locale) MonetaryAmount(javax.money.MonetaryAmount) MonetaryAmountFormat(javax.money.format.MonetaryAmountFormat) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 7 with MonetaryAmountFormat

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

the class MonetaryAmountFormatTest method testBulgarianLev.

/**
 * Test related to {@link https://java.net/jira/browse/JAVAMONEY-151}.
 */
@Test
public void testBulgarianLev() {
    MonetaryAmount money = Money.of(1123000.50, "BGN");
    Locale locale = new Locale("", "BG");
    MonetaryAmountFormat format = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder.of(locale).set(CurrencyStyle.SYMBOL).build());
    assertEquals(format.format(money), "1 123 000,50 лв");
    format = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder.of(locale).set(CurrencyStyle.CODE).build());
    assertEquals(format.format(money), "1 123 000,50 BGN");
}
Also used : Locale(java.util.Locale) MonetaryAmount(javax.money.MonetaryAmount) MonetaryAmountFormat(javax.money.format.MonetaryAmountFormat) Test(org.testng.annotations.Test)

Example 8 with MonetaryAmountFormat

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

the class MonetaryAmountFormatTest method testPrint.

/**
 * Test method for
 * {@link javax.money.format.MonetaryAmountFormat#print(java.lang.Appendable, javax.money.MonetaryAmount)}
 * .
 *
 * @throws IOException
 */
@Test
public void testPrint() throws IOException {
    StringBuilder b = new StringBuilder();
    MonetaryAmountFormat defaultFormat = MonetaryFormats.getAmountFormat(Locale.GERMANY);
    defaultFormat.print(b, Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(12.50).create());
    assertEquals("12,50 CHF", b.toString());
    b.setLength(0);
    defaultFormat.print(b, Monetary.getDefaultAmountFactory().setCurrency("INR").setNumber(123456789101112.123456).create());
    assertEquals("123.456.789.101.112,12 INR", b.toString());
    b.setLength(0);
    defaultFormat = MonetaryFormats.getAmountFormat(new Locale("", "IN"));
    defaultFormat.print(b, Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(1211112.50).create());
    assertEquals("CHF 1,211,112.50", b.toString());
    b.setLength(0);
    defaultFormat.print(b, Monetary.getDefaultAmountFactory().setCurrency("INR").setNumber(123456789101112.123456).create());
    assertEquals("INR 123,456,789,101,112.12", b.toString());
    b.setLength(0);
// Locale india = new Locale("", "IN");
// defaultFormat = MonetaryFormats.getAmountFormat(india)
// .setNumberGroupSizes(3, 2).of();
// defaultFormat.print(b, Monetary.getAmount("INR",
// 123456789101112.123456));
// assertEquals("INR 12,34,56,78,91,01,112.12",
// b.toString());
}
Also used : Locale(java.util.Locale) MonetaryAmountFormat(javax.money.format.MonetaryAmountFormat) Test(org.testng.annotations.Test)

Example 9 with MonetaryAmountFormat

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

the class MonetaryAmountFormatTest method testWithCustomPattern.

/**
 * Test related to {@link https://java.net/jira/browse/JAVAMONEY-92}.
 */
@Test
public void testWithCustomPattern() {
    MonetaryAmountFormat format = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder.of(Locale.GERMANY).set(CurrencyStyle.SYMBOL).set("pattern", "#,##0.00### ¤").build());
    Money money = Money.of(12345.23456789, "EUR");
    assertEquals("12.345,23457 €", format.format(money));
    format = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder.of(Locale.GERMANY).set(CurrencyStyle.SYMBOL).build());
    assertEquals("12.345,23 €", format.format(money));
}
Also used : Money(org.javamoney.moneta.Money) MonetaryAmountFormat(javax.money.format.MonetaryAmountFormat) Test(org.testng.annotations.Test)

Example 10 with MonetaryAmountFormat

use of javax.money.format.MonetaryAmountFormat in project tutorials by eugenp.

the class JavaMoneyUnitManualTest method givenLocale_whenFormatted_thanEquals.

@Test
public void givenLocale_whenFormatted_thanEquals() {
    MonetaryAmount oneDollar = Monetary.getDefaultAmountFactory().setCurrency("USD").setNumber(1).create();
    MonetaryAmountFormat formatUSD = MonetaryFormats.getAmountFormat(Locale.US);
    String usFormatted = formatUSD.format(oneDollar);
    assertEquals("USD 1", oneDollar.toString());
    assertNotNull(formatUSD);
    assertEquals("USD1.00", usFormatted);
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) MonetaryAmountFormat(javax.money.format.MonetaryAmountFormat) Test(org.junit.Test)

Aggregations

MonetaryAmountFormat (javax.money.format.MonetaryAmountFormat)10 Test (org.testng.annotations.Test)8 Locale (java.util.Locale)4 MonetaryAmount (javax.money.MonetaryAmount)4 Test (org.junit.Test)2 BigDecimal (java.math.BigDecimal)1 Money (org.javamoney.moneta.Money)1 BeforeTest (org.testng.annotations.BeforeTest)1