BaseClient { public Object executeRequest(Request request, Type returnType) { this.validateNotNullArguments(request, returnType); String response = this.executeRequest(request); if (String.class.equals(returnType)) { return response; } return adaptor.buildResource(response, returnType); } BaseClient(SDKConfiguration config, String hostname); protected  BaseClient(
            ResourceAdaptor adaptor,
            HttpRestClient client,
            Supplier<TaskMonitor> supplier,
            String hostname); void setSessionId(String sessionId); String getSessionId(); Object executeRequest(Request request, Type returnType); T executeRequest(Request request, Class<T> returnType); TaskResource executeMonitorableRequest(Request request);  }
@Test(expected = SDKInvalidArgumentException.class) public void shouldThrowExceptionWhenTryingToExecuteRequestWithoutType() { this.baseClient.executeRequest(new Request(HttpMethod.GET, ANY_URI_STRING), (Type) null); }
@Test(expected = SDKInvalidArgumentException.class) public void shouldThrowExceptionWhenTryingToExecuteRequestWithoutClass() { this.baseClient.executeRequest(new Request(HttpMethod.GET, ANY_URI_STRING), null); }
@Test(expected = SDKInvalidArgumentException.class) public void shouldThrowExceptionWhenTryingToExecuteRequestWithoutRequestObjectWithType() { this.baseClient.executeRequest(null, TypeToken.of(Object.class).getType()); }
@Test(expected = SDKInvalidArgumentException.class) public void shouldThrowExceptionWhenTryingToExecuteRequestWithoutRequestObjectWithClass() { this.baseClient.executeRequest(null, Object.class); }
@Test(expected = SDKNoResponseException.class) public void shouldThrowExceptionWhenServerReturnsNoResponseForExecuteRequestWithType() { given(httpClient.sendRequest(anyString(), any(Request.class))).willReturn(""); this.baseClient.executeRequest(new Request(HttpMethod.GET, ANY_URI_STRING), TypeToken.of(Object.class).getType()); }
@Test(expected = SDKNoResponseException.class) public void shouldThrowExceptionWhenServerReturnsNoResponseForExecuteRequestWithClass() { given(httpClient.sendRequest(anyString(), any(Request.class))).willReturn(""); this.baseClient.executeRequest(new Request(HttpMethod.GET, ANY_URI_STRING), Object.class); }
@Test public void shouldExecuteRequestWithType() { given(httpClient.sendRequest(anyString(), any(Request.class))).willReturn(ANY_RESOURCE); Request request = new Request(HttpMethod.GET, ANY_URI_STRING); this.baseClient.executeRequest(request, TypeToken.of(Object.class).getType()); then(httpClient).should().sendRequest(anyString(), eq(request)); }
@Test public void shouldExecuteRequestWithClass() { given(httpClient.sendRequest(anyString(), any(Request.class))).willReturn(ANY_RESOURCE); Request request = new Request(HttpMethod.GET, ANY_URI_STRING); this.baseClient.executeRequest(request, Object.class); then(httpClient).should().sendRequest(anyString(), eq(request)); }
@Test public void shouldExecuteRequestWithTypeAndReturnString() { given(httpClient.sendRequest(anyString(), any(Request.class))).willReturn(ANY_RESPONSE_STRING); Request request = new Request(HttpMethod.GET, ANY_URI_STRING); String response = (String) this.baseClient.executeRequest(request, TypeToken.of(String.class).getType()); then(httpClient).should().sendRequest(anyString(), eq(request)); assertThat(response, is(equalTo(ANY_RESPONSE_STRING))); }
@Test public void shouldExecuteRequestWithClassAndReturnString() { given(httpClient.sendRequest(anyString(), any(Request.class))).willReturn(ANY_RESPONSE_STRING); Request request = new Request(HttpMethod.GET, ANY_URI_STRING); String response = this.baseClient.executeRequest(request, String.class); then(httpClient).should().sendRequest(anyString(), eq(request)); assertThat(response, is(equalTo(ANY_RESPONSE_STRING))); }