|
1 | 1 | package com.mapbox.api.directions.v5.models;
|
2 | 2 |
|
| 3 | +import androidx.annotation.NonNull; |
3 | 4 | import com.google.gson.Gson;
|
4 | 5 | import com.google.gson.GsonBuilder;
|
5 | 6 | import com.google.gson.JsonElement;
|
|
11 | 12 |
|
12 | 13 | import java.io.IOException;
|
13 | 14 | import java.nio.ByteBuffer;
|
| 15 | +import java.nio.charset.Charset; |
14 | 16 | import java.nio.charset.StandardCharsets;
|
15 | 17 | import java.util.Arrays;
|
16 | 18 | import java.util.Collections;
|
@@ -87,13 +89,21 @@ public void fromJson_correctlyBuildsFromJson() throws Exception {
|
87 | 89 |
|
88 | 90 | @Test
|
89 | 91 | public void deserialization_from_byte_buffer() throws Exception {
|
90 |
| - byte[] json = loadJsonFixture(DIRECTIONS_V5_PRECISION6_FIXTURE).getBytes(StandardCharsets.UTF_8); |
| 92 | + String textJson = loadJsonFixture(DIRECTIONS_V5_PRECISION6_FIXTURE); |
| 93 | + ByteBuffer buffer = putTextToDirectByteBuffer(textJson, StandardCharsets.UTF_8); |
| 94 | + |
| 95 | + DirectionsResponse responseFromBuffer = DirectionsResponse.fromJson(buffer, StandardCharsets.UTF_8); |
| 96 | + DirectionsResponse responseFromText = DirectionsResponse.fromJson(textJson); |
| 97 | + |
| 98 | + assertEquals(responseFromText, responseFromBuffer); |
| 99 | + } |
| 100 | + |
| 101 | + @NonNull private ByteBuffer putTextToDirectByteBuffer(String textJson, Charset charset) { |
| 102 | + byte[] json = textJson.getBytes(charset); |
91 | 103 | ByteBuffer buffer = ByteBuffer.allocateDirect(json.length);
|
92 | 104 | buffer.put(json);
|
93 | 105 | buffer.position(0);
|
94 |
| - DirectionsResponse response = DirectionsResponse.fromJson(buffer, StandardCharsets.UTF_8); |
95 |
| - assertNotNull(response); |
96 |
| - assertEquals(1, response.routes().size()); |
| 106 | + return buffer; |
97 | 107 | }
|
98 | 108 |
|
99 | 109 | @Test
|
|
0 commit comments