### Question:
DefaultMonetaryAmountFormat implements MonetaryAmountFormat { @Override public String format(MonetaryAmount amount) { StringBuilder builder = new StringBuilder(); try { print(builder, amount); } catch (IOException e) { throw new IllegalStateException("Error formatting of " + amount, e); } return builder.toString(); } DefaultMonetaryAmountFormat(AmountFormatContext amountFormatContext); @Override String format(MonetaryAmount amount); @Override void print(Appendable appendable, MonetaryAmount amount); @Override MonetaryAmount parse(CharSequence text); @Override String queryFrom(MonetaryAmount amount); @Override AmountFormatContext getContext();  }### Answer:
@Test public void testFormat() { AmountFormatContextBuilder builder = AmountFormatContextBuilder.of(US); AmountFormatContext context = builder.build(); DefaultMonetaryAmountFormat format = new DefaultMonetaryAmountFormat(context); String formatted = format.format(FastMoney.of(1000.42, "USD")); assertEquals(formatted, "USD1,000.42"); }
@Test public void testFormat_with_custom_pattern() { AmountFormatContextBuilder builder = AmountFormatContextBuilder.of(US); builder.set("pattern", "0.00 ¤"); AmountFormatContext context = builder.build(); DefaultMonetaryAmountFormat format = new DefaultMonetaryAmountFormat(context); String formatted = format.format(FastMoney.of(1000.42, "USD")); assertEquals(formatted, "1000.42 USD"); }
@Test public void testFormat_with_two_patterns() { AmountFormatContextBuilder builder = AmountFormatContextBuilder.of(US); builder.set("pattern", "0.00 ¤;0.0 ¤"); AmountFormatContext context = builder.build(); DefaultMonetaryAmountFormat format = new DefaultMonetaryAmountFormat(context); String formatted = format.format(FastMoney.of(1000.42, "USD")); assertEquals(formatted, "1000.42 USD"); formatted = format.format(FastMoney.of(-1000.42, "USD")); assertEquals(formatted, "-1000.4 USD"); }
@Test public void testFormat_with_two_patterns_without_currency() { AmountFormatContextBuilder builder = AmountFormatContextBuilder.of(US); builder.set("pattern", "0.00;0.0"); AmountFormatContext context = builder.build(); DefaultMonetaryAmountFormat format = new DefaultMonetaryAmountFormat(context); String formatted = format.format(FastMoney.of(1000.42, "USD")); assertEquals(formatted, "1000.42"); formatted = format.format(FastMoney.of(-1000.42, "USD")); assertEquals(formatted, "-1000.4"); }