@@ -127,6 +127,28 @@ void postDataShouldReturnJsonBody() {
127127 }
128128 }
129129
130+ @ Test
131+ void postDataShouldReturnBadRequestOnMalformedJson () throws Exception {
132+ try (var server = newServer (Map .of ("post-data" , new EchoHandler ()));
133+ var client = httpClient ()) {
134+
135+ // Double comma after a property is invalid JSON; must be 400, not 500 (HCC-14723).
136+ var body = "{\" id\" :\" some-id\" ,,\" age\" :42}" ;
137+ var headers = Map .of ("correlation-id" , UUID .randomUUID ().toString ());
138+ var request = newRequest (server , path , "POST" , ofString (body ), headers );
139+
140+ var response = client .send (request , BodyHandlers .ofString ());
141+ var statusCode = response .statusCode ();
142+ var contentType = response .headers ().firstValue ("Content-Type" ).orElse ("" );
143+ var responseBody = response .body ();
144+
145+ assertThat (statusCode ).isEqualTo (400 );
146+ assertThat (contentType ).contains ("application/problem+json" );
147+ assertThat (responseBody ).contains ("keyword" );
148+ assertThat (responseBody ).contains ("pointer" );
149+ }
150+ }
151+
130152 @ Test
131153 void postDataShouldReturnBadRequestOnMissingRequiredProperties () {
132154 Map <String , RequestHandler > handlers = Map .of ("post-data" , new EchoHandler ());
@@ -217,7 +239,7 @@ void listObjectsShouldReturnJsonBody() {
217239 }
218240
219241 @ Test
220- void listObjectsShouldReturnBadRequestOnPassingObjectInsteadOfArray () {
242+ void listObjectsShouldReturnBadRequestOnPassingObjectInsteadOfArray () throws Exception {
221243 try (var server = newServer (Map .of ("post-list-objects" , new EchoHandler ()));
222244 var client = httpClient ()) {
223245
@@ -235,12 +257,6 @@ void listObjectsShouldReturnBadRequestOnPassingObjectInsteadOfArray() {
235257 assertThat (contentType ).contains ("application/problem+json" );
236258 assertThat (responseBody ).contains ("keyword" );
237259 assertThat (responseBody ).contains ("pointer" );
238-
239- } catch (IOException e ) {
240- fail (e );
241- } catch (InterruptedException e ) {
242- Thread .currentThread ().interrupt ();
243- fail (e );
244260 }
245261 }
246262 }
@@ -448,7 +464,7 @@ void postShapeUnknownKindReturns400() {
448464 }
449465
450466 @ Test
451- void postShapeMissingDiscriminatorReturns400 () {
467+ void postShapeMissingDiscriminatorReturns400 () throws Exception {
452468 // omitting "kind" makes both branches fail "required".
453469 try (var server = newServer (Map .of ("post-shape" , new EchoHandler ()));
454470 var client = httpClient ()) {
@@ -464,11 +480,6 @@ void postShapeMissingDiscriminatorReturns400() {
464480 // Both branches fail identically at /kind required -> de-duplicated to one entry.
465481 assertThat (response .body ()).contains ("\" errors\" " ).contains ("#/kind" );
466482 assertThat (response .body ().split ("#/kind" , -1 )).hasSize (2 ); // exactly one occurrence
467- } catch (IOException e ) {
468- fail (e );
469- } catch (InterruptedException e ) {
470- Thread .currentThread ().interrupt ();
471- fail (e );
472483 }
473484 }
474485 }
0 commit comments