@Test public void getByName_shouldReturnPolicy_whenClientReturnsNotUniqueResult() throws Exception { when(responseMock.readEntity(AlertsPolicyList.class)).thenReturn(new AlertsPolicyList(asList( AlertsPolicy.builder().name("policy").build(), AlertsPolicy.builder().name("policy1").build() ))); Optional<AlertsPolicy> policyOptional = testee.getByName("policy"); assertThat(policyOptional).isNotEmpty(); }
@Override public Optional<AlertsPolicy> getByName(String alertsPolicyName) { Invocation.Builder builder = client .target(POLICIES_URL) .queryParam("filter[name]", alertsPolicyName) .request(APPLICATION_JSON_TYPE); return getPageable(builder, AlertsPolicyList.class) .filter(alertsPolicy -> alertsPolicy.getName().equals(alertsPolicyName)) .getSingle(); }
DefaultAlertsPoliciesApi extends ApiBase implements AlertsPoliciesApi { @Override public Optional<AlertsPolicy> getByName(String alertsPolicyName) { Invocation.Builder builder = client .target(POLICIES_URL) .queryParam("filter[name]", alertsPolicyName) .request(APPLICATION_JSON_TYPE); return getPageable(builder, AlertsPolicyList.class) .filter(alertsPolicy -> alertsPolicy.getName().equals(alertsPolicyName)) .getSingle(); } }
DefaultAlertsPoliciesApi extends ApiBase implements AlertsPoliciesApi { @Override public Optional<AlertsPolicy> getByName(String alertsPolicyName) { Invocation.Builder builder = client .target(POLICIES_URL) .queryParam("filter[name]", alertsPolicyName) .request(APPLICATION_JSON_TYPE); return getPageable(builder, AlertsPolicyList.class) .filter(alertsPolicy -> alertsPolicy.getName().equals(alertsPolicyName)) .getSingle(); } DefaultAlertsPoliciesApi(NewRelicClient client); }
DefaultAlertsPoliciesApi extends ApiBase implements AlertsPoliciesApi { @Override public Optional<AlertsPolicy> getByName(String alertsPolicyName) { Invocation.Builder builder = client .target(POLICIES_URL) .queryParam("filter[name]", alertsPolicyName) .request(APPLICATION_JSON_TYPE); return getPageable(builder, AlertsPolicyList.class) .filter(alertsPolicy -> alertsPolicy.getName().equals(alertsPolicyName)) .getSingle(); } DefaultAlertsPoliciesApi(NewRelicClient client); @Override Optional<AlertsPolicy> getByName(String alertsPolicyName); @Override AlertsPolicy create(AlertsPolicy policy); @Override AlertsPolicy delete(int policyId); @Override AlertsPolicyChannels updateChannels(AlertsPolicyChannels channels); }
DefaultAlertsPoliciesApi extends ApiBase implements AlertsPoliciesApi { @Override public Optional<AlertsPolicy> getByName(String alertsPolicyName) { Invocation.Builder builder = client .target(POLICIES_URL) .queryParam("filter[name]", alertsPolicyName) .request(APPLICATION_JSON_TYPE); return getPageable(builder, AlertsPolicyList.class) .filter(alertsPolicy -> alertsPolicy.getName().equals(alertsPolicyName)) .getSingle(); } DefaultAlertsPoliciesApi(NewRelicClient client); @Override Optional<AlertsPolicy> getByName(String alertsPolicyName); @Override AlertsPolicy create(AlertsPolicy policy); @Override AlertsPolicy delete(int policyId); @Override AlertsPolicyChannels updateChannels(AlertsPolicyChannels channels);  }