@@ -167,8 +167,7 @@ void sendReturnsNullOnNoContent(int statusCode) throws Exception {
167
167
httpMethod = HttpMethod .GET ;
168
168
}
169
169
};
170
- final var mockEntity = mock (Parsable .class );
171
- when (mockEntity .getFieldDeserializers ()).thenReturn (new HashMap <>());
170
+ final var mockEntity = creatMockEntity ();
172
171
final var response = requestAdapter .send (requestInformation , null , (node ) -> mockEntity );
173
172
assertNull (response );
174
173
}
@@ -198,14 +197,9 @@ void sendReturnsObjectOnContent(int statusCode) throws Exception {
198
197
httpMethod = HttpMethod .GET ;
199
198
}
200
199
};
201
- final var mockEntity = mock (Parsable .class );
202
- when (mockEntity .getFieldDeserializers ()).thenReturn (new HashMap <>());
203
- final var mockParseNode = mock (ParseNode .class );
204
- when (mockParseNode .getObjectValue (any (ParsableFactory .class ))).thenReturn (mockEntity );
205
- final var mockFactory = mock (ParseNodeFactory .class );
206
- when (mockFactory .getParseNode (any (String .class ), any (InputStream .class )))
207
- .thenReturn (mockParseNode );
208
- when (mockFactory .getValidContentType ()).thenReturn ("application/json" );
200
+ final var mockEntity = creatMockEntity ();
201
+ final var mockParseNode = creatMockParseNode (mockEntity );
202
+ final var mockFactory = creatMockParseNodeFactory (mockParseNode , "application/json" );
209
203
final var requestAdapter =
210
204
new OkHttpRequestAdapter (authenticationProviderMock , mockFactory , null , client );
211
205
final var response = requestAdapter .send (requestInformation , null , (node ) -> mockEntity );
@@ -260,16 +254,11 @@ void throwsAPIException(
260
254
httpMethod = HttpMethod .GET ;
261
255
}
262
256
};
263
- final var mockEntity = mock (Parsable .class );
264
- when (mockEntity .getFieldDeserializers ()).thenReturn (new HashMap <>());
257
+ final var mockEntity = creatMockEntity ();
265
258
final var mockParsableFactory = mock (ParsableFactory .class );
266
259
when (mockParsableFactory .create (any (ParseNode .class ))).thenReturn (mockEntity );
267
- final var mockParseNode = mock (ParseNode .class );
268
- when (mockParseNode .getObjectValue (any (ParsableFactory .class ))).thenReturn (mockEntity );
269
- final var mockFactory = mock (ParseNodeFactory .class );
270
- when (mockFactory .getParseNode (any (String .class ), any (InputStream .class )))
271
- .thenReturn (mockParseNode );
272
- when (mockFactory .getValidContentType ()).thenReturn ("application/json" );
260
+ final var mockParseNode = creatMockParseNode (mockEntity );
261
+ final var mockFactory = creatMockParseNodeFactory (mockParseNode , "application/json" );
273
262
274
263
final var requestAdapter =
275
264
new OkHttpRequestAdapter (authenticationProviderMock , mockFactory , null , client );
@@ -430,4 +419,25 @@ public static OkHttpClient getMockClient(final Response response) throws IOExcep
430
419
when (mockClient .newCall (any ())).thenReturn (remoteCall );
431
420
return mockClient ;
432
421
}
422
+
423
+ public Parsable creatMockEntity () {
424
+ final var mockEntity = mock (Parsable .class );
425
+ when (mockEntity .getFieldDeserializers ()).thenReturn (new HashMap <>());
426
+ return mockEntity ;
427
+ }
428
+
429
+ public ParseNode creatMockParseNode (Parsable entity ) {
430
+ final var mockParseNode = mock (ParseNode .class );
431
+ when (mockParseNode .getObjectValue (any (ParsableFactory .class ))).thenReturn (entity );
432
+ return mockParseNode ;
433
+ }
434
+
435
+ public ParseNodeFactory creatMockParseNodeFactory (
436
+ ParseNode mockParseNode , String validContentType ) {
437
+ final var mockFactory = mock (ParseNodeFactory .class );
438
+ when (mockFactory .getParseNode (any (String .class ), any (InputStream .class )))
439
+ .thenReturn (mockParseNode );
440
+ when (mockFactory .getValidContentType ()).thenReturn (validContentType );
441
+ return mockFactory ;
442
+ }
433
443
}
0 commit comments