@Override public BillingStateFormatter createBillingStateFormatter(final BillingState billingState) { return new DefaultBillingStateFormatter(billingState); } }
@Override public String getFormattedBalanceOfUnpaidInvoices() { return round(Objects.firstNonNull(getBalanceOfUnpaidInvoices(), BigDecimal.ZERO)).toString(); } }
public String generateEmail(final Account account, final BillingState billingState, final Account overdueable, final OverdueState nextOverdueState) throws IOException { final Map<String, Object> data = new HashMap<String, Object>(); // TODO raw objects for now. We eventually should respect the account locale and support translations data.put("account", account); data.put("billingState", overdueEmailFormatterFactory.createBillingStateFormatter(billingState)); data.put("overdueable", overdueable); data.put("nextOverdueState", nextOverdueState); // TODO single template for all languages for now return templateEngine.executeTemplate(nextOverdueState.getEnterStateEmailNotification().getTemplateName(), data); } }
@Test(groups = "fast") public void testBalanceFormatting() throws Exception { final BillingState billingState = new BillingState(UUID.randomUUID(), 2, BigDecimal.TEN, new LocalDate(), DateTimeZone.UTC, UUID.randomUUID(), null, null); final DefaultBillingStateFormatter formatter = new DefaultBillingStateFormatter(billingState); Assert.assertEquals(formatter.getFormattedBalanceOfUnpaidInvoices(), "10.00"); } }