@Test public void getActiveIngredients1() throws Exception { MockCacheManager.Create(); final String EXPECTED_RESPONSE_BODY = "[\"Hydralazine hydrochloride; hydrochlorothiazide; reserpine\",\"Hydroch" + "lorothiazide; reserpine\",\"Hydroflumethiazide; reserpine\",\"Reserpine\"]"; mockTransport = MockHelper.makeMockHttpTransport(EXPECTED_RESPONSE_BODY); handler = new MedActiveIngredientsHandler(mockTransport); List<String> expected = Arrays .asList("Hydralazine hydrochloride; hydrochlorothiazide; reserpine", "Hydrochlorothiazide; reserpine", "Hydroflumethiazide; reserpine", "Reserpine"); List<String> actual = Collections.emptyList(); actual = handler.getActiveIngredients("reserpine"); assertEquals(expected, actual); }
public List<String> getActiveIngredients(String medicationName) throws IOException { Optional<List<String>> cachedResponse = getCachedData( new TypeReference<List<String>>() { } , medicationName); if (cachedResponse.isPresent()) { return cachedResponse.get(); } List<String> activeIngredients; try { GenericUrl url = new GenericUrl(String.format(ACTIVE_INGREDIENTS_ENDPOINT, medicationName)); HttpRequest request = requestFactory.buildGetRequest(url); HttpResponse response = request.execute(); activeIngredients = addCachedData(Arrays.asList(response.parseAs(String[].class)), medicationName); } catch (HttpResponseException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); activeIngredients = Collections.emptyList(); } return activeIngredients; }
MedActiveIngredientsHandler extends WebAPIHandler { public List<String> getActiveIngredients(String medicationName) throws IOException { Optional<List<String>> cachedResponse = getCachedData( new TypeReference<List<String>>() { } , medicationName); if (cachedResponse.isPresent()) { return cachedResponse.get(); } List<String> activeIngredients; try { GenericUrl url = new GenericUrl(String.format(ACTIVE_INGREDIENTS_ENDPOINT, medicationName)); HttpRequest request = requestFactory.buildGetRequest(url); HttpResponse response = request.execute(); activeIngredients = addCachedData(Arrays.asList(response.parseAs(String[].class)), medicationName); } catch (HttpResponseException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); activeIngredients = Collections.emptyList(); } return activeIngredients; } }
MedActiveIngredientsHandler extends WebAPIHandler { public List<String> getActiveIngredients(String medicationName) throws IOException { Optional<List<String>> cachedResponse = getCachedData( new TypeReference<List<String>>() { } , medicationName); if (cachedResponse.isPresent()) { return cachedResponse.get(); } List<String> activeIngredients; try { GenericUrl url = new GenericUrl(String.format(ACTIVE_INGREDIENTS_ENDPOINT, medicationName)); HttpRequest request = requestFactory.buildGetRequest(url); HttpResponse response = request.execute(); activeIngredients = addCachedData(Arrays.asList(response.parseAs(String[].class)), medicationName); } catch (HttpResponseException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); activeIngredients = Collections.emptyList(); } return activeIngredients; } MedActiveIngredientsHandler();  MedActiveIngredientsHandler(HttpTransport transport); }
MedActiveIngredientsHandler extends WebAPIHandler { public List<String> getActiveIngredients(String medicationName) throws IOException { Optional<List<String>> cachedResponse = getCachedData( new TypeReference<List<String>>() { } , medicationName); if (cachedResponse.isPresent()) { return cachedResponse.get(); } List<String> activeIngredients; try { GenericUrl url = new GenericUrl(String.format(ACTIVE_INGREDIENTS_ENDPOINT, medicationName)); HttpRequest request = requestFactory.buildGetRequest(url); HttpResponse response = request.execute(); activeIngredients = addCachedData(Arrays.asList(response.parseAs(String[].class)), medicationName); } catch (HttpResponseException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); activeIngredients = Collections.emptyList(); } return activeIngredients; } MedActiveIngredientsHandler();  MedActiveIngredientsHandler(HttpTransport transport); @Override List<String> getData(Object... arguments); List<String> getActiveIngredients(String medicationName); }
MedActiveIngredientsHandler extends WebAPIHandler { public List<String> getActiveIngredients(String medicationName) throws IOException { Optional<List<String>> cachedResponse = getCachedData( new TypeReference<List<String>>() { } , medicationName); if (cachedResponse.isPresent()) { return cachedResponse.get(); } List<String> activeIngredients; try { GenericUrl url = new GenericUrl(String.format(ACTIVE_INGREDIENTS_ENDPOINT, medicationName)); HttpRequest request = requestFactory.buildGetRequest(url); HttpResponse response = request.execute(); activeIngredients = addCachedData(Arrays.asList(response.parseAs(String[].class)), medicationName); } catch (HttpResponseException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); activeIngredients = Collections.emptyList(); } return activeIngredients; } MedActiveIngredientsHandler();  MedActiveIngredientsHandler(HttpTransport transport); @Override List<String> getData(Object... arguments); List<String> getActiveIngredients(String medicationName);  }