AdviceTraits { public static ResponseEntity<Problem> fallback( final Problem problem, final HttpHeaders headers) { return ResponseEntity .status(HttpStatus.valueOf(Optional.ofNullable(problem.getStatus()) .orElse(Status.INTERNAL_SERVER_ERROR) .getStatusCode())) .headers(headers) .contentType(PROBLEM) .body(problem); } private  AdviceTraits(); static void log(
            final Throwable throwable,
            final HttpStatus status); static ResponseEntity<Problem> fallback(
            final Problem problem,
            final HttpHeaders headers); static Optional<MediaType> getProblemMediaType(final List<MediaType> mediaTypes);  }
@Test void fallsbackProblemWithStatus() { ResponseEntity<Problem> result = AdviceTraits.fallback( Problem.valueOf(Status.RESET_CONTENT), new HttpHeaders() ); assertThat(result.getStatusCode(), is(HttpStatus.RESET_CONTENT)); HttpHeaders expectedHeaders = new HttpHeaders(); expectedHeaders.setContentType(MediaType.valueOf("application/problem+json")); assertThat(result.getHeaders(), is(expectedHeaders)); assertThat(result.getBody().getStatus(), is(Status.RESET_CONTENT)); }
@Test void fallsbackProblemWithoutStatus() { ResponseEntity<Problem> result = AdviceTraits.fallback( Problem.builder().withTitle("Some title").build(), new HttpHeaders() ); assertThat(result.getStatusCode(), is(HttpStatus.INTERNAL_SERVER_ERROR)); HttpHeaders expectedHeaders = new HttpHeaders(); expectedHeaders.setContentType(MediaType.valueOf("application/problem+json")); assertThat(result.getHeaders(), is(expectedHeaders)); assertThat(result.getBody().getTitle(), is("Some title")); }