source: josm/trunk/test/unit/org/openstreetmap/josm/data/imagery/vectortile/mapbox/style/ExpressionTest.java@ 18723

Last change on this file since 18723 was 18723, checked in by taylor.smock, 13 months ago

Fix #22432, see #22941: Start migrating from javax to jakarta

Parsson was split out from the JSONP repository in 2021 (see
https://github.com/jakartaee/jsonp-api/issues/285 ). It is the default provider,
and will "just work" without additional configuration.

Many plugins use javax.json, so the scheduled removal of the javax.json
dependencies is set to milestone:"24.12" (see #22941).

Changes between javax.json and jakarta.json 2.0:

  • Rename of javax.json to jakarta.json
  • Some additional bug fixes

This will enable us to move easily to jakarta.json 2.1 in the future.
The changes of note with 2.1 includes:

  • Better handling of duplicated keys
  • Additional APIs around primitive types
  • API to get current event from JsonParser

We cannot currently move to jakarta.json 2.1 since it requires Java 11+.

File size: 2.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.imagery.vectortile.mapbox.style;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5
6
7import jakarta.json.Json;
8import jakarta.json.JsonValue;
9
10import nl.jqno.equalsverifier.EqualsVerifier;
11import org.junit.jupiter.api.Test;
12
13/**
14 * Test class for {@link Expression}
15 * @author Taylor Smock
16 * @since 17862
17 */
18class ExpressionTest {
19 @Test
20 void testInvalidJson() {
21 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(JsonValue.NULL));
22 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(JsonValue.FALSE));
23 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(JsonValue.TRUE));
24 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(JsonValue.EMPTY_JSON_OBJECT));
25 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(JsonValue.EMPTY_JSON_ARRAY));
26 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(Json.createObjectBuilder().add("bad", "value").build()));
27 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(Json.createValue(1)));
28 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(Json.createValue(1.0)));
29 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(Json.createValue("bad string")));
30 }
31
32 @Test
33 void testBasicExpressions() {
34 // "filter": [ "==|>=|<=|<|>", "key", "value" ]
35 assertEquals("[key=value]", new Expression(Json.createArrayBuilder().add("==").add("key").add("value").build()).toString());
36 assertEquals("[key>=true]", new Expression(Json.createArrayBuilder().add(">=").add("key").add(true).build()).toString());
37 assertEquals("[key<=false]", new Expression(Json.createArrayBuilder().add("<=").add("key").add(false).build()).toString());
38 assertEquals("[key<1]", new Expression(Json.createArrayBuilder().add("<").add("key").add(1).build()).toString());
39 assertEquals("[key>2.5]", new Expression(Json.createArrayBuilder().add(">").add("key").add(2.5).build()).toString());
40 // Test bad expression
41 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(Json.createArrayBuilder().add(">>").add("key").add("value").build()));
42
43 // Test expressions with a subarray and object. This is expected to fail when properly supported, so it should be fixed.
44 assertEquals("[key=[{bad:value}]]", new Expression(Json.createArrayBuilder().add("==").add("key").add(
45 Json.createArrayBuilder().add(Json.createObjectBuilder().add("bad", "value"))).build()).toString());
46 assertEquals("[key=]", new Expression(Json.createArrayBuilder().add("==").add("key").add(JsonValue.NULL).build()).toString());
47 }
48
49 @Test
50 void testEquals() {
51 EqualsVerifier.forClass(Expression.class).verify();
52 }
53}
Note: See TracBrowser for help on using the repository browser.