@@ -290,6 +290,40 @@ class RequestHandlerTest {
290
290
}
291
291
}
292
292
293
+ @Test
294
+ fun `should return 400 on missing body when content type stated` () {
295
+
296
+ val response = testRequestHandler.handleRequest(
297
+ POST (" /some" )
298
+ .withHeaders(
299
+ mapOf (
300
+ " Accept" to " application/json" ,
301
+ " Content-Type" to " application/json"
302
+ )
303
+ )
304
+ .withBody(null ), mockk()
305
+ )
306
+ assert (response.statusCode).isEqualTo(400 )
307
+ assert (mapper.readValue<ApiError >(response.body).code).isEqualTo(" REQUEST_BODY_MISSING" )
308
+ }
309
+
310
+ @Test
311
+ fun `should handle null body when content type is stated and request handler body type is nullable` () {
312
+
313
+ val response = testRequestHandler.handleRequest(
314
+ POST (" /some-nullable" )
315
+ .withHeaders(
316
+ mapOf (
317
+ " Accept" to " application/json" ,
318
+ " Content-Type" to " application/json"
319
+ )
320
+ )
321
+ .withBody(null ), mockk()
322
+ )
323
+ assert (response.statusCode).isEqualTo(200 )
324
+ assert (response.body).isEqualTo(""" {"greeting":""}""" )
325
+ }
326
+
293
327
@Test
294
328
fun `should handle api exception` () {
295
329
@@ -542,7 +576,7 @@ class RequestHandlerTest {
542
576
}
543
577
544
578
@Test
545
- fun `Handler should return the content type that is accepted` () {
579
+ fun `should return the content type that is accepted` () {
546
580
val jsonResponse = AcceptTypeDependingHandler ().handleRequest(
547
581
GET (" /all-objects" )
548
582
.withHeader(" accept" , " application/json" ),
@@ -664,7 +698,7 @@ class RequestHandlerTest {
664
698
)
665
699
}
666
700
667
- POST (" /some" ) { r : Request <TestRequest > ->
701
+ POST (" /some" ) { _ : Request <TestRequest > ->
668
702
ResponseEntity .ok(
669
703
TestResponse (
670
704
" v2"
@@ -680,6 +714,14 @@ class RequestHandlerTest {
680
714
)
681
715
}.producing(" application/json" , " application/*+json" )
682
716
717
+ POST (" /some-nullable" ) { r: Request <TestRequest ?> ->
718
+ ResponseEntity .ok(
719
+ TestResponse (
720
+ r.body?.greeting.orEmpty()
721
+ )
722
+ )
723
+ }.producing(" application/json" )
724
+
683
725
POST (" /somes" ) { r: Request <List <TestRequest >> ->
684
726
ResponseEntity .ok(r.body.map {
685
727
TestResponse (
0 commit comments