|
36 | 36 | import org.junit.Test;
|
37 | 37 |
|
38 | 38 | import com.google.gson.JsonArray;
|
| 39 | +import com.google.gson.JsonIOException; |
39 | 40 | import com.google.gson.JsonObject;
|
40 | 41 | import com.google.gson.reflect.TypeToken;
|
41 | 42 |
|
@@ -153,7 +154,41 @@ public void testSerializeImmutableList() {
|
153 | 154 | String json = handler.serialize(message);
|
154 | 155 | Assert.assertEquals("{\"jsonrpc\":\"2.0\",\"method\":\"foo\",\"params\":[\"a\",\"b\"]}", json);
|
155 | 156 | }
|
156 |
| - |
| 157 | + |
| 158 | + @Test |
| 159 | + public void testMessageToString() { |
| 160 | + NotificationMessage message = new NotificationMessage(); |
| 161 | + message.setMethod("foo"); |
| 162 | + List<Object> list = new ArrayList<>(); |
| 163 | + list.add("a"); |
| 164 | + list.add("b"); |
| 165 | + message.setParams(list); |
| 166 | + Assert.assertEquals("{\n" |
| 167 | + + " \"jsonrpc\": \"2.0\",\n" |
| 168 | + + " \"method\": \"foo\",\n" |
| 169 | + + " \"params\": [\n" |
| 170 | + + " \"a\",\n" |
| 171 | + + " \"b\"\n" |
| 172 | + + " ]\n" |
| 173 | + + "}", message.toString()); |
| 174 | + |
| 175 | + MessageJsonHandler handler = new MessageJsonHandler(Collections.emptyMap()) { |
| 176 | + @Override |
| 177 | + public String format(Object object) { |
| 178 | + throw new JsonIOException("TEST"); |
| 179 | + }; |
| 180 | + }; |
| 181 | + message.setJsonHandler(handler); |
| 182 | + Assert.assertEquals("NotificationMessage [\n" |
| 183 | + + " method = \"foo\"\n" |
| 184 | + + " params = ArrayList (\n" |
| 185 | + + " \"a\",\n" |
| 186 | + + " \"b\"\n" |
| 187 | + + " )\n" |
| 188 | + + " jsonrpc = \"2.0\"\n" |
| 189 | + + "]", message.toString()); |
| 190 | + } |
| 191 | + |
157 | 192 | @SuppressWarnings({ "unchecked" })
|
158 | 193 | @Test
|
159 | 194 | public void testEither_01() {
|
|
0 commit comments