use of ninja.NinjaDefault in project ninja by ninjaframework.
the class DiagnosticErrorRendererTest method buildAndRenderDiagnosticErrorWithHTMLEntities.
@Test
public void buildAndRenderDiagnosticErrorWithHTMLEntities() throws Exception {
NinjaDefault ninja = Mockito.spy(new NinjaDefault());
doReturn(Boolean.TRUE).when(ninja).isDiagnosticsEnabled();
// build context that will have HTML entites in key spots
when(context.getMethod()).thenReturn("GET");
when(context.getContextPath()).thenReturn("/");
when(context.getAttributes()).thenReturn(ImmutableMap.of("TEST-ATTR", (Object) "Attribute with < > & entities"));
Result testResult = ninja.getInternalServerErrorResult(context, new Exception("Exception message with < > & entities"));
// renderable in testResult is the DiagnosticError
Assert.assertNotNull(testResult);
Assert.assertNotNull(testResult.getRenderable());
Assert.assertThat(testResult.getRenderable(), instanceOf(DiagnosticError.class));
DiagnosticError de = (DiagnosticError) testResult.getRenderable();
DiagnosticErrorRenderer renderer = DiagnosticErrorRenderer.build(context, testResult, de);
String out = renderer.render();
Assert.assertThat(out, containsString("Attribute with < > & entities"));
Assert.assertThat(out, containsString("Exception message with < > & entities"));
}
Aggregations