### Question:
DefaultServersApi extends ApiBase implements ServersApi { @Override public Optional<Server> getByName(String serverName) { String serverNameEncoded = UriComponent.encode(serverName, QUERY_PARAM_SPACE_ENCODED); Invocation.Builder builder = client .target(SERVERS_URL) .queryParam("filter[name]", serverNameEncoded) .request(APPLICATION_JSON_TYPE); return getPageable(builder, ServerList.class) .filter(application -> application.getName().equals(serverName)) .getSingle(); } DefaultServersApi(NewRelicClient client); @Override Optional<Server> getByName(String serverName); @Override Server getById(int serverId);  }### Answer:
@Test public void getByName_shouldReturnServer_whenClientReturnsNotUniqueResult() throws Exception { when(responseMock.readEntity(ServerList.class)).thenReturn(new ServerList(asList( Server.builder().name("server").build(), Server.builder().name("server1").build() ))); Optional<Server> serverOptional = testee.getByName("server"); assertThat(serverOptional).isNotEmpty(); }
@Test public void getByName_shouldNotReturnServer_whenClientReturnsNotMatchingResult() throws Exception { when(responseMock.readEntity(ServerList.class)).thenReturn(new ServerList(Collections.singletonList( Server.builder().name("server1").build() ))); Optional<Server> serverOptional = testee.getByName("server"); assertThat(serverOptional).isEmpty(); }
@Test public void getByName_shouldNotReturnServer_whenClientReturnsEmptyList() throws Exception { when(responseMock.readEntity(ServerList.class)).thenReturn(new ServerList(Collections.emptyList())); Optional<Server> serverOptional = testee.getByName("server"); assertThat(serverOptional).isEmpty(); }