NinjaDefault implements Ninja { @Override public Result getBadRequestResult(Context context, BadRequestException exception) { if (isDiagnosticsEnabled()) { DiagnosticError diagnosticError = DiagnosticErrorBuilder.build400BadRequestDiagnosticError(exception, true); return Results.badRequest().render(diagnosticError); } Message message = buildErrorMessage( context, NinjaConstant.I18N_NINJA_SYSTEM_BAD_REQUEST_TEXT_KEY, NinjaConstant.I18N_NINJA_SYSTEM_BAD_REQUEST_TEXT_DEFAULT, Optional.ofNullable(exception), Optional.<Result>empty()); Result result = Results .badRequest() .supportedContentTypes(Result.TEXT_HTML, Result.APPLICATION_JSON, Result.APPLICATION_XML) .fallbackContentType(Result.TEXT_HTML) .render(message) .template( ninjaProperties.getWithDefault( NinjaConstant.LOCATION_VIEW_HTML_BAD_REQUEST_KEY, NinjaConstant.LOCATION_VIEW_FTL_HTML_BAD_REQUEST)); return result; }  boolean isDiagnosticsEnabled(); @Override void onRouteRequest(Context.Impl context); @Override void renderErrorResultAndCatchAndLogExceptions(
            Result result, Context context); @Override void onFrameworkStart(); @Override void onFrameworkShutdown(); @Override Result onException(Context context, Exception exception); Result onException(Context context, Exception exception, Result underlyingResult); Result getRenderingExceptionResult(Context context, RenderingException exception, Result underlyingResult); @Deprecated Result getInternalServerErrorResult(Context context, Exception exception); @Override Result getInternalServerErrorResult(Context context, Exception exception, Result underlyingResult); @Override Result getNotFoundResult(Context context); @Override Result getNotFoundResult(Context context, RequestNotFoundException exception); @Override Result getBadRequestResult(Context context, BadRequestException exception); @Override Result getUnauthorizedResult(Context context); @Override Result getForbiddenResult(Context context); @Override Result getForbiddenResult(Context context, ForbiddenRequestException exception);  }
@Test public void testThatGetBadRequestContentNegotiation() throws Exception { Result result = ninjaDefault.getBadRequestResult(contextImpl, new BadRequestException("not important")); assertThat(result.getContentType(), equalTo(null)); assertThat(result.supportedContentTypes().size(), equalTo(3)); }
@Test public void testThatGetBadRequestDoesFallsBackToHtml() throws Exception { Result result = ninjaDefault.getBadRequestResult(contextImpl, new BadRequestException("not important")); assertThat(result.fallbackContentType().get(), equalTo(Result.TEXT_HTML)); }
@Test public void testGetBadRequest() throws Exception { when(ninjaProperties.getWithDefault( ArgumentMatchers.eq(NinjaConstant.LOCATION_VIEW_HTML_BAD_REQUEST_KEY), ArgumentMatchers.eq(NinjaConstant.LOCATION_VIEW_FTL_HTML_BAD_REQUEST))) .thenReturn(NinjaConstant.LOCATION_VIEW_FTL_HTML_BAD_REQUEST); BadRequestException exception = new BadRequestException("not important"); Result result = ninjaDefault.getBadRequestResult( contextImpl, exception); assertThat(result.getStatusCode(), equalTo(Result.SC_400_BAD_REQUEST)); assertThat(result.getTemplate(), equalTo(NinjaConstant.LOCATION_VIEW_FTL_HTML_BAD_REQUEST)); assertTrue(result.getRenderable() instanceof Message); verify(messages).getWithDefault( ArgumentMatchers.eq(NinjaConstant.I18N_NINJA_SYSTEM_BAD_REQUEST_TEXT_KEY), ArgumentMatchers.eq(NinjaConstant.I18N_NINJA_SYSTEM_BAD_REQUEST_TEXT_DEFAULT), ArgumentMatchers.eq(contextImpl), any(Optional.class)); verify(messages).getWithDefault( ArgumentMatchers.eq(exception.getMessage()), ArgumentMatchers.eq(exception.getLocalizedMessage()), ArgumentMatchers.eq(contextImpl), any(Optional.class)); verify(ninjaProperties).getWithDefault( ArgumentMatchers.eq(NinjaConstant.LOCATION_VIEW_HTML_BAD_REQUEST_KEY), ArgumentMatchers.eq(NinjaConstant.LOCATION_VIEW_FTL_HTML_BAD_REQUEST)); }