NinjaDefault implements Ninja { @Override public Result getNotFoundResult(Context context) { return getNotFoundResult(context, null); }  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 testThatGetOnNotFoundDoesContentNegotiation() throws Exception { Result result = ninjaDefault.getNotFoundResult(contextImpl); assertThat(result.getContentType(), equalTo(null)); assertThat(result.supportedContentTypes().size(), equalTo(3)); }
@Test public void testThatGetOnNotFoundDoesFallsBackToHtml() throws Exception { Result result = ninjaDefault.getNotFoundResult(contextImpl); assertThat(result.fallbackContentType().get(), equalTo(Result.TEXT_HTML)); }
@Test public void testGetOnNotFoundResultWorks() throws Exception { when(ninjaProperties.getWithDefault( ArgumentMatchers.eq(NinjaConstant.LOCATION_VIEW_HTML_NOT_FOUND_KEY), ArgumentMatchers.eq(NinjaConstant.LOCATION_VIEW_FTL_HTML_NOT_FOUND))) .thenReturn(NinjaConstant.LOCATION_VIEW_FTL_HTML_NOT_FOUND); Result result = ninjaDefault.getNotFoundResult(contextImpl); assertThat(result.getStatusCode(), equalTo(Result.SC_404_NOT_FOUND)); assertThat(result.getTemplate(), equalTo(NinjaConstant.LOCATION_VIEW_FTL_HTML_NOT_FOUND)); assertTrue(result.getRenderable() instanceof Message); verify(messages).getWithDefault( ArgumentMatchers.eq(NinjaConstant.I18N_NINJA_SYSTEM_NOT_FOUND_TEXT_KEY), ArgumentMatchers.eq(NinjaConstant.I18N_NINJA_SYSTEM_NOT_FOUND_TEXT_DEFAULT), ArgumentMatchers.eq(contextImpl), any(Optional.class)); verify(ninjaProperties).getWithDefault( ArgumentMatchers.eq(NinjaConstant.LOCATION_VIEW_HTML_NOT_FOUND_KEY), ArgumentMatchers.eq(NinjaConstant.LOCATION_VIEW_FTL_HTML_NOT_FOUND)); }
@Test public void testThatGetOnNotFoundExceptionDoesContentNegotiation() throws Exception { Result result = ninjaDefault.getNotFoundResult(contextImpl, new RequestNotFoundException("not important")); assertThat(result.getContentType(), equalTo(null)); assertThat(result.supportedContentTypes().size(), equalTo(3)); }
@Test public void testThatGetOnNotFoundExceptionDoesFallsBackToHtml() throws Exception { Result result = ninjaDefault.getNotFoundResult(contextImpl, new RequestNotFoundException("not important")); assertThat(result.fallbackContentType().get(), equalTo(Result.TEXT_HTML)); }
@Test public void testGetOnNotFoundExceptionResultWorks() throws Exception { when(ninjaProperties.getWithDefault( ArgumentMatchers.eq(NinjaConstant.LOCATION_VIEW_HTML_NOT_FOUND_KEY), ArgumentMatchers.eq(NinjaConstant.LOCATION_VIEW_FTL_HTML_NOT_FOUND))) .thenReturn(NinjaConstant.LOCATION_VIEW_FTL_HTML_NOT_FOUND); RequestNotFoundException exception = new RequestNotFoundException("not important"); Result result = ninjaDefault.getNotFoundResult( contextImpl, exception); assertThat(result.getStatusCode(), equalTo(Result.SC_404_NOT_FOUND)); assertThat(result.getTemplate(), equalTo(NinjaConstant.LOCATION_VIEW_FTL_HTML_NOT_FOUND)); assertTrue(result.getRenderable() instanceof Message); verify(messages).getWithDefault( ArgumentMatchers.eq(NinjaConstant.I18N_NINJA_SYSTEM_NOT_FOUND_TEXT_KEY), ArgumentMatchers.eq(NinjaConstant.I18N_NINJA_SYSTEM_NOT_FOUND_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_NOT_FOUND_KEY), ArgumentMatchers.eq(NinjaConstant.LOCATION_VIEW_FTL_HTML_NOT_FOUND)); }