Skip to content

Commit 3bca38d

Browse files
committed
Fix tests
Signed-off-by: Taylor Smock <tsmock@meta.com>
1 parent 9b7d424 commit 3bca38d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/main/java/org/openstreetmap/josm/plugins/mapwithai/tools/MapPaintUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ public static synchronized void addSourcesToPaintStyle(DataSet ds) {
160160
return;
161161
}
162162
List<String> sources = ds.allPrimitives().stream().map(MapPaintUtils::getSourceValue).filter(Objects::nonNull)
163-
.map(s -> s.replace('.', '_'))
164-
.distinct().collect(Collectors.toList());
163+
.map(s -> s.replace('.', '_')).distinct().collect(Collectors.toList());
165164
if (!styleSource.isLoaded()) {
166165
styleSource.loadStyleSource();
167166
}

src/test/unit/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReaderTest.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.junit.jupiter.api.Assertions.assertNotNull;
66

77
import java.io.IOException;
8+
import java.io.StringReader;
89
import java.util.Collections;
910
import java.util.List;
1011

@@ -20,6 +21,7 @@
2021
import jakarta.json.JsonArrayBuilder;
2122
import jakarta.json.JsonObjectBuilder;
2223
import jakarta.json.JsonValue;
24+
import jakarta.json.stream.JsonParser;
2325

2426
@BasicPreferences
2527
@Territories
@@ -29,8 +31,12 @@ class MapWithAISourceReaderTest {
2931
void testParseSimple() throws IOException {
3032
JsonObjectBuilder builder = Json.createObjectBuilder();
3133
builder.add("nowhere", JsonValue.NULL);
32-
try (var reader = new MapWithAISourceReader("")) {
33-
List<MapWithAIInfo> infoList = reader.parseJson(builder.build());
34+
final String json = builder.build().toString();
35+
try (var reader = new MapWithAISourceReader("");
36+
StringReader sr = new java.io.StringReader(json);
37+
JsonParser parser = Json.createParser(sr)) {
38+
parser.next();
39+
List<MapWithAIInfo> infoList = reader.parseJson(parser);
3440
assertEquals(1, infoList.size());
3541
assertEquals("nowhere", infoList.get(0).getName());
3642
}
@@ -45,9 +51,12 @@ void testParseComplex() throws IOException {
4551
JsonArrayBuilder coCountriesArray = Json.createArrayBuilder(Collections.singleton("addr:housenumber"));
4652
coCountries.add("US-CO", coCountriesArray.build());
4753
co.add("countries", coCountries.build());
48-
builder.add("Colorado", co);
49-
try (var reader = new MapWithAISourceReader("")) {
50-
List<MapWithAIInfo> infoList = reader.parseJson(builder.build());
54+
String json = builder.add("Colorado", co).build().toString();
55+
try (var reader = new MapWithAISourceReader("");
56+
StringReader sr = new StringReader(json);
57+
JsonParser parser = Json.createParser(sr)) {
58+
parser.next();
59+
List<MapWithAIInfo> infoList = reader.parseJson(parser);
5160
assertEquals(1, infoList.size());
5261
MapWithAIInfo info = infoList.stream().filter(i -> "Colorado".equals(i.getName())).findFirst().orElse(null);
5362
assertNotNull(info);

0 commit comments

Comments
 (0)