UniProtClient { public Collection<String> fetchReactomeIds(String uniprotId) { String url = MessageFormat.format(UNIPROT_URL, uniprotId); try { String result = restTemplate.getForObject(url, String.class); return parseResult(result); } catch (RestClientException e) { LOGGER.error(e.getMessage(), e); return Lists.newArrayList(); } } @Inject  UniProtClient(RestTemplate restTemplate); Collection<String> fetchReactomeIds(String uniprotId); static final String UNIPROT_URL; }
@Test public void testFetchReactomeIds() { String url = MessageFormat.format(UniProtClient.UNIPROT_URL, UNIPROT_ID); when(restTemplateMock.getForObject(url, String.class)).thenReturn("Entry\tCross-reference (reactome)\n" + "Q8N349\tREACT_111102;\n"); assertThat(subject.fetchReactomeIds(UNIPROT_ID), containsInAnyOrder("REACT_111102")); }
@Test public void testFetchReactomeIdsUniprotDown() { String url = MessageFormat.format(UniProtClient.UNIPROT_URL, UNIPROT_ID); Mockito.doThrow(new HttpServerErrorException(HttpStatus.valueOf(HttpStatus.SERVICE_UNAVAILABLE.value()))) .when(restTemplateMock).getForObject(url, String.class); assertThat(subject.fetchReactomeIds(UNIPROT_ID).size(), is(0)); }