ClientItemCollectionHandler extends BaseHandler { public List<ItemDto> retrievePromotionalItemsByPage(int pageNumber, int pageSize) { if (pageNumber < 0) { pageNumber = 0; } if (pageSize < 0) { pageSize = 0; } if (pageSize > 50) { pageSize = 50; } String path = String.format("/items/promotion?pn=%d&ps=%d", pageNumber, pageSize); String hal = HalHmacResourceFactory.INSTANCE .newClientResource(locale, path) .get(String.class); ReadableRepresentation rr = unmarshalHal(hal); List<ItemDto> clientItems = Lists.newArrayList(); for (Map.Entry<String, ReadableRepresentation> itemResource : rr.getResources()) { List<Link> links = itemResource.getValue().getLinks(); ItemDto clientItem = ClientItemHandler.buildClientItem(itemResource.getValue().getProperties(), links); clientItems.add(clientItem); } return clientItems; } ClientItemCollectionHandler(Locale locale); List<ItemDto> retrievePromotionalItemsByPage(int pageNumber, int pageSize);  }
@Test public void retrievePromotionalItemsByPage() throws Exception { URI expectedUri = URI.create("http: when(client.resource(expectedUri)).thenReturn(webResource); when(webResource.get(String.class)).thenReturn( FixtureAsserts.jsonFixture("/fixtures/hal/item/expected-public-retrieve-items-page-1.json") ); List<ItemDto> items = PublicMerchantClient .newInstance(locale) .items() .retrievePromotionalItemsByPage(1,1); assertEquals("Unexpected number of items", 1, items.size()); assertEquals("Expected title", "Cryptonomicon", items.get(0).getOptionalProperties().get("title")); assertEquals("Expected uri", "http: assertEquals("Expected uri", "/item/0099410672", items.get(0).getOptionalProperties().get("self")); }