### Question:
ApplicationDataStore extends CommonDatastore<ApplicationItem, Application> implements DatastoreHasAdd<ApplicationItem>,
DatastoreHasUpdate<ApplicationItem>,
DatastoreHasGet<ApplicationItem>,DatastoreHasSearch<ApplicationItem>, DatastoreHasDelete { @Override public ApplicationItem update(final APIID id, final Map<String, String> attributes) { try { final ApplicationUpdater applicationUpdater = converter.toApplicationUpdater(attributes); final Application application = applicationAPI.updateApplication(id.toLong(), applicationUpdater); return converter.toApplicationItem(application); } catch (final Exception e) { throw new APIException(e); } } ApplicationDataStore(final APISession engineSession, final ApplicationAPI applicationAPI, final PageAPI pageAPI, final ApplicationItemConverter converter); @Override void delete(final List<APIID> ids); @Override ApplicationItem get(final APIID id); @Override ApplicationItem add(final ApplicationItem item); @Override ApplicationItem update(final APIID id, final Map<String, String> attributes); @Override ItemSearchResult<ApplicationItem> search(final int page, final int resultsByPage, final String search, final String orders,
            final Map<String, String> filters);  }### Answer:
@Test public void should_return_application_updated_by_ApplicationAPI_converted_to_ApplicationItem_on_update() throws Exception { final HashMap<String, String> attributesToUpDate = new HashMap<String, String>(); attributesToUpDate.put(ApplicationItem.ATTRIBUTE_TOKEN, "app_name"); attributesToUpDate.put(ApplicationItem.ATTRIBUTE_DISPLAY_NAME, "App display name"); final ApplicationUpdater applicationUpdater = new ApplicationUpdater(); given(converter.toApplicationUpdater(attributesToUpDate)).willReturn(applicationUpdater); final ApplicationImpl application = new ApplicationImpl("app", "1.0", "app desc", 2L, 3L); given(applicationAPI.updateApplication(1, applicationUpdater)).willReturn(application); final ApplicationItem item = new ApplicationItem(); given(converter.toApplicationItem(application)).willReturn(item); given(pageAPI.getPageByName("custompage_home")).willReturn(homePage); given(homePage.getId()).willReturn(1L); given(applicationAPI.createApplicationPage(application.getId(), 1, "custompage_home")).willReturn(applicationPage); final ApplicationItem createdItem = dataStore.update(APIID.makeAPIID(1L), attributesToUpDate); verify(converter, times(1)).toApplicationUpdater(attributesToUpDate); verify(applicationAPI, times(1)).updateApplication(1, applicationUpdater); verify(converter, times(1)).toApplicationItem(application); assertThat(createdItem).isEqualTo(new ApplicationItem()); }
@Test(expected = APIException.class) public void should_throw_APIException_when_ApplicationAPI_throws_an_exception_on_UpDate() throws Exception { given(applicationAPI.updateApplication(anyLong(), any(ApplicationUpdater.class))).willThrow(new UpdateException("")); dataStore.update(APIID.makeAPIID(1L), new HashMap<String, String>()); }