CatalogServiceImpl implements CatalogService { @Override public List<CatalogEntry> getEntries(final String catalogName) { Assert.hasText(catalogName, "the catalog name must not be empty!"); return catalogList.flatMap( catalog -> catalog.stream() .filter(c -> catalogName.equalsIgnoreCase(c.getName())) .findFirst() .map(Catalog::getEntries)) .orElseThrow(() -> new IllegalArgumentException(MessageFormat.format("Catalog with name {0} was not found.", catalogName)) ); }  @Override List<CatalogEntry> getEntries(final String catalogName);  }
@Test public void test_ok() { final List<CatalogEntry> catalogEntries = catalogService.getEntries("sourceSystems"); assertThat(catalogEntries, hasSize(2)); assertThat(catalogEntries.get(0).getCode(), is("CRM")); assertThat(catalogEntries.get(0).getDescription(), is("CRM system")); assertThat(catalogEntries.get(1).getCode(), is("BILLING")); assertThat(catalogEntries.get(1).getDescription(), is("Billing system")); }
@Test(expected = IllegalArgumentException.class) public void test_catalogNotFound() { catalogService.getEntries("FAKE"); }