Skip to content

Commit 392150d

Browse files
committed
improve test
1 parent 3f43a57 commit 392150d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

services-directions-models/src/test/java/com/mapbox/api/directions/v5/models/DirectionsResponseTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mapbox.api.directions.v5.models;
22

3+
import androidx.annotation.NonNull;
34
import com.google.gson.Gson;
45
import com.google.gson.GsonBuilder;
56
import com.google.gson.JsonElement;
@@ -11,6 +12,7 @@
1112

1213
import java.io.IOException;
1314
import java.nio.ByteBuffer;
15+
import java.nio.charset.Charset;
1416
import java.nio.charset.StandardCharsets;
1517
import java.util.Arrays;
1618
import java.util.Collections;
@@ -87,13 +89,21 @@ public void fromJson_correctlyBuildsFromJson() throws Exception {
8789

8890
@Test
8991
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);
91103
ByteBuffer buffer = ByteBuffer.allocateDirect(json.length);
92104
buffer.put(json);
93105
buffer.position(0);
94-
DirectionsResponse response = DirectionsResponse.fromJson(buffer, StandardCharsets.UTF_8);
95-
assertNotNull(response);
96-
assertEquals(1, response.routes().size());
106+
return buffer;
97107
}
98108

99109
@Test

0 commit comments

Comments
 (0)