DefaultCustomerNameFormatterImpl implements CustomerNameFormatter { @Override public String formatName(final Address address) { return formatNameInternal(address, nameTemplate); } DefaultCustomerNameFormatterImpl(final String nameTemplate); @Override String formatName(final Address address); @Override String formatName(final Address address, final String format); @Override String formatName(final Customer customer); @Override String formatName(final Customer customer, final String format);  }
@Test public void testFormatNameFromAddress() throws Exception { final Address address = context.mock(Address.class, "address"); context.checking(new Expectations() {{ allowing(address).getFirstname(); will(returnValue("A")); allowing(address).getMiddlename(); will(returnValue("B")); allowing(address).getLastname(); will(returnValue("C")); allowing(address).getSalutation(); will(returnValue("D")); }}); final DefaultCustomerNameFormatterImpl formatter = new DefaultCustomerNameFormatterImpl("{{firstname}} {{middlename}} {{lastname}}"); assertEquals("A B C", formatter.formatName(address)); assertEquals("A C", formatter.formatName(address, "{{firstname}} {{lastname}}")); assertEquals("A C B", formatter.formatName(address, "{{firstname}} {{lastname}} {{middlename}}")); assertEquals("D C B", formatter.formatName(address, "{{salutation}} {{lastname}} {{middlename}}")); }
@Test public void testFormatNameFromCustomer() throws Exception { final Customer customer = context.mock(Customer.class, "customer"); context.checking(new Expectations() {{ allowing(customer).getFirstname(); will(returnValue("A")); allowing(customer).getMiddlename(); will(returnValue("B")); allowing(customer).getLastname(); will(returnValue("C")); allowing(customer).getSalutation(); will(returnValue("D")); }}); final DefaultCustomerNameFormatterImpl formatter = new DefaultCustomerNameFormatterImpl("{{firstname}} {{middlename}} {{lastname}}"); assertEquals("A B C", formatter.formatName(customer)); assertEquals("A C", formatter.formatName(customer, "{{firstname}} {{lastname}}")); assertEquals("A C B", formatter.formatName(customer, "{{firstname}} {{lastname}} {{middlename}}")); assertEquals("D A C B", formatter.formatName(customer, "{{salutation}} {{firstname}} {{lastname}} {{middlename}}")); }