|
8 | 8 | package org.eclipse.lsp4j.jsonrpc.test.json;
|
9 | 9 |
|
10 | 10 | import java.util.Arrays;
|
11 |
| -import java.util.HashMap; |
| 11 | +import java.util.Collections; |
12 | 12 | import java.util.HashSet;
|
13 | 13 | import java.util.LinkedHashMap;
|
14 | 14 | import java.util.List;
|
|
22 | 22 | import org.eclipse.lsp4j.jsonrpc.messages.Message;
|
23 | 23 | import org.eclipse.lsp4j.jsonrpc.messages.NotificationMessage;
|
24 | 24 | import org.eclipse.lsp4j.jsonrpc.messages.RequestMessage;
|
| 25 | +import org.eclipse.lsp4j.jsonrpc.messages.ResponseError; |
25 | 26 | import org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage;
|
26 | 27 | import org.junit.Assert;
|
27 | 28 | import org.junit.Test;
|
@@ -522,6 +523,26 @@ public void testEnumParam() {
|
522 | 523 | parameters);
|
523 | 524 | }
|
524 | 525 |
|
| 526 | + @Test |
| 527 | + public void testResponseErrorData() { |
| 528 | + MessageJsonHandler handler = new MessageJsonHandler(Collections.emptyMap()); |
| 529 | + ResponseMessage message = (ResponseMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," |
| 530 | + + "\"id\":\"2\",\n" |
| 531 | + + "\"error\": { \"code\": -32001, \"message\": \"foo\",\n" |
| 532 | + + " \"data\": { \"uri\": \"file:/foo\", \"version\": 5, \"list\": [\"a\", \"b\", \"c\"] }\n" |
| 533 | + + " }\n" |
| 534 | + + "}"); |
| 535 | + ResponseError error = message.getError(); |
| 536 | + Assert.assertTrue("Expected a JsonObject in error.data", error.getData() instanceof JsonObject); |
| 537 | + JsonObject data = (JsonObject) error.getData(); |
| 538 | + Assert.assertEquals("file:/foo", data.get("uri").getAsString()); |
| 539 | + Assert.assertEquals(5, data.get("version").getAsInt()); |
| 540 | + JsonArray list = data.get("list").getAsJsonArray(); |
| 541 | + Assert.assertEquals("a", list.get(0).getAsString()); |
| 542 | + Assert.assertEquals("b", list.get(1).getAsString()); |
| 543 | + Assert.assertEquals("c", list.get(2).getAsString()); |
| 544 | + } |
| 545 | + |
525 | 546 | public static final <T> void swap(T[] a, int i, int j) {
|
526 | 547 | T t = a[i];
|
527 | 548 | a[i] = a[j];
|
@@ -652,8 +673,8 @@ public void testErrorResponse_AllOrders() {
|
652 | 673 | ResponseMessage message = (ResponseMessage) handler.parseMessage(json);
|
653 | 674 | Assert.assertEquals("failed", message.getError().getMessage());
|
654 | 675 | Object data = message.getError().getData();
|
655 |
| - Map<String, String> expected = new HashMap<>(); |
656 |
| - expected.put("uri", "failed"); |
| 676 | + JsonObject expected = new JsonObject(); |
| 677 | + expected.addProperty("uri", "failed"); |
657 | 678 | Assert.assertEquals(expected, data);
|
658 | 679 | Assert.assertNull(message.getResult());
|
659 | 680 | });
|
|
0 commit comments