@@ -730,4 +730,51 @@ public int statusCode() {
730730 assertNull (exception .getProblemDetails ().getDetails ());
731731 assertNull (exception .getProblemDetails ().getInstance ());
732732 }
733+
734+ @ Test
735+ void testMinimalProblemDetails () {
736+ // The specific error code is irrelevant to this test.
737+ final int statusCode = 400 ;
738+ final Headers headers = Headers .of (Collections .singletonMap ("x-key" , Arrays .asList ("value" )));
739+ final SolidClient solidClient = new SolidClient (ClientProvider .getClient (), headers , false );
740+ final SolidContainer resource = new SolidContainer (URI .create ("http://example.com" ));
741+
742+ final SolidClientException exception = assertThrows (
743+ BadRequestException .class ,
744+ () -> solidClient .handleResponse (resource , headers , "message" )
745+ .apply (new Response <byte []>() {
746+ @ Override
747+ public Headers headers () {
748+ final List <String > headerValues = new ArrayList <>();
749+ headerValues .add ("application/problem+json" );
750+ final Map <String , List <String >> headerMap = new HashMap <>();
751+ headerMap .put ("Content-Type" , headerValues );
752+ return Headers .of (headerMap );
753+ }
754+
755+ // Return minimal problem details..
756+ @ Override
757+ public byte [] body () {
758+ return "{\" status\" :400}" .getBytes ();
759+ }
760+
761+ @ Override
762+ public URI uri () {
763+ return null ;
764+ }
765+
766+ @ Override
767+ public int statusCode () {
768+ return statusCode ;
769+ }
770+ })
771+ );
772+ assertEquals (statusCode , exception .getStatusCode ());
773+ // On malformed response, the ProblemDetails should fall back to defaults.
774+ assertEquals (ProblemDetails .DEFAULT_TYPE , exception .getProblemDetails ().getType ().toString ());
775+ assertEquals ("Bad Request" , exception .getProblemDetails ().getTitle ());
776+ assertEquals (statusCode , exception .getProblemDetails ().getStatus ());
777+ assertNull (exception .getProblemDetails ().getDetails ());
778+ assertNull (exception .getProblemDetails ().getInstance ());
779+ }
733780}
0 commit comments