@@ -138,14 +138,7 @@ public void testSuccessfulUnaryResponse() throws ExecutionException, Interrupted
138
138
139
139
Field request ;
140
140
Field expectedResponse ;
141
- request =
142
- expectedResponse =
143
- Field .newBuilder () // "echo" service
144
- .setName ("imTheBestField" )
145
- .setNumber (2 )
146
- .setCardinality (Cardinality .CARDINALITY_OPTIONAL )
147
- .setDefaultValue ("blah" )
148
- .build ();
141
+ request = expectedResponse = createTestMessage ();
149
142
150
143
MOCK_SERVICE .addResponse (expectedResponse );
151
144
@@ -164,27 +157,65 @@ public void testErrorUnaryResponse() throws InterruptedException {
164
157
165
158
HttpJsonCallContext callContext = HttpJsonCallContext .createDefault ().withChannel (channel );
166
159
167
- Field request ;
168
- request =
169
- Field .newBuilder () // "echo" service
170
- .setName ("imTheBestField" )
171
- .setNumber (2 )
172
- .setCardinality (Cardinality .CARDINALITY_OPTIONAL )
173
- .setDefaultValue ("blah" )
174
- .build ();
175
-
176
160
ApiException exception =
177
161
ApiExceptionFactory .createException (
178
162
new Exception (), FakeStatusCode .of (Code .NOT_FOUND ), false );
179
163
MOCK_SERVICE .addException (exception );
180
164
181
165
try {
182
- callable .futureCall (request , callContext ).get ();
166
+ callable .futureCall (createTestMessage () , callContext ).get ();
183
167
Assert .fail ("No exception raised" );
184
168
} catch (ExecutionException e ) {
185
169
HttpResponseException respExp = (HttpResponseException ) e .getCause ();
186
170
assertThat (respExp .getStatusCode ()).isEqualTo (400 );
187
171
assertThat (respExp .getContent ()).isEqualTo (exception .toString ());
188
172
}
189
173
}
174
+
175
+ @ Test
176
+ public void testErrorNullContentSuccessfulResponse () throws InterruptedException {
177
+ HttpJsonDirectCallable <Field , Field > callable =
178
+ new HttpJsonDirectCallable <>(FAKE_METHOD_DESCRIPTOR );
179
+
180
+ HttpJsonCallContext callContext = HttpJsonCallContext .createDefault ().withChannel (channel );
181
+
182
+ MOCK_SERVICE .addNullResponse ();
183
+
184
+ try {
185
+ callable .futureCall (createTestMessage (), callContext ).get ();
186
+ Assert .fail ("No exception raised" );
187
+ } catch (ExecutionException e ) {
188
+ HttpJsonStatusRuntimeException respExp = (HttpJsonStatusRuntimeException ) e .getCause ();
189
+ assertThat (respExp .getStatusCode ()).isEqualTo (200 );
190
+ assertThat (respExp .getCause ().getMessage ())
191
+ .isEqualTo ("Both response message and response exception were null" );
192
+ }
193
+ }
194
+
195
+ @ Test
196
+ public void testErrorNullContentFailedResponse () throws InterruptedException {
197
+ HttpJsonDirectCallable <Field , Field > callable =
198
+ new HttpJsonDirectCallable <>(FAKE_METHOD_DESCRIPTOR );
199
+
200
+ HttpJsonCallContext callContext = HttpJsonCallContext .createDefault ().withChannel (channel );
201
+ MOCK_SERVICE .addNullResponse (400 );
202
+
203
+ try {
204
+ callable .futureCall (createTestMessage (), callContext ).get ();
205
+ Assert .fail ("No exception raised" );
206
+ } catch (ExecutionException e ) {
207
+ HttpResponseException respExp = (HttpResponseException ) e .getCause ();
208
+ assertThat (respExp .getStatusCode ()).isEqualTo (400 );
209
+ assertThat (respExp .getContent ()).isNull ();
210
+ }
211
+ }
212
+
213
+ private Field createTestMessage () {
214
+ return Field .newBuilder () // "echo" service
215
+ .setName ("imTheBestField" )
216
+ .setNumber (2 )
217
+ .setCardinality (Cardinality .CARDINALITY_OPTIONAL )
218
+ .setDefaultValue ("blah" )
219
+ .build ();
220
+ }
190
221
}
0 commit comments