diff --git a/.github/workflows/ant-manual.yml b/.github/workflows/ant-manual.yml index 2088b87..8237c6f 100644 --- a/.github/workflows/ant-manual.yml +++ b/.github/workflows/ant-manual.yml @@ -4,7 +4,7 @@ on: workflow_dispatch jobs: call-workflow: - uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1 + uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v2 with: java-version: 17 diff --git a/.github/workflows/ant.yml b/.github/workflows/ant.yml index a472501..7d0c9f3 100644 --- a/.github/workflows/ant.yml +++ b/.github/workflows/ant.yml @@ -21,7 +21,7 @@ jobs: release_needed: ${{ steps.create_release_needed.outputs.release_needed }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: ${{ (github.repository == 'JOSM/MapRoulette' && github.ref_type == 'branch' && github.ref_name == 'master' && github.event_name != 'schedule' && github.event_name != 'pull_request') && '0' || '1' }} @@ -44,7 +44,7 @@ jobs: strategy: matrix: josm-revision: ["", "r18877"] - uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1 + uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v2 with: josm-revision: ${{ matrix.josm-revision }} java-version: 17 diff --git a/.github/workflows/reports.yaml b/.github/workflows/reports.yaml index e96588c..43794f4 100644 --- a/.github/workflows/reports.yaml +++ b/.github/workflows/reports.yaml @@ -10,4 +10,4 @@ permissions: jobs: call-workflow: - uses: JOSM/JOSMPluginAction/.github/workflows/reports.yaml@v1 + uses: JOSM/JOSMPluginAction/.github/workflows/reports.yaml@v2 diff --git a/build.xml b/build.xml index ff5953b..2d5fb98 100644 --- a/build.xml +++ b/build.xml @@ -1,5 +1,5 @@ - + @@ -20,7 +20,33 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ivy.xml b/ivy.xml deleted file mode 100644 index 8c57f07..0000000 --- a/ivy.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index e489009..414594e 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ org.openstreetmap.josm josm - 18511 + 18905 provided @@ -27,21 +27,21 @@ test - com.github.tomakehurst - wiremock-jre8 - 2.35.0 + org.wiremock + wiremock + 3.6.0 test org.junit.jupiter junit-jupiter-api - 5.9.2 + 5.10.2 test org.junit.jupiter junit-jupiter-params - 5.9.2 + 5.10.2 test @@ -50,28 +50,22 @@ 1.49.a test - - com.google.code.findbugs - jsr305 - 3.0.2 - provided - org.apache.commons commons-jcs3-core - 3.1 + 3.2 provided - javax.json - javax.json-api - 1.1.4 + jakarta.json + jakarta.json-api + 2.1.3 provided org.commonmark commonmark - 0.21.0 + 0.22.0 compile @@ -80,7 +74,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.10.1 + 3.13.0 17 @@ -88,11 +82,11 @@ com.diffplug.spotless spotless-maven-plugin - 2.30.0 + 2.43.0 - 4.21.0 + 4.21 ${project.basedir}/../00_core_tools/eclipse/formatter.xml @@ -109,6 +103,29 @@ + + org.apache.maven.plugins + maven-enforcer-plugin + 3.4.1 + + + enforce-versions + + enforce + + + + + 3.6.3 + + + 17 + + + + + + \ No newline at end of file diff --git a/src/main/java/org/openstreetmap/josm/plugins/maproulette/actions/downloadtasks/MapRouletteDownloadTaskBox.java b/src/main/java/org/openstreetmap/josm/plugins/maproulette/actions/downloadtasks/MapRouletteDownloadTaskBox.java index 1293413..1235499 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/maproulette/actions/downloadtasks/MapRouletteDownloadTaskBox.java +++ b/src/main/java/org/openstreetmap/josm/plugins/maproulette/actions/downloadtasks/MapRouletteDownloadTaskBox.java @@ -27,6 +27,7 @@ import org.openstreetmap.josm.gui.progress.ProgressMonitor; import org.openstreetmap.josm.gui.progress.ProgressTaskId; import org.openstreetmap.josm.gui.util.GuiHelper; +import org.openstreetmap.josm.io.OsmApiException; import org.openstreetmap.josm.io.OsmTransferException; import org.openstreetmap.josm.plugins.maproulette.api.TaskAPI; import org.openstreetmap.josm.plugins.maproulette.api.UnauthorizedException; @@ -108,7 +109,7 @@ protected void realRun() throws IOException, OsmTransferException { } }); // This is specifically so that user's don't get a bug report message - final var transferException = new OsmTransferException(unauthorizedException); + final var transferException = new OsmApiException(unauthorizedException); transferException.setUrl(MapRouletteConfig.getBaseUrl()); throw transferException; } catch (IOException e) { diff --git a/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/BundleAPI.java b/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/BundleAPI.java index c9d4d2f..f0d3b38 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/BundleAPI.java +++ b/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/BundleAPI.java @@ -84,9 +84,10 @@ public static TaskBundle parseBundle(InputStream bundle) { * * @param id The id of the bundle to get * @return The specified bundle + * @throws UnauthorizedException if the user hasn't logged in to MapRoulette */ @Nonnull - public static TaskBundle getBundle(long id) { + public static TaskBundle getBundle(long id) throws UnauthorizedException { final var client = get(getBaseUrl() + PATH + "/" + id); try { try (var inputStream = client.connect().getContent()) { @@ -104,8 +105,9 @@ public static TaskBundle getBundle(long id) { * * @param id The bundle to delete * @return {@code true} if the deletion was successful + * @throws UnauthorizedException if the user hasn't logged in to MapRoulette */ - public static boolean deleteBundle(long id) { + public static boolean deleteBundle(long id) throws UnauthorizedException { final var client = delete(getBaseUrl() + PATH + "/" + id); try { int responseCode = client.connect().getResponseCode(); @@ -126,9 +128,10 @@ public static boolean deleteBundle(long id) { * @param original The original bundle * @param taskIds The tasks to remove * @return The new bundle + * @throws UnauthorizedException if the user hasn't logged in to MapRoulette */ @Nonnull - public static TaskBundle unbundle(TaskBundle original, long... taskIds) { + public static TaskBundle unbundle(TaskBundle original, long... taskIds) throws UnauthorizedException { final var client = get(getBaseUrl() + PATH + "/" + original.id() + "/unbundle", Map.of("taskIds", LongStream.of(taskIds).mapToObj(Long::toString).collect(Collectors.joining(",")))); try { diff --git a/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/UnauthorizedException.java b/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/UnauthorizedException.java index deccb8e..e5d2c37 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/UnauthorizedException.java +++ b/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/UnauthorizedException.java @@ -1,12 +1,13 @@ // License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.maproulette.api; +import java.io.IOException; import java.io.Serial; /** * Thrown if the user is not authorized for the specified operation */ -public class UnauthorizedException extends RuntimeException { +public class UnauthorizedException extends IOException { /** * The serial UID for this exception */ diff --git a/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/parsers/TaskParser.java b/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/parsers/TaskParser.java index dab46aa..ae7eb9e 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/parsers/TaskParser.java +++ b/src/main/java/org/openstreetmap/josm/plugins/maproulette/api/parsers/TaskParser.java @@ -7,6 +7,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.ArrayList; @@ -20,6 +21,7 @@ import org.openstreetmap.josm.gui.progress.NullProgressMonitor; import org.openstreetmap.josm.io.IllegalDataException; import org.openstreetmap.josm.io.OsmChangeReader; +import org.openstreetmap.josm.plugins.maproulette.api.UnauthorizedException; import org.openstreetmap.josm.plugins.maproulette.api.enums.TaskStatus; import org.openstreetmap.josm.plugins.maproulette.api.model.ElementCreate; import org.openstreetmap.josm.plugins.maproulette.api.model.ElementTagChange; @@ -61,21 +63,33 @@ private TaskParser() { * * @param inputStream the stream to get the task from * @return The new task. May be a singular task or an array of tasks. + * @throws UnauthorizedException if the user hasn't logged in to MapRoulette */ @Nonnull - public static Object parseTask(InputStream inputStream) { + public static Object parseTask(InputStream inputStream) throws UnauthorizedException { try (var reader = Json.createParser(inputStream)) { while (reader.hasNext()) { var value = switch (reader.next()) { case START_OBJECT -> parseTask(reader.getObject()); case START_ARRAY -> reader.getArrayStream().filter(JsonObject.class::isInstance) - .map(JsonObject.class::cast).map(TaskParser::parseTask).toArray(Task[]::new); + .map(JsonObject.class::cast).map(obj -> { + try { + return parseTask(obj); + } catch (UnauthorizedException e) { + throw new UncheckedIOException(e); + } + }).toArray(Task[]::new); default -> null; }; if (value != null) { return value; } } + } catch (UncheckedIOException e) { + if (e.getCause()instanceof UnauthorizedException unauthorizedException) { + throw unauthorizedException; + } + throw e; } throw new IllegalArgumentException("InputStream did not contain expected JSON data"); } @@ -85,9 +99,10 @@ public static Object parseTask(InputStream inputStream) { * * @param obj the JsonObject to get the task from * @return The new task + * @throws UnauthorizedException if the user hasn't logged in to MapRoulette */ @Nonnull - private static Task parseTask(JsonObject obj) { + private static Task parseTask(JsonObject obj) throws UnauthorizedException { MessageParser.parse(obj); try { return new Task(obj.getJsonNumber("id").longValue(), obj.getString("name"), diff --git a/src/main/java/org/openstreetmap/josm/plugins/maproulette/data/HiddenList.java b/src/main/java/org/openstreetmap/josm/plugins/maproulette/data/HiddenList.java new file mode 100644 index 0000000..90011c0 --- /dev/null +++ b/src/main/java/org/openstreetmap/josm/plugins/maproulette/data/HiddenList.java @@ -0,0 +1,59 @@ +// License: GPL. For details, see LICENSE file. +package org.openstreetmap.josm.plugins.maproulette.data; + +import java.util.Arrays; +import java.util.function.LongPredicate; + +/** + * Hidden tasks from filters + */ +public final class HiddenList { + private static LongPredicate[] tests = new LongPredicate[0]; + private static long[] hidden = new long[0]; + + private HiddenList() { + // Hide constructor + } + + /** + * Update the hidden list + * @param ids The ids to use + */ + public static void update(long... ids) { + final var t = tests; + final var tIds = new long[ids.length]; + int count = 0; + for (long id : ids) { + for (LongPredicate test : t) { + if (test.test(id)) { + tIds[count++] = id; + break; + } + } + } + var h = Arrays.copyOf(tIds, count); + Arrays.sort(h); + hidden = h; + } + + /** + * Add a function to use for checking whether a task is hidden + * @param checkFunction The function to use; a return of {@code true} means that the task should be hidden. + */ + public static void addListUpdater(LongPredicate checkFunction) { + synchronized (HiddenList.class) { + var t = Arrays.copyOf(tests, tests.length + 1); + t[t.length - 1] = checkFunction; + tests = t; + } + } + + /** + * Check if an id is hidden + * @param id The id to check + * @return {@code true} if the id is hidden + */ + public static boolean isHidden(long id) { + return Arrays.binarySearch(hidden, id) >= 0; + } +} diff --git a/src/main/java/org/openstreetmap/josm/plugins/maproulette/data/IgnoreList.java b/src/main/java/org/openstreetmap/josm/plugins/maproulette/data/IgnoreList.java index e246c6b..b5adf04 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/maproulette/data/IgnoreList.java +++ b/src/main/java/org/openstreetmap/josm/plugins/maproulette/data/IgnoreList.java @@ -17,11 +17,11 @@ public final class IgnoreList { /** * The ignored tasks */ - private static long[] ignoredTasks = convertList(Config.getPref().getList("mapillary.ignore.tasks")); + private static long[] ignoredTasks = convertList(Config.getPref().getList("maproulette.ignore.tasks")); /** * The ignored challenges */ - private static long[] ignoredChallenges = convertList(Config.getPref().getList("mapillary.ignore.challenges")); + private static long[] ignoredChallenges = convertList(Config.getPref().getList("maproulette.ignore.challenges")); /** * {@code true} if a save is required */ @@ -96,8 +96,8 @@ private static synchronized void save() { final var tasks = ignoredTasks; final var challenges = ignoredChallenges; if (doSave) { - Config.getPref().putList("mapillary.ignore.tasks", convertList(tasks)); - Config.getPref().putList("mapillary.ignore.challenges", convertList(challenges)); + Config.getPref().putList("maproulette.ignore.tasks", convertList(tasks)); + Config.getPref().putList("maproulette.ignore.challenges", convertList(challenges)); } } diff --git a/src/main/java/org/openstreetmap/josm/plugins/maproulette/gui/layer/MapRouletteClusteredPointLayer.java b/src/main/java/org/openstreetmap/josm/plugins/maproulette/gui/layer/MapRouletteClusteredPointLayer.java index 03e756c..537b875 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/maproulette/gui/layer/MapRouletteClusteredPointLayer.java +++ b/src/main/java/org/openstreetmap/josm/plugins/maproulette/gui/layer/MapRouletteClusteredPointLayer.java @@ -52,6 +52,7 @@ import org.openstreetmap.josm.plugins.maproulette.api.model.Task; import org.openstreetmap.josm.plugins.maproulette.api.model.TaskClusteredPoint; import org.openstreetmap.josm.plugins.maproulette.api_caching.TaskCache; +import org.openstreetmap.josm.plugins.maproulette.data.HiddenList; import org.openstreetmap.josm.plugins.maproulette.gui.ModifiedObjects; import org.openstreetmap.josm.plugins.maproulette.gui.task.list.TaskListPanel; import org.openstreetmap.josm.plugins.maproulette.io.upload.LateUploadHook; @@ -199,8 +200,9 @@ public void paint(Graphics2D g, MapView mv, Bounds bounds) { final var painter = new StyledMapRenderer(g, mv, false); final var mrColor = LOCKED_TASK_COLOR.get(); final var mrColorOpacity = new Color(mrColor.getRed(), mrColor.getGreen(), mrColor.getBlue(), 128); + final var taskListPanel = MainApplication.getMap().getToggleDialog(TaskListPanel.class); - final var listSelected = MainApplication.getMap().getToggleDialog(TaskListPanel.class).getSelected(); + final var listSelected = taskListPanel.getSelected(); painter.enableSlowOperations(mv.getMapMover() == null || !mv.getMapMover().movementInProgress() || !PROPERTY_HIDE_LABELS_WHILE_DRAGGING.get()); @@ -214,7 +216,8 @@ public void paint(Graphics2D g, MapView mv, Bounds bounds) { final var statusSymbol = new Symbol(SymbolShape.SQUARE, 25, null, fixedColor, fixedColor); final var disabledStatusSymbol = new Symbol(SymbolShape.SQUARE, 13, null, fixedColor, fixedColor); for (var point : this.pointBucket.search(box)) { - if (ModifiedObjects.getLockedTask(point.id()) == null && !TaskCache.isHidden(point)) { + if (ModifiedObjects.getLockedTask(point.id()) == null && !TaskCache.isHidden(point) + && !HiddenList.isHidden(point.id())) { final boolean isSelected = this.selected.contains(point) || listSelected.contains(point); final var symbolColor = switch (point.status()) { case FIXED -> fixedColor; diff --git a/src/main/java/org/openstreetmap/josm/plugins/maproulette/gui/task/list/TaskListPanel.java b/src/main/java/org/openstreetmap/josm/plugins/maproulette/gui/task/list/TaskListPanel.java index 7b1c805..23843b2 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/maproulette/gui/task/list/TaskListPanel.java +++ b/src/main/java/org/openstreetmap/josm/plugins/maproulette/gui/task/list/TaskListPanel.java @@ -42,10 +42,12 @@ import org.openstreetmap.josm.plugins.maproulette.actions.downloadtasks.MapRouletteDownloadTaskBox; import org.openstreetmap.josm.plugins.maproulette.api.MRColors; import org.openstreetmap.josm.plugins.maproulette.api.model.ClusteredPoint; +import org.openstreetmap.josm.plugins.maproulette.api.model.Identifier; import org.openstreetmap.josm.plugins.maproulette.api.model.Task; import org.openstreetmap.josm.plugins.maproulette.api.model.TaskClusteredPoint; import org.openstreetmap.josm.plugins.maproulette.api_caching.ChallengeCache; import org.openstreetmap.josm.plugins.maproulette.api_caching.TaskCache; +import org.openstreetmap.josm.plugins.maproulette.data.HiddenList; import org.openstreetmap.josm.plugins.maproulette.gui.ModifiedObjects; import org.openstreetmap.josm.plugins.maproulette.gui.layer.MapRouletteClusteredPointLayer; import org.openstreetmap.josm.plugins.maproulette.gui.preferences.MapRoulettePreferences; @@ -105,6 +107,7 @@ public boolean include(Entry entry) return !TaskCache.isHidden(point); } }; + HiddenList.addListUpdater(this::isHidden); filterField.filter(expr -> { expr = expr.replace("+", "\\+"); final ArrayList> andFilters = new ArrayList<>(); @@ -114,6 +117,11 @@ public boolean include(Entry entry) andFilters.add(RowFilter.regexFilter("(?i)" + word)); } tableRowSorter.setRowFilter(andFilters.size() > 1 ? RowFilter.andFilter(andFilters) : defaultFilter); + final var layers = MainApplication.getLayerManager().getLayersOfType(MapRouletteClusteredPointLayer.class); + final var ids = layers.stream().map(MapRouletteClusteredPointLayer::getTasks).flatMap(Collection::stream) + .mapToLong(Identifier::id).toArray(); + HiddenList.update(ids); + layers.forEach(MapRouletteClusteredPointLayer::invalidate); }); menu.add(new GoToTaskLocation()); menu.add(new IgnoreAction(IgnoreAction.IgnoreType.IGNORE_TASK)); @@ -247,6 +255,20 @@ public void layerOrderChanged(LayerManager.LayerOrderChangeEvent e) { // Ignore } + /** + * Check if a task is hidden + * @param id The task to check + * @return {@code true} if the task is hidden + */ + private boolean isHidden(long id) { + for (int i = 0; i < this.model.getRowCount(); i++) { + if (id == this.model.get(i).id()) { + return this.table.convertRowIndexToView(i) < 0; + } + } + return true; + } + /** * Open task in browser */ diff --git a/src/main/java/org/openstreetmap/josm/plugins/maproulette/markdown/SelectParser.java b/src/main/java/org/openstreetmap/josm/plugins/maproulette/markdown/SelectParser.java index cdd79fa..074dd3c 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/maproulette/markdown/SelectParser.java +++ b/src/main/java/org/openstreetmap/josm/plugins/maproulette/markdown/SelectParser.java @@ -7,7 +7,7 @@ import java.util.TreeMap; import java.util.regex.Pattern; -import org.commonmark.internal.util.Parsing; +import org.commonmark.text.Characters; import org.commonmark.node.AbstractVisitor; import org.commonmark.node.CustomNode; import org.commonmark.node.Node; @@ -82,8 +82,8 @@ private static class SelectNode extends CustomNode { * @param selectBlock The full select block */ SelectNode(String selectBlock) { - final var startDefault = Parsing.find('"', selectBlock, 0) + 1; - final var endDefault = Parsing.find('"', selectBlock, startDefault); + final var startDefault = Characters.find('"', selectBlock, 0) + 1; + final var endDefault = Characters.find('"', selectBlock, startDefault); final var valueMatcher = Pattern.compile("values=\"([^\"]*)").matcher(selectBlock); final var nameMatcher = Pattern.compile("name=\"([^\"]*)").matcher(selectBlock); if (nameMatcher.find()) { diff --git a/src/main/java/org/openstreetmap/josm/plugins/maproulette/util/HttpClientUtils.java b/src/main/java/org/openstreetmap/josm/plugins/maproulette/util/HttpClientUtils.java index b8fcea5..1c4fb4c 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/maproulette/util/HttpClientUtils.java +++ b/src/main/java/org/openstreetmap/josm/plugins/maproulette/util/HttpClientUtils.java @@ -10,6 +10,7 @@ import java.util.Objects; import java.util.stream.Collectors; +import org.openstreetmap.josm.plugins.maproulette.api.UnauthorizedException; import org.openstreetmap.josm.tools.HttpClient; /** @@ -28,8 +29,9 @@ private HttpClientUtils() { * * @param url The url to GET * @return The client to use + * @throws UnauthorizedException if the user hasn't logged in to MapRoulette */ - public static HttpClient get(String url) { + public static HttpClient get(String url) throws UnauthorizedException { return get(url, Collections.emptyMap()); } @@ -39,8 +41,9 @@ public static HttpClient get(String url) { * @param url The url to GET * @param queryParameters The query parameters * @return The client to use + * @throws UnauthorizedException if the user hasn't logged in to MapRoulette */ - public static HttpClient get(String url, Map queryParameters) { + public static HttpClient get(String url, Map queryParameters) throws UnauthorizedException { var client = HttpClient.create(safeUrl(url, queryParameters)); sign(client); return client; @@ -69,8 +72,9 @@ private static URL safeUrl(String url, Map queryParameters) { * Sign the client * * @param client The client to add the api key to + * @throws UnauthorizedException if the user isn't logged in or hasn't logged in to MapRoulette before */ - private static void sign(HttpClient client) { + private static void sign(HttpClient client) throws UnauthorizedException { client.setHeader("apiKey", OsmPreferenceUtils.getMapRouletteApiKey()); } @@ -91,8 +95,9 @@ private static String query(Map queryParameters) { * @param url The url to PUT * @param queryParameters The query parameters * @return The client to use + * @throws UnauthorizedException if the user hasn't logged in to MapRoulette */ - public static HttpClient put(String url, Map queryParameters) { + public static HttpClient put(String url, Map queryParameters) throws UnauthorizedException { var client = put(url, Collections.emptyMap(), query(queryParameters).substring(1).getBytes(StandardCharsets.UTF_8)); client.setHeader("Content-Type", "application/x-www-form-urlencoded"); @@ -106,8 +111,10 @@ public static HttpClient put(String url, Map queryParameters) { * @param queryParameters The query parameters * @param body The body to use * @return The client to use + * @throws UnauthorizedException if the user hasn't logged in to MapRoulette */ - public static HttpClient put(String url, Map queryParameters, byte[] body) { + public static HttpClient put(String url, Map queryParameters, byte[] body) + throws UnauthorizedException { var client = HttpClient.create(safeUrl(url, queryParameters), "PUT"); client.setRequestBody(Objects.requireNonNullElse(body, new byte[0])); sign(client); @@ -120,8 +127,9 @@ public static HttpClient put(String url, Map queryParameters, by * @param url The URL to POST * @param queryParameters The query parameters to be put in the body * @return The client to use + * @throws UnauthorizedException if the user hasn't logged in to MapRoulette */ - public static HttpClient post(String url, Map queryParameters) { + public static HttpClient post(String url, Map queryParameters) throws UnauthorizedException { var client = HttpClient.create(safeUrl(url, Collections.emptyMap()), "POST"); client.setRequestBody(query(queryParameters).substring(1).getBytes(StandardCharsets.UTF_8)); sign(client); @@ -133,8 +141,9 @@ public static HttpClient post(String url, Map queryParameters) { * * @param url The URL to DELETE * @return The client to use + * @throws UnauthorizedException if the user hasn't logged in to MapRoulette */ - public static HttpClient delete(String url) { + public static HttpClient delete(String url) throws UnauthorizedException { var client = HttpClient.create(safeUrl(url, Collections.emptyMap()), "DELETE"); sign(client); return client; diff --git a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/ChallengeParserTest.java b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/ChallengeParserTest.java index 7fcaf5d..420e2a7 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/ChallengeParserTest.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/ChallengeParserTest.java @@ -28,13 +28,24 @@ void testChallenge15318() { final var expected = new Challenge(15318, "Add direction to Stop - USA Los Angeles Timezone", Instant.parse("2020-11-28T18:22:24.399Z"), Instant.parse("2023-01-24T14:21:34.897Z"), "This challenge will show every [highway=stop](https://wiki.openstreetmap.org/wiki/Tag:highway%3Dstop) without [direction=*](https://wiki.openstreetmap.org/wiki/Key:direction). Your goal is to add tag \"direction\" with value: \"forward\", \"backward\" or \"both\" for every stop. Read article [highway=stop](https://wiki.openstreetmap.org/wiki/Tag:highway%3Dstop) to know how to map.\n\n#### Overpass query\n[All my queries](https://wiki.openstreetmap.org/wiki/User:Binnette/OverpassQueries)\n\n#### About Binnette\n[Twitch](https://www.twitch.tv/binnettetv) - [Twitter](https://twitter.com/BinnetteBin) - [Wiki](https://wiki.openstreetmap.org/wiki/User:Binnette)", - false, "", new ChallengeGeneral(918586, 39866, "Add tag direction with value: \"forward\", \"backward\" or \"both\" for every stop. Read article [highway=stop](https://wiki.openstreetmap.org/wiki/Tag:highway%3Dstop) to know how to map.\n\nEx: direction=forward / direction=backward / direction=both\n\nNote:\n- for this usecase iD editor is great and shows directions.\n- with iD to change direction, click on the node and press v (reverse shortcut).", 2, "Add direction=forward/backward/both to [highway=stop](https://wiki.openstreetmap.org/wiki/Tag:highway%3Dstop).", true, false, 0, 1674515454, "Add tag direction to highway=stop - USA LA Timezone #maproulette", "", false, new long[0], false), - new ChallengeCreation("area[name=\"America/Los_Angeles Timezone\"]->.a;\nnode[\"highway\"=\"stop\"][!\"direction\"][!\"stop\"](area.a);\nway(bn)[\"highway\"][\"oneway\"!=\"yes\"];\nnode(w)[\"highway\"=\"stop\"][!\"direction\"];\nout skel;", "", "node"), + false, "", + new ChallengeGeneral(918586, 39866, + "Add tag direction with value: \"forward\", \"backward\" or \"both\" for every stop. Read article [highway=stop](https://wiki.openstreetmap.org/wiki/Tag:highway%3Dstop) to know how to map.\n\nEx: direction=forward / direction=backward / direction=both\n\nNote:\n- for this usecase iD editor is great and shows directions.\n- with iD to change direction, click on the node and press v (reverse shortcut).", + 2, + "Add direction=forward/backward/both to [highway=stop](https://wiki.openstreetmap.org/wiki/Tag:highway%3Dstop).", + true, false, 0, 1674515454, "Add tag direction to highway=stop - USA LA Timezone #maproulette", + "", false, new long[0], false), + new ChallengeCreation( + "area[name=\"America/Los_Angeles Timezone\"]->.a;\nnode[\"highway\"=\"stop\"][!\"direction\"][!\"stop\"](area.a);\nway(bn)[\"highway\"][\"oneway\"!=\"yes\"];\nnode(w)[\"highway\"=\"stop\"][!\"direction\"];\nout skel;", + "", "node"), new ChallengePriority(Priority.LOW, "{}", "{}", "{}"), - new ChallengeExtra(19, 3, 19, -1, "", "", false, "", "", null, null, false, false, "[]", "", false, null), + new ChallengeExtra(19, 3, 19, -1, "", "", false, "", "", null, null, false, false, "[]", "", false, + null), 3, "Request timeout to overpass-api.de/178.63.48.217:80 after 120000 ms", Instant.parse("2022-07-23T07:13:38.609Z"), Instant.parse("2022-07-23T07:13:38.609Z"), - new Point(38.3241717215975, -120.521573627918), "{\"type\":\"Polygon\",\"coordinates\":[[[-124.586248289365,32.5435948864956],[-124.586248289365,48.9940324531592],[-114.103130987674,48.9940324531592],[-114.103130987674,32.5435948864956],[-124.586248289365,32.5435948864956]]]}", 4, 29734); + new Point(38.3241717215975, -120.521573627918), + "{\"type\":\"Polygon\",\"coordinates\":[[[-124.586248289365,32.5435948864956],[-124.586248289365,48.9940324531592],[-114.103130987674,48.9940324531592],[-114.103130987674,32.5435948864956],[-124.586248289365,32.5435948864956]]]}", + 4, 29734); assertRecordsEqual(expected, challenge); } } diff --git a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/ClusteredPointParserTest.java b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/ClusteredPointParserTest.java index 2369928..b238761 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/ClusteredPointParserTest.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/ClusteredPointParserTest.java @@ -23,18 +23,19 @@ class ClusteredPointParserTest { @Test void testTask136226437() throws IOException { - final var box = TaskAPI.box(-108.4962538, 39.082404, -108.4962538, 39.082404, - 1_000, 0, true, null, null, false, true, true); + final var box = TaskAPI.box(-108.4962538, 39.082404, -108.4962538, 39.082404, 1_000, 0, true, null, null, false, + true, true); assertEquals(1, box.length); final var photoMC = new PublicUser(11197, null, "Photo_MC", null, null); final var actual = box[0]; - final var expected = new ClusteredPoint(136226437L, -1L, "", "861207014_way_1", - 27887L, "United States | Polygon has self intersection", new Point(39.082404, -108.4962538), - "", "", Instant.parse("2023-01-31T19:28:24.909Z"), null, 2, TaskStatus.TOO_HARD, null, + final var expected = new ClusteredPoint(136226437L, -1L, "", "861207014_way_1", 27887L, + "United States | Polygon has self intersection", new Point(39.082404, -108.4962538), "", "", + Instant.parse("2023-01-31T19:28:24.909Z"), null, 2, TaskStatus.TOO_HARD, null, Instant.parse("2022-10-18T03:19:56.028Z"), 923162L, photoMC, new PointReview(1, photoMC, new PublicUser(9724, null, "Jenn_Bh", null, null), - Instant.parse("2022-10-18T07:09:14.455Z"), null, null, - null, Instant.parse("2022-10-18T07:08:52.469Z"), new long[0]), 0, null, false); + Instant.parse("2022-10-18T07:09:14.455Z"), null, null, null, + Instant.parse("2022-10-18T07:08:52.469Z"), new long[0]), + 0, null, false); assertRecordsEqual(expected, actual); } } diff --git a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/GeometryParserTest.java b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/GeometryParserTest.java index 6a70812..8e990fa 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/GeometryParserTest.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/GeometryParserTest.java @@ -1,3 +1,4 @@ +// License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.maproulette.api.parsers; import static org.junit.jupiter.api.Assertions.assertAll; diff --git a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/TaskParserTest.java b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/TaskParserTest.java index 962af9e..d6b6a0f 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/TaskParserTest.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/api/parsers/TaskParserTest.java @@ -37,22 +37,22 @@ class TaskParserTest { void testTaskParsing135045992() { final var task = assertDoesNotThrow(() -> TaskAPI.start(135045992)); final var expected = new Task(135045992, "way/131190351", Instant.parse("2022-08-06T15:23:36.531Z"), - Instant.parse("2022-08-06T15:23:36.531Z"), 24092, "", - new Point(36.0819446365856, -119.104608317353), task.geometries(), - new OSMChange(new ElementCreate[0], new ElementUpdate[]{ - new ElementUpdate(131190351L, OsmPrimitiveType.WAY, Integer.MIN_VALUE, new ElementTagChange( - Map.of("landuse", "farmland", "FMMP_modified", "yes"), new String[0] - )) - }), TaskStatus.CREATED, null, null, null, - new TaskReviewFields(null, null, null, null, null, - null, null, null, null, null), - 0, -1L, null, null, false, null, ""); + Instant.parse("2022-08-06T15:23:36.531Z"), 24092, "", new Point(36.0819446365856, -119.104608317353), + task.geometries(), + new OSMChange(new ElementCreate[0], + new ElementUpdate[] { new ElementUpdate(131190351L, OsmPrimitiveType.WAY, Integer.MIN_VALUE, + new ElementTagChange(Map.of("landuse", "farmland", "FMMP_modified", "yes"), + new String[0])) }), + TaskStatus.CREATED, null, null, null, + new TaskReviewFields(null, null, null, null, null, null, null, null, null, null), 0, -1L, null, null, + false, null, ""); assertRecordsEqual(expected, task); // Check geometries final var way = task.geometries().getWays().iterator().next(); assertAll("Tags were improperly parsed", () -> assertEquals("way/131190351", way.get("@id")), () -> assertEquals("28.9408234929", way.get("acres")), - () -> assertEquals("http://www.consrv.ca.gov/dlrp/fmmp/products/Pages/DownloadGISdata.aspx", way.get("source")), + () -> assertEquals("http://www.consrv.ca.gov/dlrp/fmmp/products/Pages/DownloadGISdata.aspx", + way.get("source")), () -> assertEquals("farmland", way.get("landuse")), () -> assertEquals("Tulare", way.get("addr:county")), () -> assertEquals("Farmland Mapping and Monitoring Program", way.get("attribution")), @@ -67,12 +67,11 @@ void testTaskParsing135045992() { @Test void testTaskParsing134808786() { final var task = assertDoesNotThrow(() -> TaskAPI.start(134808786)); - final var expected = new Task(134808786, "node/-103005", Instant.parse("2022-08-04T15:44:15.335Z"), Instant.parse("2022-08-04T15:44:15.335Z"), - 28467, "", new Point(43.3719671, -82.9782727), task.geometries(), - task.cooperativeWork(), TaskStatus.CREATED, null, null, null, - new TaskReviewFields(null, null, null, null, null, - null, null, null, null, null), - 0, -1L, null, null, false, null, ""); + final var expected = new Task(134808786, "node/-103005", Instant.parse("2022-08-04T15:44:15.335Z"), + Instant.parse("2022-08-04T15:44:15.335Z"), 28467, "", new Point(43.3719671, -82.9782727), + task.geometries(), task.cooperativeWork(), TaskStatus.CREATED, null, null, null, + new TaskReviewFields(null, null, null, null, null, null, null, null, null, null), 0, -1L, null, null, + false, null, ""); assertRecordsEqual(expected, task); final var actualData = expected.cooperativeWorkAsOsc(); assertNotNull(actualData); @@ -83,15 +82,20 @@ void testTaskParsing134808786() { final var node = ds.getNodes().iterator().next(); assertEquals(43.3719671, node.lat(), ILatLon.MAX_SERVER_PRECISION); assertEquals(-82.9782727, node.lon(), ILatLon.MAX_SERVER_PRECISION); - assertEquals(Map.of("gnis:feature_id", "624965", "name", "Duff Creek", "waterway", "stream"), - node.getKeys()); + assertEquals(Map.of("gnis:feature_id", "624965", "name", "Duff Creek", "waterway", "stream"), node.getKeys()); assertTrue(node.isNew()); } @Test void testTaskParsing136226437() { final var task = assertDoesNotThrow(() -> TaskAPI.start(136226437)); - final var expected = new Task(136226437L, "861207014_way_1", Instant.parse("2022-09-15T18:50:39.354Z"), Instant.parse("2022-10-18T03:19:56.028Z"), 27887, "", new Point(39.082404, -108.4962538), task.geometries(), task.cooperativeWork(), TaskStatus.TOO_HARD, Instant.parse("2022-10-18T03:19:56.028Z"), 923162L, 11197L, new TaskReviewFields(1, 11197L, 9724L, Instant.parse("2022-10-18T07:09:14.455Z"), null, null, null, Instant.parse("2022-10-18T07:08:52.469Z"), null, null), 0, -1L, null, null, false, null, ""); + final var expected = new Task(136226437L, "861207014_way_1", Instant.parse("2022-09-15T18:50:39.354Z"), + Instant.parse("2022-10-18T03:19:56.028Z"), 27887, "", new Point(39.082404, -108.4962538), + task.geometries(), task.cooperativeWork(), TaskStatus.TOO_HARD, + Instant.parse("2022-10-18T03:19:56.028Z"), 923162L, 11197L, + new TaskReviewFields(1, 11197L, 9724L, Instant.parse("2022-10-18T07:09:14.455Z"), null, null, null, + Instant.parse("2022-10-18T07:08:52.469Z"), null, null), + 0, -1L, null, null, false, null, ""); assertRecordsEqual(expected, task); } } diff --git a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/data/IgnoreListTest.java b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/data/IgnoreListTest.java index 1efc184..353387d 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/data/IgnoreListTest.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/data/IgnoreListTest.java @@ -1,3 +1,4 @@ +// License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.maproulette.data; import static org.junit.jupiter.api.Assertions.assertAll; @@ -21,15 +22,10 @@ void testIgnores() { } IgnoreList.ignoreTask(15); IgnoreList.ignoreChallenge(15); - assertAll(() -> assertTrue(IgnoreList.isTaskIgnored(0)), - () -> assertTrue(IgnoreList.isChallengeIgnored(0)), - () -> assertTrue(IgnoreList.isTaskIgnored(9)), - () -> assertTrue(IgnoreList.isChallengeIgnored(9)), - () -> assertTrue(IgnoreList.isTaskIgnored(15)), - () -> assertTrue(IgnoreList.isChallengeIgnored(15)), - () -> assertTrue(IgnoreList.isTaskIgnored(20)), - () -> assertTrue(IgnoreList.isChallengeIgnored(20)), - () -> assertTrue(IgnoreList.isTaskIgnored(29)), - () -> assertTrue(IgnoreList.isChallengeIgnored(29))); + assertAll(() -> assertTrue(IgnoreList.isTaskIgnored(0)), () -> assertTrue(IgnoreList.isChallengeIgnored(0)), + () -> assertTrue(IgnoreList.isTaskIgnored(9)), () -> assertTrue(IgnoreList.isChallengeIgnored(9)), + () -> assertTrue(IgnoreList.isTaskIgnored(15)), () -> assertTrue(IgnoreList.isChallengeIgnored(15)), + () -> assertTrue(IgnoreList.isTaskIgnored(20)), () -> assertTrue(IgnoreList.isChallengeIgnored(20)), + () -> assertTrue(IgnoreList.isTaskIgnored(29)), () -> assertTrue(IgnoreList.isChallengeIgnored(29))); } } \ No newline at end of file diff --git a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/data/TaskPrimitivesTest.java b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/data/TaskPrimitivesTest.java index 7a5080b..a76567c 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/data/TaskPrimitivesTest.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/data/TaskPrimitivesTest.java @@ -1,3 +1,4 @@ +// License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.maproulette.data; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; diff --git a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/gui/MRGuiHelperTest.java b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/gui/MRGuiHelperTest.java index 9dc7b3c..48799bd 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/gui/MRGuiHelperTest.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/gui/MRGuiHelperTest.java @@ -1,3 +1,4 @@ +// License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.maproulette.gui; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -14,10 +15,12 @@ class MRGuiHelperTest { void testGetInstructionTextMustache() { final var task = assertDoesNotThrow(() -> TaskAPI.get(147197178)); final var instructions = MRGuiHelper.getInstructionText(task); - assertEquals(""" -
    -
  1. Node 6318952236 has been tagged as a building indicating that it represents a building, but it is better to represent buildings with polygons or multipolygons. Please see if there is enough satellite imagery information to replace this node with a new polygon. If there is enough detail to draw this building as a polygon then add the polygon that represents the building and remove the building tag from this node or transfer the tags from this node to the new polygon, and then delete this node. See https://wiki.openstreetmap.org/wiki/Mapping_addresses_as_separate_nodes_or_by_adding_to_building_polygons.
  2. -
