From 3bca38d512869545bd67ea39a4cd1c3a4eb3c776 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Mon, 11 Nov 2024 08:27:09 -0700 Subject: [PATCH] Fix tests Signed-off-by: Taylor Smock --- .../mapwithai/tools/MapPaintUtils.java | 3 +-- .../mapwithai/MapWithAISourceReaderTest.java | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/tools/MapPaintUtils.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/tools/MapPaintUtils.java index 439569eb..db47919b 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/tools/MapPaintUtils.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/tools/MapPaintUtils.java @@ -160,8 +160,7 @@ public static synchronized void addSourcesToPaintStyle(DataSet ds) { return; } List sources = ds.allPrimitives().stream().map(MapPaintUtils::getSourceValue).filter(Objects::nonNull) - .map(s -> s.replace('.', '_')) - .distinct().collect(Collectors.toList()); + .map(s -> s.replace('.', '_')).distinct().collect(Collectors.toList()); if (!styleSource.isLoaded()) { styleSource.loadStyleSource(); } diff --git a/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReaderTest.java b/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReaderTest.java index 92db3303..132c51cf 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReaderTest.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReaderTest.java @@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; +import java.io.StringReader; import java.util.Collections; import java.util.List; @@ -20,6 +21,7 @@ import jakarta.json.JsonArrayBuilder; import jakarta.json.JsonObjectBuilder; import jakarta.json.JsonValue; +import jakarta.json.stream.JsonParser; @BasicPreferences @Territories @@ -29,8 +31,12 @@ class MapWithAISourceReaderTest { void testParseSimple() throws IOException { JsonObjectBuilder builder = Json.createObjectBuilder(); builder.add("nowhere", JsonValue.NULL); - try (var reader = new MapWithAISourceReader("")) { - List infoList = reader.parseJson(builder.build()); + final String json = builder.build().toString(); + try (var reader = new MapWithAISourceReader(""); + StringReader sr = new java.io.StringReader(json); + JsonParser parser = Json.createParser(sr)) { + parser.next(); + List infoList = reader.parseJson(parser); assertEquals(1, infoList.size()); assertEquals("nowhere", infoList.get(0).getName()); } @@ -45,9 +51,12 @@ void testParseComplex() throws IOException { JsonArrayBuilder coCountriesArray = Json.createArrayBuilder(Collections.singleton("addr:housenumber")); coCountries.add("US-CO", coCountriesArray.build()); co.add("countries", coCountries.build()); - builder.add("Colorado", co); - try (var reader = new MapWithAISourceReader("")) { - List infoList = reader.parseJson(builder.build()); + String json = builder.add("Colorado", co).build().toString(); + try (var reader = new MapWithAISourceReader(""); + StringReader sr = new StringReader(json); + JsonParser parser = Json.createParser(sr)) { + parser.next(); + List infoList = reader.parseJson(parser); assertEquals(1, infoList.size()); MapWithAIInfo info = infoList.stream().filter(i -> "Colorado".equals(i.getName())).findFirst().orElse(null); assertNotNull(info);