Skip to content

Commit 12045b9

Browse files
committed
Fix isolation in tests, so that they do not leave gobale toggle on, fix JSON parser map length
Signed-off-by: Alexander Lowey-Weber <alexander.weber@here.com>
1 parent a582687 commit 12045b9

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

here-naksha-lib-base/src/jvmMain/java/naksha/base/JsonMap.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ public <T> JsonMap(@Nullable T @NotNull [] entries, int fromIndex, int toIndex)
117117
* @see #wrap(Object[], int)
118118
*/
119119
public <T> JsonMap(@Nullable T @NotNull [] entries, int fromIndex, int toIndex, boolean intern) {
120-
int length = toIndex - fromIndex;
121-
if (length < 0 || length > entries.length || (length & 1) == 1) throw new IllegalArgumentException("Invalid entries array");
120+
final int size = toIndex - fromIndex;
121+
if (size < 0 || size > entries.length || (size & 1) == 1) throw new IllegalArgumentException("Invalid entries array");
122+
int length = size >> 1;
122123

123124
assert fromIndex >= 0 && fromIndex <= toIndex && toIndex <= entries.length;
124125
if (!intern) {

here-naksha-lib-base/src/jvmTest/java/naksha/base/JsonMapTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static org.junit.jupiter.api.Assertions.*;
77

88
public class JsonMapTest {
9+
910
@Test
1011
public void test_map_entry_set() {
1112
final JsonMap map = new JsonMap();
@@ -45,12 +46,17 @@ public void test_map_entry_set() {
4546
}
4647

4748
@Test
48-
public void parserTest() {
49+
public void parserTest() {
50+
final var newJsonParserEnabled = Platform.PlatformCompanion.useNewJson();
51+
Platform.PlatformCompanion.enableNewJsonParser();
52+
try {
4953
final String json = "{\"type\":\"Feature\",\"momType\":\"Topology\",\"id\":\"urn:here::ipc:Topology:12345\",\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[45.0,45.0],[45.0,46.0]]},\"properties\":{\"startNodeId\":\"So long, and thanks for all the fish.\",\"endNodeId\":\"So long, and thanks for all the fish.\",\"leftAdmin\":[{\"range\":{\"endOffset\":1.0,\"startOffset\":0.0},\"value\":{\"id\":\"urn:here::here:admin:82928227\"}}]}}";
50-
Platform.PlatformCompanion.enableNewJsonParser();
5154
Object o = Platform.fromJSON(json);
5255
assertInstanceOf(JvmMap.class, o);
5356
var jvmMap = (JvmMap) o;
5457
assertTrue(jvmMap.containsKey("properties"));
58+
} finally {
59+
if (!newJsonParserEnabled) Platform.PlatformCompanion.disableNewJsonParser();
60+
}
5561
}
5662
}

0 commit comments

Comments
 (0)