- """, instructions); + assertEquals( + """ +
    +
  1. Node 6318952236 has been tagged as a building indicating that it represents a building, but it is better to represent buildings with polygons or multipolygons. Please see if there is enough satellite imagery information to replace this node with a new polygon. If there is enough detail to draw this building as a polygon then add the polygon that represents the building and remove the building tag from this node or transfer the tags from this node to the new polygon, and then delete this node. See https://wiki.openstreetmap.org/wiki/Mapping_addresses_as_separate_nodes_or_by_adding_to_building_polygons.
  2. +
+ """, + instructions); } } \ No newline at end of file diff --git a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/gui/TaskListPanelTest.java b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/gui/TaskListPanelTest.java index e59a7d4..d94474d 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/gui/TaskListPanelTest.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/gui/TaskListPanelTest.java @@ -1,3 +1,4 @@ +// License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.maproulette.gui; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -43,13 +44,13 @@ public class TaskListPanelTest { * @param ignoreType The ignore action to use */ public static void fireIgnoreAction(TaskListPanel panel, IgnoreAction.IgnoreType ignoreType) { - final var table = ((JTable) ((JComponent) ((JComponent) ((JComponent) panel.getComponent(1 /* The scroll pane */)) - .getComponent(0 /* The viewport */)).getComponent(0 /* A panel */)) - .getComponent(2 /* The table */)); + final var table = ((JTable) ((JComponent) ((JComponent) ((JComponent) panel + .getComponent(1 /* The scroll pane */)).getComponent(0 /* The viewport */)) + .getComponent(0 /* A panel */)).getComponent(2 /* The table */)); final var menu = table.getComponentPopupMenu(); final var menuItem = (JMenuItem) switch (ignoreType) { - case IGNORE_TASK -> menu.getComponent(1); - case IGNORE_CHALLENGE -> menu.getComponent(2); + case IGNORE_TASK -> menu.getComponent(1); + case IGNORE_CHALLENGE -> menu.getComponent(2); }; menu.setInvoker(table); final var action = menuItem.getAction(); @@ -70,9 +71,11 @@ public Bounds getLatLonBoundsBox() { } }; action.actionPerformed(null); - MainApplication.worker.submit(() -> { /* Sync thread */ }).get(); + MainApplication.worker.submit(() -> { + /* Sync thread */ }).get(); action.actionPerformed(null); - MainApplication.worker.submit(() -> { /* Sync thread */ }).get(); + MainApplication.worker.submit(() -> { + /* Sync thread */ }).get(); } /** @@ -83,9 +86,9 @@ public Bounds getLatLonBoundsBox() { */ public static Action getDownloadAction(TaskListPanel taskListPanel) { final var action = ((JButton) ((JComponent) ((JComponent) taskListPanel.getComponent(2 /* The side buttons */)) - .getComponent(0 /* A singular JPanel */)) - .getComponent(0 /* The download button */)).getAction(); - assertEquals("org.openstreetmap.josm.plugins.maproulette.gui.task.list.TaskListPanel$DownloadDataAction", action.getClass().getName()); + .getComponent(0 /* A singular JPanel */)).getComponent(0 /* The download button */)).getAction(); + assertEquals("org.openstreetmap.josm.plugins.maproulette.gui.task.list.TaskListPanel$DownloadDataAction", + action.getClass().getName()); return action; } } \ No newline at end of file diff --git a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/gui/layer/MapRouletteClusteredPointLayerTest.java b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/gui/layer/MapRouletteClusteredPointLayerTest.java index 8b3f226..2d069c7 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/gui/layer/MapRouletteClusteredPointLayerTest.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/gui/layer/MapRouletteClusteredPointLayerTest.java @@ -1,3 +1,4 @@ +// License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.maproulette.gui.layer; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -53,7 +54,8 @@ public Bounds getLatLonBoundsBox() { try { MainApplication.getMap().addToggleDialog(panel); TaskListPanelTest.getDownloadAction(panel).actionPerformed(null); - MainApplication.worker.submit(() -> { /* Sync thread */ }).get(5, TimeUnit.SECONDS); + MainApplication.worker.submit(() -> { + /* Sync thread */ }).get(5, TimeUnit.SECONDS); final var layers = MainApplication.getLayerManager().getLayersOfType(MapRouletteClusteredPointLayer.class); assertEquals(1, layers.size()); final var layer = layers.get(0); @@ -68,7 +70,8 @@ public Bounds getLatLonBoundsBox() { // Now what happens with shift events? layer.mouseClicked(generateMouseEvent(true, 36.0778797, -119.1075725)); assertEquals(2, panel.getSelected().size()); - assertTrue(panel.getSelected().stream().mapToLong(Identifier::id).allMatch(id -> id == 133361784L || id == 133361785L)); + assertTrue(panel.getSelected().stream().mapToLong(Identifier::id) + .allMatch(id -> id == 133361784L || id == 133361785L)); assertEquals(2, panel.getSelected().stream().mapToLong(Identifier::id).distinct().count()); // Now, let us hide the challenge for the objects we have selected TaskListPanelTest.fireIgnoreAction(panel, IgnoreAction.IgnoreType.IGNORE_CHALLENGE); @@ -88,7 +91,7 @@ private static MouseEvent generateMouseEvent(boolean shift, double lat, double l final var ll = new LatLon(lat, lon); mv.zoomTo(ll); final var point = mv.getPoint(ll); - return new MouseEvent(MainApplication.getMap(), UUID.randomUUID().hashCode(), - System.currentTimeMillis(), shift ? MouseEvent.SHIFT_DOWN_MASK : 0, point.x, point.y, 1, false, MouseEvent.BUTTON1); + return new MouseEvent(MainApplication.getMap(), UUID.randomUUID().hashCode(), System.currentTimeMillis(), + shift ? MouseEvent.SHIFT_DOWN_MASK : 0, point.x, point.y, 1, false, MouseEvent.BUTTON1); } } \ No newline at end of file diff --git a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/io/upload/EarlyUploadHookTest.java b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/io/upload/EarlyUploadHookTest.java index aaef8bf..76d740a 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/io/upload/EarlyUploadHookTest.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/io/upload/EarlyUploadHookTest.java @@ -1,3 +1,4 @@ +// License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.maproulette.io.upload; import static org.junit.jupiter.api.Assertions.assertAll; @@ -56,7 +57,7 @@ void setUp() { } @ParameterizedTest - @ValueSource(strings = {"9494185766_node_4", "9494185766", "node/9494185766", "node 9494185766@4"}) + @ValueSource(strings = { "9494185766_node_4", "9494185766", "node/9494185766", "node 9494185766@4" }) void testRegexParsing(String title) { final var ds = new DataSet(); final var node = TestUtils.newNode(""); @@ -66,12 +67,11 @@ void testRegexParsing(String title) { ds.addPrimitive(node); final var apiDataSet = new APIDataSet(ds); MainApplication.getLayerManager().addLayer(new OsmDataLayer(ds, "testRegexParsing", null)); - final var mrLayer = new MapRouletteClusteredPointLayer(new Bounds(0, 0, 0, 0), Collections.singleton( - new ClusteredPoint(132279499L, 0L, "null", title, 0L, "parentName", new Point(0, 0), - "bounding", "blurb", Instant.EPOCH, Difficulty.NORMAL, 2, TaskStatus.CREATED, null, - Instant.EPOCH, 0L, new PublicUser(0L, null, "someone", Instant.EPOCH, null), - new PointReview(null, null, null, null, null, null, null, null, null), 0, null, false) - )); + final var mrLayer = new MapRouletteClusteredPointLayer(new Bounds(0, 0, 0, 0), + Collections.singleton(new ClusteredPoint(132279499L, 0L, "null", title, 0L, "parentName", + new Point(0, 0), "bounding", "blurb", Instant.EPOCH, Difficulty.NORMAL, 2, TaskStatus.CREATED, + null, Instant.EPOCH, 0L, new PublicUser(0L, null, "someone", Instant.EPOCH, null), + new PointReview(null, null, null, null, null, null, null, null, null), 0, null, false))); MainApplication.getLayerManager().addLayer(mrLayer); Config.getPref().putInt("message." + EarlyUploadHook.PREF_CHECK_IF_FINISHED + ".value", 0); Config.getPref().putBoolean("message." + EarlyUploadHook.PREF_CHECK_IF_FINISHED, false); @@ -87,7 +87,9 @@ void testRegexParsing(String title) { @Test void testManyClosedTasks() { for (int i = 100_000_000; i < 100_000_050; i++) { - ModifiedObjects.addModifiedTask(new ModifiedTask(new Task(i, "", null, null, 15318, null, null, null, null, null, null, null, null, null, 0, null, null, null, false, null, null), TaskStatus.FIXED, null, null, null, null)); + ModifiedObjects.addModifiedTask( + new ModifiedTask(new Task(i, "", null, null, 15318, null, null, null, null, null, null, null, null, + null, 0, null, null, null, false, null, null), TaskStatus.FIXED, null, null, null, null)); } final var map = new HashMap(); hook.modifyChangesetTags(map); diff --git a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/markdown/SelectParserTest.java b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/markdown/SelectParserTest.java index c849e2b..bd46d7d 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/markdown/SelectParserTest.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/markdown/SelectParserTest.java @@ -1,3 +1,4 @@ +// License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.maproulette.markdown; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -29,14 +30,14 @@ void setup() { static List testSelect() { final var renderSelect = "\n\n"; final var markdownSelect = "[select \" \" values=\"One,Two,Three\"]"; - return Arrays.asList( - Arguments.of("

" + renderSelect + "

\n", markdownSelect), + return Arrays.asList(Arguments.of("

" + renderSelect + "

\n", markdownSelect), Arguments.of("

Matching: " + renderSelect + "

\n", "Matching: " + markdownSelect), Arguments.of("

" + renderSelect + " values

\n", markdownSelect + " values"), - Arguments.of("

Matching: " + renderSelect + " values

\n", "Matching: " + markdownSelect + " values"), - Arguments.of("

\n\n

\n", - "[select \" \" name=\"Test Name\" values=\"One,Two,Three\"]") - ); + Arguments.of("

Matching: " + renderSelect + " values

\n", + "Matching: " + markdownSelect + " values"), + Arguments.of( + "

\n\n

\n", + "[select \" \" name=\"Test Name\" values=\"One,Two,Three\"]")); } @ParameterizedTest diff --git a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/LoggingHandler.java b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/LoggingHandler.java index df33f62..3b278a7 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/LoggingHandler.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/LoggingHandler.java @@ -35,7 +35,7 @@ */ @Documented @Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE, ElementType.METHOD}) +@Target({ ElementType.TYPE, ElementType.METHOD }) @ExtendWith(LoggingHandler.LoggingHandlerImplementation.class) public @interface LoggingHandler { /** @@ -52,11 +52,14 @@ class LoggingHandlerImplementation implements BeforeEachCallback, AfterEachCallb @Override public void afterEach(ExtensionContext context) { - MainApplication.worker.submit(() -> { /* Sync thread */ }); - GuiHelper.runInEDTAndWait(() -> { /* Sync thread */ }); - final int failLevel = AnnotationSupport.findAnnotation(context.getElement(), LoggingHandler.class).map(LoggingHandler::value) - .orElse(AnnotationSupport.findAnnotation(context.getClass(), LoggingHandler.class).map(LoggingHandler::value) - .orElse(1000)); + MainApplication.worker.submit(() -> { + /* Sync thread */ }); + GuiHelper.runInEDTAndWait(() -> { + /* Sync thread */ }); + final int failLevel = AnnotationSupport.findAnnotation(context.getElement(), LoggingHandler.class) + .map(LoggingHandler::value) + .orElse(AnnotationSupport.findAnnotation(context.getClass(), LoggingHandler.class) + .map(LoggingHandler::value).orElse(1000)); ExtensionContext.Store store = context.getStore(ExtensionContext.Namespace.create(LoggingHandler.class)); TestHandler testHandler = store.get(TestHandler.class, TestHandler.class); Logging.getLogger().removeHandler(testHandler); @@ -64,9 +67,9 @@ public void afterEach(ExtensionContext context) { for (Handler handler : handlers) { Logging.getLogger().addHandler(handler); } - assertAll(testHandler.getRecords().stream() - .filter(logRecord -> logRecord.getLevel().intValue() >= failLevel) - .map(logRecord -> fail(logRecord.getMessage(), logRecord.getThrown()))); + assertAll( + testHandler.getRecords().stream().filter(logRecord -> logRecord.getLevel().intValue() >= failLevel) + .map(logRecord -> fail(logRecord.getMessage(), logRecord.getThrown()))); testHandler.clearRecords(); } @@ -81,8 +84,8 @@ public void beforeEach(ExtensionContext context) { store.put(TestHandler.class, testHandler); Logging.getLogger().addHandler(testHandler); // Ensure that exceptions thrown in the EDT are logged -- they weren't in testing - GuiHelper.runInEDTAndWaitWithException(() -> - Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> Logging.error(throwable))); + GuiHelper.runInEDTAndWaitWithException(() -> Thread.currentThread() + .setUncaughtExceptionHandler((thread, throwable) -> Logging.error(throwable))); } @Override @@ -134,4 +137,3 @@ public void close() throws SecurityException { } } } - diff --git a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/MapRouletteConfig.java b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/MapRouletteConfig.java index 5520ce0..df1c68b 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/MapRouletteConfig.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/MapRouletteConfig.java @@ -57,9 +57,9 @@ public Extension() { @Override protected void onBeforeEach(WireMockRuntimeInfo wireMockRuntimeInfo) { - org.openstreetmap.josm.plugins.maproulette.config.MapRouletteConfig.setInstance( - new org.openstreetmap.josm.plugins.maproulette.config.MapRouletteConfig(wireMockRuntimeInfo.getHttpBaseUrl() + "/api/v2") - ); + org.openstreetmap.josm.plugins.maproulette.config.MapRouletteConfig + .setInstance(new org.openstreetmap.josm.plugins.maproulette.config.MapRouletteConfig( + wireMockRuntimeInfo.getHttpBaseUrl() + "/api/v2")); Config.getPref().put("osm-server.url", wireMockRuntimeInfo.getHttpBaseUrl() + "/api"); } @@ -85,14 +85,17 @@ protected void onAfterEach(WireMockRuntimeInfo wireMockRuntimeInfo) { class MapRouletteExtension extends ResponseDefinitionTransformer { @Override - public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, FileSource files, Parameters parameters) { + public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, FileSource files, + Parameters parameters) { if (request.getUrl().startsWith("/api/v2/task/") && request.getUrl().matches("/api/v2/task/\\d+")) { final var file = files.getTextFileNamed(request.getUrl().substring(1) + "/start"); if (file != null) { - final var builder = responseDefinition.wasConfigured() ? ResponseDefinitionBuilder.like(responseDefinition) : ResponseDefinitionBuilder.responseDefinition(); - return builder - .withStatus(HTTP_OK) - .withResponseBody(Body.ofBinaryOrText(file.readContents(), new ContentTypeHeader("application/json"))) + final var builder = responseDefinition.wasConfigured() + ? ResponseDefinitionBuilder.like(responseDefinition) + : ResponseDefinitionBuilder.responseDefinition(); + return builder.withStatus(HTTP_OK) + .withResponseBody( + Body.ofBinaryOrText(file.readContents(), new ContentTypeHeader("application/json"))) .build(); } } diff --git a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/RecordAssertion.java b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/RecordAssertion.java index b0249ef..d777a50 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/RecordAssertion.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/RecordAssertion.java @@ -55,35 +55,47 @@ public static void assertRecordsEqual(T expected, T actual, S final var actualObj = method.invoke(actual); if (expectedObj instanceof Record && actualObj instanceof Record && expectedObj.getClass().equals(actualObj.getClass())) { - executableList.add(() -> assertRecordsEqual((Record) expectedObj, (Record) actualObj, component.getName())); + executableList.add( + () -> assertRecordsEqual((Record) expectedObj, (Record) actualObj, component.getName())); } else if (expectedObj instanceof Object[] expectedArray && actualObj instanceof Object[] actualArray) { - if (expectedObj.getClass().getComponentType().isRecord() && expectedObj.getClass().equals(actualObj.getClass())) { - executableList.add(() -> assertEquals(expectedArray.length, actualArray.length, component.getName())); + if (expectedObj.getClass().getComponentType().isRecord() + && expectedObj.getClass().equals(actualObj.getClass())) { + executableList + .add(() -> assertEquals(expectedArray.length, actualArray.length, component.getName())); if (expectedArray.length == actualArray.length) { for (int i = 0; i < expectedArray.length; i++) { final var index = i; - executableList.add(() -> assertRecordsEqual((Record) expectedArray[index], (Record) actualArray[index], component.getName())); + executableList.add(() -> assertRecordsEqual((Record) expectedArray[index], + (Record) actualArray[index], component.getName())); } } } else { executableList.add(() -> assertArrayEquals(expectedArray, actualArray, component.getName())); } } else if (expectedObj instanceof long[] && actualObj instanceof long[]) { - executableList.add(() -> assertArrayEquals((long[]) expectedObj, (long[]) actualObj, component.getName())); + executableList.add( + () -> assertArrayEquals((long[]) expectedObj, (long[]) actualObj, component.getName())); } else if (expectedObj instanceof int[] && actualObj instanceof int[]) { - executableList.add(() -> assertArrayEquals((int[]) expectedObj, (int[]) actualObj, component.getName())); + executableList + .add(() -> assertArrayEquals((int[]) expectedObj, (int[]) actualObj, component.getName())); } else if (expectedObj instanceof short[] && actualObj instanceof short[]) { - executableList.add(() -> assertArrayEquals((short[]) expectedObj, (short[]) actualObj, component.getName())); + executableList.add( + () -> assertArrayEquals((short[]) expectedObj, (short[]) actualObj, component.getName())); } else if (expectedObj instanceof char[] && actualObj instanceof char[]) { - executableList.add(() -> assertArrayEquals((char[]) expectedObj, (char[]) actualObj, component.getName())); + executableList.add( + () -> assertArrayEquals((char[]) expectedObj, (char[]) actualObj, component.getName())); } else if (expectedObj instanceof byte[] && actualObj instanceof byte[]) { - executableList.add(() -> assertArrayEquals((byte[]) expectedObj, (byte[]) actualObj, component.getName())); + executableList.add( + () -> assertArrayEquals((byte[]) expectedObj, (byte[]) actualObj, component.getName())); } else if (expectedObj instanceof boolean[] && actualObj instanceof boolean[]) { - executableList.add(() -> assertArrayEquals((boolean[]) expectedObj, (boolean[]) actualObj, component.getName())); + executableList.add(() -> assertArrayEquals((boolean[]) expectedObj, (boolean[]) actualObj, + component.getName())); } else if (expectedObj instanceof double[] && actualObj instanceof double[]) { - executableList.add(() -> assertArrayEquals((double[]) expectedObj, (double[]) actualObj, component.getName())); + executableList.add( + () -> assertArrayEquals((double[]) expectedObj, (double[]) actualObj, component.getName())); } else if (expectedObj instanceof float[] && actualObj instanceof float[]) { - executableList.add(() -> assertArrayEquals((float[]) expectedObj, (float[]) actualObj, component.getName())); + executableList.add( + () -> assertArrayEquals((float[]) expectedObj, (float[]) actualObj, component.getName())); } else { executableList.add(() -> assertEquals(expectedObj, actualObj, component.getName())); }