### Question:
DefaultApplicationsApi extends ApiBase implements ApplicationsApi { @Override public Optional<Application> getByName(String applicationName) { Invocation.Builder builder = client .target(APPLICATIONS_URL) .queryParam("filter[name]", applicationName) .request(APPLICATION_JSON_TYPE); return getPageable(builder, ApplicationList.class) .filter(application -> application.getName().equals(applicationName)) .getSingle(); } DefaultApplicationsApi(NewRelicClient client); @Override Optional<Application> getByName(String applicationName); @Override Application update(int applicationId, Application application);  }### Answer:
@Test public void getByName_shouldNotReturnApplication_whenClientReturnsNotMatchingResult() throws Exception { when(responseMock.readEntity(ApplicationList.class)).thenReturn(new ApplicationList(Collections.singletonList( Application.builder().name("app1").build() ))); Optional<Application> applicationOptional = testee.getByName("app"); assertThat(applicationOptional).isEmpty(); }
@Test public void getByName_shouldNotReturnApplication_whenClientReturnsEmptyList() throws Exception { when(responseMock.readEntity(ApplicationList.class)).thenReturn(new ApplicationList(Collections.emptyList())); Optional<Application> applicationOptional = testee.getByName("app"); assertThat(applicationOptional).isEmpty(); }
@Test public void getByName_shouldReturnApplication_whenClientReturnsNotUniqueResult() throws Exception { when(responseMock.readEntity(ApplicationList.class)).thenReturn(new ApplicationList(asList( Application.builder().name("app").build(), Application.builder().name("app1").build() ))); Optional<Application> applicationOptional = testee.getByName("app"); assertThat(applicationOptional).isNotEmpty(); }