RoutingProcedureResponse { public Throwable error() { if ( isSuccess() ) { throw new IllegalStateException( "Can't access error of a succeeded result " + records ); } return error; } RoutingProcedureResponse(Query procedure, List<Record> records );  RoutingProcedureResponse(Query procedure, Throwable error ); private  RoutingProcedureResponse(Query procedure, List<Record> records, Throwable error ); boolean isSuccess(); Query procedure(); List<Record> records(); Throwable error();  }
@Test void shouldHaveErrorWhenFailed() { RuntimeException error = new RuntimeException( "Hi!" ); RoutingProcedureResponse response = new RoutingProcedureResponse( PROCEDURE, error ); assertEquals( error, response.error() ); }