diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 063c13e..505c107 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -102,7 +102,7 @@ test: paths: - build reports: - junit: build/test-results/test/TEST-*.xml + junit: build/test-results/**/TEST-*.xml dependencies: - assemble diff --git a/build.gradle b/build.gradle index d76a426..f7f10de 100644 --- a/build.gradle +++ b/build.gradle @@ -140,6 +140,8 @@ task integrationTest(type: Test) { testClassesDirs = sourceSets.intTest.output.classesDirs classpath = sourceSets.intTest.runtimeClasspath shouldRunAfter test + // Ignore failures -- servers may or may not be down + ignoreFailures = true } check.dependsOn integrationTest diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/BoundingBoxMapWithAIDownloader.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/BoundingBoxMapWithAIDownloader.java index ff6489b..6f38568 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/BoundingBoxMapWithAIDownloader.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/BoundingBoxMapWithAIDownloader.java @@ -30,7 +30,7 @@ public class BoundingBoxMapWithAIDownloader extends BoundingBoxDownloader { private static long lastErrorTime; private final Bounds downloadArea; - private MapWithAIInfo info; + private final MapWithAIInfo info; private static final int DEFAULT_TIMEOUT = 50_000; // 50 seconds diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java index ffc885b..3c7aa63 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java @@ -31,7 +31,7 @@ import org.openstreetmap.josm.tools.Utils; public class DataAvailability { /** This points to a list of default sources that can be used with MapWithAI */ - public static String DEFAULT_SERVER_URL = "https://gokaart.gitlab.io/JOSM_MapWithAI/json/sources.json"; + private static String defaultServerUrl = "https://gokaart.gitlab.io/JOSM_MapWithAI/json/sources.json"; /** A map of tag -> message of possible data types */ static final Map POSSIBLE_DATA_POINTS = new TreeMap<>(); @@ -68,7 +68,7 @@ public class DataAvailability { * Initialize the class */ private static void initialize() { - try (CachedFile jsonFile = new CachedFile(DEFAULT_SERVER_URL); + try (CachedFile jsonFile = new CachedFile(defaultServerUrl); JsonParser jsonParser = Json.createParser(jsonFile.getContentReader());) { jsonFile.setMaxAge(604_800); jsonParser.next(); @@ -276,6 +276,13 @@ public class DataAvailability { * @param url The URL which serves MapWithAI servers */ public static void setReleaseUrl(String url) { - DEFAULT_SERVER_URL = url; + defaultServerUrl = url; + } + + /** + * @param url The URL which serves MapWithAI servers + */ + public static String getReleaseUrl() { + return defaultServerUrl; } } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadMapWithAITask.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadMapWithAITask.java index 245ccf4..6357c60 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadMapWithAITask.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadMapWithAITask.java @@ -26,7 +26,7 @@ import org.openstreetmap.josm.tools.Utils; import org.xml.sax.SAXException; public class DownloadMapWithAITask extends DownloadOsmTask { - private List urls; + private final List urls; public DownloadMapWithAITask() { urls = MapWithAILayerInfo.getInstance().getLayers(); diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java index 79f1a99..97b8219 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java @@ -274,6 +274,17 @@ public class GetDataRunnable extends RecursiveTask { replaceTags(dataSet, replaceTags); } + /** + * Replace tags in a dataset with a set of replacement tags + * + * @param dataSet The dataset with primitives to change + * @param map The tags to replace + */ + public static void replaceTags(DataSet dataSet, Map replaceTags) { + replaceTags.forEach((orig, replace) -> dataSet.allNonDeletedPrimitives().parallelStream() + .filter(prim -> prim.hasTag(orig.getKey(), orig.getValue())).forEach(prim -> prim.put(replace))); + } + /** * Replace tags in a dataset with a set of replacement tags * @@ -288,17 +299,6 @@ public class GetDataRunnable extends RecursiveTask { })); } - /** - * Replace tags in a dataset with a set of replacement tags - * - * @param dataSet The dataset with primitives to change - * @param map The tags to replace - */ - public static void replaceTags(DataSet dataSet, Map replaceTags) { - replaceTags.forEach((orig, replace) -> dataSet.allNonDeletedPrimitives().parallelStream() - .filter(prim -> prim.hasTag(orig.getKey(), orig.getValue())).forEach(prim -> prim.put(replace))); - } - private static void cleanupDataSet(DataSet dataSet) { Map origIds = dataSet.allPrimitives().parallelStream() .filter(prim -> prim.hasKey(MergeDuplicateWays.ORIG_ID)).distinct() diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/cleanup/MissingConnectionTags.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/cleanup/MissingConnectionTags.java index 70b8750..2915871 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/cleanup/MissingConnectionTags.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/cleanup/MissingConnectionTags.java @@ -112,7 +112,6 @@ public class MissingConnectionTags extends AbstractConflationCommand { protected void fixErrors(String prefKey, Collection commands, Collection issues) { for (TestError issue : issues) { - issue.getHighlighted(); if (!issue.isFixable() || issue.getFix() == null || issue.getPrimitives().parallelStream().anyMatch(IPrimitive::isDeleted)) { continue; @@ -154,15 +153,12 @@ public class MissingConnectionTags extends AbstractConflationCommand { way.getDataSet().searchNodes(searchBBox).stream().filter(MissingConnectionTags::noConflationKey) .forEach(duplicateNodeTest::visit); duplicateNodeTest.endTest(); - if (duplicateNodeTest.getErrors().isEmpty()) { - continue; - } List dupeNodes = duplicateNodeTest.getErrors().stream() .filter(e -> e.getPrimitives().contains(node)).flatMap(e -> e.getPrimitives().stream()) .distinct() .filter(p -> !p.isDeleted() && !p.equals(node) && noConflationKey(p) && p.getOsmId() > 0) .collect(Collectors.toList()); - if (dupeNodes.isEmpty()) { + if (duplicateNodeTest.getErrors().isEmpty() || dupeNodes.isEmpty()) { continue; } List dupes = duplicateNodeTest.getErrors().stream() @@ -256,7 +252,7 @@ public class MissingConnectionTags extends AbstractConflationCommand { if (Geometry.getDistance(node, way) < precision) { WaySegment seg = Geometry.getClosestWaySegment(way, node); List prims = Arrays.asList(way, seg.getFirstNode(), seg.getSecondNode()); - if (seg != null && prims.stream().allMatch(p -> p.getOsmId() > 0)) { + if (prims.stream().allMatch(p -> p.getOsmId() > 0)) { return new ChangePropertyCommand(node, "conn", String.join(",", prims.stream().map(p -> p.getPrimitiveId().toString()).collect(Collectors.toList()))); } @@ -324,4 +320,18 @@ public class MissingConnectionTags extends AbstractConflationCommand { return false; } + @Override + public boolean equals(Object o) { + if (o instanceof MissingConnectionTags) { + MissingConnectionTags omct = (MissingConnectionTags) o; + return Objects.equals(omct.precision, this.precision) && super.equals(o); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hash(precision); + } + } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfo.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfo.java index 7328ab0..6b9beba 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfo.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfo.java @@ -110,10 +110,10 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable getParametersString(JsonArray parameters) { + return parameters == null ? Collections.emptyList() + : parameters.stream().filter(JsonObject.class::isInstance).map(JsonObject.class::cast) + .filter(map -> map.getBoolean("enabled", false)).filter(map -> map.containsKey("parameter")) + .map(map -> map.getString("parameter")).collect(Collectors.toList()); + + } + /** * Get the conflation parameters as a string * @@ -809,14 +817,6 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable getParametersString(JsonArray parameters) { - return parameters == null ? Collections.emptyList() - : parameters.stream().filter(JsonObject.class::isInstance).map(JsonObject.class::cast) - .filter(map -> map.getBoolean("enabled", false)).filter(map -> map.containsKey("parameter")) - .map(map -> map.getString("parameter")).collect(Collectors.toList()); - - } - public String getUrlExpanded() { StringBuilder sb; if (conflate && Config.getPref().getBoolean("mapwithai.third_party.conflate", true)) { @@ -847,7 +847,7 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable comparator = new Comparator() { - - @Override - public int compare(MapWithAIInfo o1, MapWithAIInfo o2) { - return o1.getCategory().getDescription().compareTo(o2.getCategory().getDescription()); - } - }; + Comparator comparator = (o1, o2) -> o1.getCategory().getDescription() + .compareTo(o2.getCategory().getDescription()); if (information != null) { information = information.stream().sorted(comparator).collect(Collectors.toSet()); } @@ -335,13 +330,12 @@ public class MapWithAILayerInfo { } private static Map getReplacementTags(String layerUrl) { - String toGet = layerUrl.endsWith("pjson") ? layerUrl : layerUrl.concat("?f=pjson"); + String toGet = layerUrl.endsWith("?f=pjson") ? layerUrl : layerUrl.concat("?f=pjson"); try (CachedFile featureServer = new CachedFile(toGet); BufferedReader br = featureServer.getContentReader(); JsonReader reader = Json.createReader(br)) { - JsonObject info = reader.readObject(); - return info.getJsonArray("fields").getValuesAs(JsonObject.class).stream() + return reader.readObject().getJsonArray("fields").getValuesAs(JsonObject.class).stream() .collect(Collectors.toMap(o -> o.getString("name"), o -> o.getString("alias", null))); } catch (IOException e) { Logging.error(e); @@ -571,7 +565,7 @@ public class MapWithAILayerInfo { * otherwise */ public String getUniqueId(MapWithAIInfo info) { - if (info.getId() != null && layerIds.get(info.getId()) == info) { + if (info != null && info.getId() != null && info.equals(layerIds.get(info.getId()))) { return info.getId(); } return null; @@ -588,8 +582,10 @@ public class MapWithAILayerInfo { return layerIds.get(id); } - public static interface FinishListener { - - public void onFinish(); + public interface FinishListener { + /** + * Called when information is finished loading + */ + void onFinish(); } } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadOptions.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadOptions.java index 474c496..7849c05 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadOptions.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadOptions.java @@ -27,7 +27,7 @@ import org.openstreetmap.josm.tools.GBC; public class MapWithAIDownloadOptions extends JPanel implements DownloadSelection, Destroyable, PropertyChangeListener { private final JPanel optionPanel; private DownloadDialog iGui; - private MapWithAIProvidersPanel mapwithaiProvidersPanel; + private final MapWithAIProvidersPanel mapwithaiProvidersPanel; public MapWithAIDownloadOptions() { optionPanel = new JPanel(new GridBagLayout()); diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadReader.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadReader.java index 5e97448..6d6ac05 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadReader.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadReader.java @@ -10,6 +10,7 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.util.Collection; import java.util.List; +import java.util.concurrent.ExecutionException; import java.util.function.Consumer; import javax.swing.Icon; @@ -30,6 +31,7 @@ import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIPreferenceHelpe import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo; import org.openstreetmap.josm.tools.GBC; import org.openstreetmap.josm.tools.ImageProvider; +import org.openstreetmap.josm.tools.Logging; public class MapWithAIDownloadReader implements DownloadSource { @@ -45,7 +47,14 @@ public class MapWithAIDownloadReader implements DownloadSource replacementTableDisplayData; private MapWithAILayerInfo info; private static final int MAX_SELECTED_TO_EDIT = 1; - private static final String SOURCE = "source"; public MapWithAIPreferences() { super("mapwithai", tr("MapWithAI preferences"), tr("Modify MapWithAI preferences"), false, new JTabbedPane()); diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/AddMapWithAIPanel.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/AddMapWithAIPanel.java index 3f47f8d..857782e 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/AddMapWithAIPanel.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/AddMapWithAIPanel.java @@ -191,7 +191,7 @@ public class AddMapWithAIPanel extends JPanel { }); } - private JsonArray convertToJsonParameterArray(Map> parameters) { + private static JsonArray convertToJsonParameterArray(Map> parameters) { JsonArrayBuilder builder = Json.createArrayBuilder(); for (Map.Entry> entry : parameters.entrySet()) { JsonObjectBuilder entryBuilder = Json.createObjectBuilder(); diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIParametersPanel.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIParametersPanel.java index f67cbd8..9fab7fa 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIParametersPanel.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIParametersPanel.java @@ -27,7 +27,7 @@ import org.openstreetmap.josm.tools.Pair; public class MapWithAIParametersPanel extends JPanel { private final class ParametersTableModel extends AbstractTableModel { - private Set disabledRows = new HashSet<>(); + private final Set disabledRows = new HashSet<>(); @Override public String getColumnName(int column) { @@ -109,8 +109,8 @@ public class MapWithAIParametersPanel extends JPanel { } } - private List headers; - private ParametersTableModel model; + private final List headers; + private final ParametersTableModel model; /** * Creates empty table diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java index 6a9043b..3ca5a1d 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java @@ -12,9 +12,6 @@ import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -53,19 +50,16 @@ import org.openstreetmap.josm.data.imagery.Shape; import org.openstreetmap.josm.data.preferences.NamedColorProperty; import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser; -import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; import org.openstreetmap.josm.gui.preferences.imagery.ImageryProvidersPanel; import org.openstreetmap.josm.gui.util.GuiHelper; import org.openstreetmap.josm.gui.widgets.FilterField; import org.openstreetmap.josm.gui.widgets.HtmlPanel; -import org.openstreetmap.josm.gui.widgets.JosmEditorPane; import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo; import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAICategory; import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo; import org.openstreetmap.josm.tools.GBC; import org.openstreetmap.josm.tools.ImageProvider; import org.openstreetmap.josm.tools.ImageProvider.ImageSizes; -import org.openstreetmap.josm.tools.LanguageInfo; import org.openstreetmap.josm.tools.ListenerList; import org.openstreetmap.josm.tools.Logging; @@ -111,7 +105,7 @@ public class MapWithAIProvidersPanel extends JPanel { private final transient MapWithAILayerInfo layerInfo; private final transient ListenerList areaListeners = ListenerList.create(); - private static interface AreaListener { + private interface AreaListener { void updateArea(Bounds area); } @@ -517,14 +511,12 @@ public class MapWithAIProvidersPanel extends JPanel { private class NewEntryAction extends AbstractAction { private static final long serialVersionUID = 7451336680150337942L; - private final MapWithAIInfo.MapWithAIType type; NewEntryAction(MapWithAIInfo.MapWithAIType type) { putValue(NAME, type.toString()); putValue(SHORT_DESCRIPTION, tr("Add a new {0} entry by entering the URL", type.toString())); String icon = /* ICON(dialogs/) */ "add"; new ImageProvider("dialogs", icon).getResource().attachImageIcon(this, true); - this.type = type; } @Override @@ -841,39 +833,4 @@ public class MapWithAIProvidersPanel extends JPanel { return false; } } - - private static boolean confirmEulaAcceptance(PreferenceTabbedPane gui, String eulaUrl) { - URL url; - try { - url = new URL(eulaUrl.replaceAll("\\{lang\\}", LanguageInfo.getWikiLanguagePrefix())); - JosmEditorPane htmlPane; - try { - htmlPane = new JosmEditorPane(url); - } catch (IOException e1) { - Logging.trace(e1); - // give a second chance with a default Locale 'en' - try { - url = new URL(eulaUrl.replaceAll("\\{lang\\}", "")); - htmlPane = new JosmEditorPane(url); - } catch (IOException e2) { - Logging.debug(e2); - JOptionPane.showMessageDialog(gui, tr("EULA license URL not available: {0}", eulaUrl)); - return false; - } - } - Box box = Box.createVerticalBox(); - htmlPane.setEditable(false); - JScrollPane scrollPane = new JScrollPane(htmlPane); - scrollPane.setPreferredSize(new Dimension(400, 400)); - box.add(scrollPane); - int option = JOptionPane.showConfirmDialog(MainApplication.getMainFrame(), box, - tr("Please abort if you are not sure"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); - if (option == JOptionPane.YES_OPTION) { - return true; - } - } catch (MalformedURLException e2) { - JOptionPane.showMessageDialog(gui, tr("Malformed URL for the EULA licence: {0}", eulaUrl)); - } - return false; - } } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReader.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReader.java index 871eb67..95aa401 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReader.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReader.java @@ -71,6 +71,16 @@ public class MapWithAISourceReader implements Closeable { this.source = source; } + /** + * Parses MapWithAI entry sources + * + * @param jsonObject The json of the data sources + * @return The parsed entries + */ + public static List parseJson(JsonObject jsonObject) { + return jsonObject.entrySet().stream().map(MapWithAISourceReader::parse).collect(Collectors.toList()); + } + /** * Parses MapWithAI source. * @@ -93,16 +103,6 @@ public class MapWithAISourceReader implements Closeable { } } - /** - * Parses MapWithAI entry sources - * - * @param jsonObject The json of the data sources - * @return The parsed entries - */ - public static List parseJson(JsonObject jsonObject) { - return jsonObject.entrySet().stream().map(MapWithAISourceReader::parse).collect(Collectors.toList()); - } - private static MapWithAIInfo parse(Map.Entry entry) { String name = entry.getKey(); if (JsonValue.ValueType.OBJECT.equals(entry.getValue().getValueType())) { diff --git a/test/integration/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReaderTestIT.java b/test/integration/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReaderTestIT.java index 2395be0..aa1aa18 100644 --- a/test/integration/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReaderTestIT.java +++ b/test/integration/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReaderTestIT.java @@ -16,13 +16,16 @@ import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo; import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAIType; import org.openstreetmap.josm.testutils.JOSMTestRules; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + public class MapWithAISourceReaderTestIT { @Rule + @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") public JOSMTestRules rule = new JOSMTestRules().preferences().territories().projection(); @Test public void testDefaultSourceIT() throws IOException { - try (MapWithAISourceReader source = new MapWithAISourceReader(DataAvailability.DEFAULT_SERVER_URL)) { + try (MapWithAISourceReader source = new MapWithAISourceReader(DataAvailability.getReleaseUrl())) { List infoList = source.parse(); assertFalse(infoList.isEmpty()); for (MapWithAIType type : Arrays.asList(MapWithAIType.FACEBOOK, MapWithAIType.THIRD_PARTY)) { diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/UpdateProdTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/UpdateProdTest.java index c8951de..3311f73 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/UpdateProdTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/UpdateProdTest.java @@ -18,6 +18,8 @@ import org.openstreetmap.josm.testutils.JOSMTestRules; import org.openstreetmap.josm.testutils.mockers.OpenBrowserMocker; import org.openstreetmap.josm.testutils.mockers.WindowMocker; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + /** * Test the update prod * @@ -25,6 +27,7 @@ import org.openstreetmap.josm.testutils.mockers.WindowMocker; */ public class UpdateProdTest { @Rule + @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") public JOSMTestRules rule = new JOSMTestRules().preferences(); @Test diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadListenerTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadListenerTest.java index 2d2e299..f3434be 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadListenerTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadListenerTest.java @@ -20,8 +20,11 @@ import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules; import org.openstreetmap.josm.testutils.JOSMTestRules; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + public class DownloadListenerTest { @Rule + @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") public JOSMTestRules rule = new MapWithAITestRules().sources().wiremock().preferences().projection(); @Test @@ -46,7 +49,7 @@ public class DownloadListenerTest { // Test when MapWithAI layer isn't continuous downloading ds.addDataSource(new DataSource(bounds, "Test bounds 2")); - layer.getDataSet().isEmpty(); + assertTrue(layer.getDataSet().isEmpty()); Awaitility.await().atMost(Durations.FIVE_SECONDS).until(() -> !layer.getDataSet().isEmpty()); assertFalse(layer.getDataSet().isEmpty()); diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadMapWithAITaskTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadMapWithAITaskTest.java index 545f381..8c9cee5 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadMapWithAITaskTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadMapWithAITaskTest.java @@ -19,8 +19,11 @@ import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInf import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules; import org.openstreetmap.josm.testutils.JOSMTestRules; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + public class DownloadMapWithAITaskTest { @Rule + @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") public JOSMTestRules rule = new MapWithAITestRules().wiremock().preferences().fakeAPI().projection().territories(); @Test diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnableTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnableTest.java index 18b71a0..4ebf724 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnableTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnableTest.java @@ -32,8 +32,11 @@ import org.openstreetmap.josm.tools.Geometry; import com.github.tomakehurst.wiremock.WireMockServer; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + public class GetDataRunnableTest { @Rule + @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") public JOSMTestRules rule = new MapWithAITestRules().wiremock().projection().fakeAPI().territories(); public static String getDefaultMapWithAIAPIForTest(WireMockServer wireMock, String url) { diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIObjectTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIObjectTest.java index cb6bf74..c6b94aa 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIObjectTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIObjectTest.java @@ -27,12 +27,15 @@ import org.openstreetmap.josm.gui.layer.OsmDataLayer; import org.openstreetmap.josm.plugins.mapwithai.commands.MapWithAIAddCommand; import org.openstreetmap.josm.testutils.JOSMTestRules; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + /** * @author Taylor Smock * */ public class MapWithAIObjectTest { @Rule + @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") public JOSMTestRules rule = new JOSMTestRules().main().projection(); private MapWithAIObject mapWithAIObject; diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MergeDuplicateWaysActionTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MergeDuplicateWaysActionTest.java index 4cb2984..2a834e9 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MergeDuplicateWaysActionTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MergeDuplicateWaysActionTest.java @@ -22,11 +22,14 @@ import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.layer.OsmDataLayer; import org.openstreetmap.josm.testutils.JOSMTestRules; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + /** * @author Taylor Smock */ public class MergeDuplicateWaysActionTest { @Rule + @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") public JOSMTestRules rules = new JOSMTestRules().preferences().projection().main(); MergeDuplicateWaysAction action; diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddComandTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddComandTest.java index e6fe6dd..9cfa730 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddComandTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddComandTest.java @@ -248,7 +248,7 @@ public class MapWithAIAddComandTest { assertNotNull(osmData.getPrimitiveById(176232378, OsmPrimitiveType.NODE)); assertNotNull(osmData.getPrimitiveById(176220609, OsmPrimitiveType.NODE)); assertNotNull(osmData.getPrimitiveById(way)); - Awaitility.await().pollDelay(Durations.ONE_HUNDRED_MILLISECONDS); + Awaitility.await().pollDelay(Durations.ONE_HUNDRED_MILLISECONDS).until(() -> true); List> futures = new ArrayList<>(swingMocker.futureTasks); Assertions.assertDoesNotThrow(() -> { for (Future future : futures) { diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/MergeDuplicateWaysTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/MergeDuplicateWaysTest.java index 522fa31..1b385db 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/MergeDuplicateWaysTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/MergeDuplicateWaysTest.java @@ -217,7 +217,7 @@ public class MergeDuplicateWaysTest { assertFalse(MergeDuplicateWays.checkDirection(set), "The direction is not the same"); pair1.b.a = pair1.b.a - 2; - assertThrows(NullPointerException.class, () -> MergeDuplicateWays.checkDirection(null), + assertThrows(NullPointerException.class, () -> assertNull(MergeDuplicateWays.checkDirection(null)), "Throw an NPE if the argument is null"); assertFalse(MergeDuplicateWays.checkDirection(Collections.emptySet()), diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/conflation/cleanup/MissingConnectionTagsTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/conflation/cleanup/MissingConnectionTagsTest.java index 15fcc80..87d42aa 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/conflation/cleanup/MissingConnectionTagsTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/conflation/cleanup/MissingConnectionTagsTest.java @@ -30,10 +30,12 @@ import org.openstreetmap.josm.plugins.mapwithai.testutils.MissingConnectionTagsM import org.openstreetmap.josm.testutils.JOSMTestRules; import org.openstreetmap.josm.testutils.mockers.WindowMocker; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import mockit.integration.TestRunnerDecorator; public class MissingConnectionTagsTest { @Rule + @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") public JOSMTestRules josmTestRules = new JOSMTestRules().projection().main(); private DataSet ds; private MissingConnectionTags missing; diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfoTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfoTest.java index ee63dd3..caa9ab6 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfoTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfoTest.java @@ -21,7 +21,12 @@ public class MapWithAIInfoTest { assertEquals(type, i.getSourceType()); } - private static Stream provideMapWithAIInfoInitializers() { + /** + * Provide initializers for the tests, along with expected arguments. + * + * @return A stream of arguments for assertInitializersWorked + */ + protected static Stream provideMapWithAIInfoInitializers() { String name = "TEST"; String url = "https://test.url"; String id = "a;lkdjfadl;ksfj"; diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadReaderTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadReaderTest.java index 5b83de0..17b688f 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadReaderTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadReaderTest.java @@ -29,8 +29,11 @@ import org.openstreetmap.josm.testutils.JOSMTestRules; import org.openstreetmap.josm.testutils.mockers.WindowMocker; import org.openstreetmap.josm.tools.ImageProvider; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + public class MapWithAIDownloadReaderTest { @Rule + @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") public JOSMTestRules rules = new MapWithAITestRules().wiremock().projection().territories(); @Test diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/ReplacementPreferenceTableTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/ReplacementPreferenceTableTest.java index 597141b..2e00ca8 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/ReplacementPreferenceTableTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/ReplacementPreferenceTableTest.java @@ -17,6 +17,7 @@ import org.openstreetmap.josm.gui.preferences.advanced.PrefEntry; import org.openstreetmap.josm.testutils.JOSMTestRules; import org.openstreetmap.josm.testutils.mockers.WindowMocker; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import mockit.Mock; import mockit.MockUp; @@ -26,12 +27,17 @@ import mockit.MockUp; */ public class ReplacementPreferenceTableTest { @Rule + @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") public JOSMTestRules rule = new JOSMTestRules().preferences(); ReplacementPreferenceTable test; - private static final class ReplacementPreferenceTableMock extends MockUp { + protected static final class ReplacementPreferenceTableMock extends MockUp { private boolean set; + /** + * @param set the return value for + * {@link ReplacementPreferenceTableMock#askAddSetting} + */ public ReplacementPreferenceTableMock(boolean set) { this.set = set; } @@ -40,6 +46,14 @@ public class ReplacementPreferenceTableTest { protected boolean askAddSetting(JComponent gui, JPanel p) { return set; } + + /** + * @param set the return value for + * {@link ReplacementPreferenceTableMock#askAddSetting} + */ + public void setAskAddSetting(boolean set) { + this.set = set; + } } @Before diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/AddMapWithAIPanelTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/AddMapWithAIPanelTest.java index ca5131f..4de560c 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/AddMapWithAIPanelTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/AddMapWithAIPanelTest.java @@ -18,8 +18,11 @@ import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules; import org.openstreetmap.josm.testutils.JOSMTestRules; import org.openstreetmap.josm.testutils.mockers.WindowMocker; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + public class AddMapWithAIPanelTest { @Rule + @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") public JOSMTestRules rule = new MapWithAITestRules().wiremock().sources().territories().projection() .assertionsInEDT(); @@ -40,7 +43,6 @@ public class AddMapWithAIPanelTest { JosmTextArea rawUrl = (JosmTextArea) rawUrlField.get(panel); JosmTextField name = (JosmTextField) nameField.get(panel); MapWithAIInfo info = (MapWithAIInfo) infoField.get(panel); - MapWithAIParametersPanel parametersTable = (MapWithAIParametersPanel) parametersTableField.get(panel); assertSame(oldInfo, info); assertTrue(rawUrl.getText().isEmpty()); diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReaderTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReaderTest.java index 7fa606e..167a514 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReaderTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReaderTest.java @@ -19,8 +19,11 @@ import org.openstreetmap.josm.testutils.JOSMTestRules; import com.google.common.collect.ImmutableMap; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + public class MapWithAISourceReaderTest { @Rule + @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") public JOSMTestRules rule = new JOSMTestRules().preferences().territories().projection(); @Test diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/MapWithAITestRules.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/MapWithAITestRules.java index e98b75f..d5bfe44 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/MapWithAITestRules.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/MapWithAITestRules.java @@ -105,7 +105,7 @@ public class MapWithAITestRules extends JOSMTestRules { requests.forEach(r -> Logging.error(r.getAbsoluteUrl())); assertTrue(requests.isEmpty()); resetMapWithAILayerInfo(); - DataAvailability.setReleaseUrl(DataAvailability.DEFAULT_SERVER_URL); + DataAvailability.setReleaseUrl(DataAvailability.getReleaseUrl()); Config.getPref().put("osm-server.url", null); } if (workerExceptions) {