### Question:
ExecutionErrorsService { public JsonArray toJsonErrors(List<GraphQLError> errors) { JsonArrayBuilder arrayBuilder = jsonBuilderFactory.createArrayBuilder(); for (GraphQLError e : errors) { arrayBuilder.add(toJsonError(e)); } return arrayBuilder.build(); }  JsonArray toJsonErrors(List<GraphQLError> errors);  }### Answer:
@Test void testToJsonErrors_WhenExceptionWhileDataFetchingErrorCaught_ShouldReturnJsonBodyWithCustomExtensions() { Map<String, Object> extensions = new HashMap<>(); extensions.put("code", "OPERATION_FAILED"); GraphqlErrorException graphqlErrorException = GraphqlErrorException.newErrorException() .extensions(extensions) .build(); ExceptionWhileDataFetching exceptionWhileDataFetching = new ExceptionWhileDataFetching(ExecutionPath.rootPath(), graphqlErrorException, new SourceLocation(1, 1)); JsonArray jsonArray = executionErrorsService.toJsonErrors(singletonList(exceptionWhileDataFetching)); JsonObject extensionJsonObject = jsonArray.getJsonObject(0).getJsonObject("extensions"); assertThat(extensionJsonObject.getString("exception")).isEqualTo("graphql.GraphqlErrorException"); assertThat(extensionJsonObject.getString("classification")).isEqualTo("DataFetchingException"); assertThat(extensionJsonObject.getString("code")).isEqualTo("OPERATION_FAILED"); }
@Test void testToJsonErrors_WhenExceptionWhileValidationErrorCaught_ShouldReturnJsonBodyWithCustomExtensions() { Map<String, Object> extensions = new HashMap<>(); extensions.put("code", "OPERATION_FAILED"); ValidationError validationError = ValidationError.newValidationError() .validationErrorType(ValidationErrorType.UnknownDirective) .description("TestDescription") .queryPath(singletonList("Test-Path")) .extensions(extensions) .build(); JsonArray jsonArray = executionErrorsService.toJsonErrors(singletonList(validationError)); JsonObject extensionJsonObject = jsonArray.getJsonObject(0).getJsonObject("extensions"); assertThat(extensionJsonObject.getString("description")).isEqualTo("TestDescription"); assertThat(extensionJsonObject.getString("validationErrorType")).isEqualTo("UnknownDirective"); assertThat(extensionJsonObject.getJsonArray("queryPath").getString(0)).isEqualTo("Test-Path"); assertThat(extensionJsonObject.getString("classification")).isEqualTo("ValidationError"); assertThat(extensionJsonObject.getString("code")).isEqualTo("OPERATION_FAILED"); }