ClientItemHandler extends BaseHandler { public Optional<ItemDto> retrieveBySku(String sku) { String path = "/items/" + sku; String hal = HalHmacResourceFactory.INSTANCE .newClientResource(locale, path) .get(String.class); ReadableRepresentation rr = unmarshalHal(hal); Map<String, Object> properties = rr.getProperties(); List<Link> links = rr.getLinks(); ItemDto item = buildClientItem(properties, links); return Optional.of(item); } ClientItemHandler(Locale locale); Optional<ItemDto> retrieveBySku(String sku); static ItemDto buildClientItem(Map<String, Object> properties, List<Link> links);  }
@Test public void retrieveBySku() throws Exception { URI expectedUri = URI.create("http: when(client.resource(expectedUri)).thenReturn(webResource); when(webResource.get(String.class)) .thenReturn( FixtureAsserts.fixture("/fixtures/hal/item/expected-customer-retrieve-item.json")); Optional<ItemDto> optionalItem = PublicMerchantClient .newInstance(locale) .item() .retrieveBySku("0575088893"); assertTrue(optionalItem.isPresent()); ItemDto actualItem = optionalItem.get(); assertEquals("0575088893",actualItem.getSKU()); assertEquals("The Quantum Thief",actualItem.getOptionalProperties().get("title")); }