### Question:
ExceptionRepresentation extends MappingRepresentation { @Override protected void serialize( MappingSerializer serializer ) { if ( includeLegacyRepresentation ) { renderWithLegacyFormat( errors.get( 0 ).cause(), serializer ); } renderWithStatusCodeFormat( serializer ); } ExceptionRepresentation( Throwable exception );  ExceptionRepresentation( Throwable exception, boolean includeLegacyRepresentation );  ExceptionRepresentation( Neo4jError ... errors );   }### Answer:
@Test public void shouldIncludeCause() throws Exception { ExceptionRepresentation rep = new ExceptionRepresentation( new RuntimeException( "Hoho", new RuntimeException( "Haha", new RuntimeException( "HAHA!" ) ) ) ); JsonNode out = serialize( rep ); assertThat( out.get("cause").get("message").asText(), is( "Haha" ) ); assertThat( out.get( "cause" ).get("cause").get("message").asText(), is( "HAHA!") ); }
@Test public void shouldRenderErrorsWithNeo4jStatusCode() throws Exception { ExceptionRepresentation rep = new ExceptionRepresentation( new KernelException( UnknownError, "Hello" ) { } ); JsonNode out = serialize( rep ); assertThat(out.get("errors").get(0).get("code").asText(), equalTo("Neo.DatabaseError.General.UnknownError")); assertThat(out.get("errors").get(0).get("message").asText(), equalTo("Hello")); }
@Test public void shouldExcludeLegacyFormatIfAsked() throws Exception { ExceptionRepresentation rep = new ExceptionRepresentation( new KernelException( UnknownError, "Hello" ) { }, false ); JsonNode out = serialize( rep ); assertThat(out.get("errors").get(0).get("code").asText(), equalTo("Neo.DatabaseError.General.UnknownError")); assertThat(out.get("errors").get(0).get("message").asText(), equalTo("Hello")); assertThat(out.has( "message" ), equalTo(false)); }