Skip to content

Commit 9d992f2

Browse files
committed
test: Update tests to use new responses
1 parent a9c1ecd commit 9d992f2

File tree

1 file changed

+13
-36
lines changed

1 file changed

+13
-36
lines changed

src/test/java/com/ibm/cloud/sdk/core/test/service/ResponseTest.java

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import com.ibm.cloud.sdk.core.http.RequestBuilder;
1616
import com.ibm.cloud.sdk.core.http.Response;
1717
import com.ibm.cloud.sdk.core.http.ServiceCall;
18-
import com.ibm.cloud.sdk.core.http.ServiceCallbackWithDetails;
18+
import com.ibm.cloud.sdk.core.http.ServiceCallback;
1919
import com.ibm.cloud.sdk.core.service.BaseService;
2020
import com.ibm.cloud.sdk.core.service.model.GenericModel;
2121
import com.ibm.cloud.sdk.core.test.BaseServiceUnitTest;
@@ -84,30 +84,30 @@ public void setUp() throws Exception {
8484
}
8585

8686
/**
87-
* Test that all fields are populated when calling executeWithDetails().
87+
* Test that all fields are populated when calling execute().
8888
*
8989
* @throws InterruptedException the interrupted exception
9090
*/
9191
@Test
92-
public void testExecuteWithDetails() throws InterruptedException {
92+
public void testExecute() throws InterruptedException {
9393
server.enqueue(new MockResponse().setBody(testResponseBody));
9494

95-
Response<TestModel> response = service.testMethod().executeWithDetails();
95+
Response<TestModel> response = service.testMethod().execute();
9696
assertNotNull(response.getResult());
9797
assertEquals(testResponseValue, response.getResult().getKey());
9898
assertNotNull(response.getHeaders());
9999
}
100100

101101
/**
102-
* Test that all fields are populated when calling enqueueWithDetails().
102+
* Test that all fields are populated when calling enqueue().
103103
*
104104
* @throws InterruptedException the interrupted exception
105105
*/
106106
@Test
107-
public void testEnqueueWithDetails() throws InterruptedException {
107+
public void testEnqueue() throws InterruptedException {
108108
server.enqueue(new MockResponse().setBody(testResponseBody));
109109

110-
service.testMethod().enqueueWithDetails(new ServiceCallbackWithDetails<TestModel>() {
110+
service.testMethod().enqueue(new ServiceCallback<TestModel>() {
111111
@Override
112112
public void onResponse(Response<TestModel> response) {
113113
assertNotNull(response.getResult());
@@ -126,37 +126,14 @@ public void onFailure(Exception e) { }
126126
public void testReactiveRequest() throws InterruptedException {
127127
server.enqueue(new MockResponse().setBody(testResponseBody));
128128

129-
final TestModel[] responseValue = new TestModel[1];
130-
Single<TestModel> observableRequest = service.testMethod().reactiveRequest();
131-
132-
observableRequest
133-
.subscribeOn(Schedulers.single())
134-
.subscribe(new Consumer<TestModel>() {
135-
@Override
136-
public void accept(TestModel testModel) throws Exception {
137-
responseValue[0] = testModel;
138-
}
139-
});
140-
141-
// asynchronous, so test that we continued without a value yet
142-
assertNull(responseValue[0]);
143-
Thread.sleep(2000);
144-
assertNotNull(responseValue[0]);
145-
assertEquals(testResponseValue, responseValue[0].getKey());
146-
}
147-
148-
@Test
149-
public void testReactiveRequestWithDetails() throws InterruptedException {
150-
server.enqueue(new MockResponse().setBody(testResponseBody));
151-
152-
Single<Response<TestModel>> observableRequest = service.testMethod().reactiveRequestWithDetails();
129+
Single<Response<TestModel>> observableRequest = service.testMethod().reactiveRequest();
153130

154131
observableRequest
155132
.subscribeOn(Schedulers.single())
156133
.subscribe(new Consumer<Response<TestModel>>() {
157134
@Override
158-
public void accept(Response<TestModel> testModel) throws Exception {
159-
testResponseModel = testModel;
135+
public void accept(Response<TestModel> response) throws Exception {
136+
testResponseModel = response;
160137
}
161138
});
162139

@@ -169,19 +146,19 @@ public void accept(Response<TestModel> testModel) throws Exception {
169146
}
170147

171148
/**
172-
* Test that headers are accessible from a HEAD method call using executeWithDetails().
149+
* Test that headers are accessible from a HEAD method call using execute().
173150
*
174151
* @throws InterruptedException the interrupted exception
175152
*/
176153
@Test
177-
public void testExecuteWithDetailsForHead() throws InterruptedException {
154+
public void testExecuteForHead() throws InterruptedException {
178155
Headers rawHeaders = Headers.of("Content-Length", "472", "Content-Type", "application/json"
179156
, "Server", "Mock");
180157
com.ibm.cloud.sdk.core.http.Headers expectedHeaders =
181158
new com.ibm.cloud.sdk.core.http.Headers(rawHeaders);
182159
server.enqueue(new MockResponse().setHeaders(rawHeaders));
183160

184-
Response<Void> response = service.testHeadMethod().executeWithDetails();
161+
Response<Void> response = service.testHeadMethod().execute();
185162
com.ibm.cloud.sdk.core.http.Headers actualHeaders = response.getHeaders();
186163
System.out.print(actualHeaders.equals(expectedHeaders));
187164
assertNull(response.getResult());

0 commit comments

Comments
 (0)