/******************************************************************************************************************* * * Creates a {@link PresentationModel} for a {@link Customer} injecting a {@link Selectable} role which fires a * {@link CustomerSelectedEvent} on selection. * * @param customer the {@code Customer} * @return the {@code PresentationModel} * ******************************************************************************************************************/ @Nonnull @VisibleForTesting PresentationModel createPresentationModelFor (final @Nonnull Customer customer) { final Selectable publishEventOnSelection = () -> messageBus.publish(new CustomerSelectedEvent(customer)); return customer.as(Presentable).createPresentationModel(publishEventOnSelection); } }
/******************************************************************************************************************* * * Reacts to the notification that a {@link Customer} has been selected by populating the presentation with * his projects. * * @param event the notification event * ******************************************************************************************************************/ @VisibleForTesting void onCustomerSelectedEvent (final @Nonnull @ListensTo CustomerSelectedEvent event) { log.info("onCustomerSelectedEvent({})", event); presentation.populate(event.getCustomer().findProjects() .stream() .map(project -> (ProjectSpi)project) .sorted(comparing(ProjectSpi::getName)) .map(project -> createPresentationModelFor(project)) .collect(toCompositePresentationModel())); }
public CustomerXml (final @Nonnull Customer customer) { final Customer.Builder builder = customer.toBuilder(); this.id = builder.getId(); this.name = builder.getName(); this.billingAddressXml = new AddressXml(builder.getBillingAddress()); this.vatNumber = builder.getVatNumber(); }
@Test public void toString_must_return_all_the_fields() { final Address a1 = Address.builder().withStreet("Foo Bar rd 20") .withCity("San Francisco") .withZip("12345") .withState("CA") .withCountry("USA") .create(); final Customer c1 = Customer.builder().withId(new Id("the id")) .withName("Acme Corp.") .withVatNumber("1233455345") .withBillingAddress(a1) .create(); assertThat(c1.toString(), is("InMemoryCustomer(id=the id, name=Acme Corp., billingAddress=Address(street=Foo Bar rd 20, " + "city=San Francisco, state=CA, country=USA, zip=12345), vatNumber=1233455345)")); } }
.withCountry("USA") .create(); final Customer c1 = Customer.builder().withId(new Id("1")) .withName("Acme Corp.") .withVatNumber("1233455345")