kopia lustrzana https://github.com/JOSM/MapWithAI
Spotbugs, errorprone fixes
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
c8d1bba766
commit
21d5c6b477
|
@ -102,7 +102,7 @@ test:
|
|||
paths:
|
||||
- build
|
||||
reports:
|
||||
junit: build/test-results/test/TEST-*.xml
|
||||
junit: build/test-results/**/TEST-*.xml
|
||||
dependencies:
|
||||
- assemble
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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<String, String> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.openstreetmap.josm.tools.Utils;
|
|||
import org.xml.sax.SAXException;
|
||||
|
||||
public class DownloadMapWithAITask extends DownloadOsmTask {
|
||||
private List<MapWithAIInfo> urls;
|
||||
private final List<MapWithAIInfo> urls;
|
||||
|
||||
public DownloadMapWithAITask() {
|
||||
urls = MapWithAILayerInfo.getInstance().getLayers();
|
||||
|
|
|
@ -274,6 +274,17 @@ public class GetDataRunnable extends RecursiveTask<DataSet> {
|
|||
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<Tag, Tag> 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<DataSet> {
|
|||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<Tag, Tag> 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<OsmPrimitive, String> origIds = dataSet.allPrimitives().parallelStream()
|
||||
.filter(prim -> prim.hasKey(MergeDuplicateWays.ORIG_ID)).distinct()
|
||||
|
|
|
@ -112,7 +112,6 @@ public class MissingConnectionTags extends AbstractConflationCommand {
|
|||
|
||||
protected void fixErrors(String prefKey, Collection<Command> commands, Collection<TestError> 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<OsmPrimitive> 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<String> 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<OsmPrimitive> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -110,10 +110,10 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithA
|
|||
}
|
||||
// fuzzy match
|
||||
if (s != null && !s.trim().isEmpty()) {
|
||||
s = s.toLowerCase();
|
||||
s = s.toLowerCase(Locale.ROOT);
|
||||
for (MapWithAICategory type : MapWithAICategory.values()) {
|
||||
if (s.contains(type.getDescription().toLowerCase())
|
||||
|| type.getDescription().toLowerCase().contains(s)) {
|
||||
if (s.contains(type.getDescription().toLowerCase(Locale.ROOT))
|
||||
|| type.getDescription().toLowerCase(Locale.ROOT).contains(s)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithA
|
|||
bounds = new ImageryBounds(e.bounds, ",");
|
||||
if (e.shapes != null) {
|
||||
try {
|
||||
for (String s : e.shapes.split(";")) {
|
||||
for (String s : e.shapes.split(";", -1)) {
|
||||
bounds.addShape(new Shape(s, ","));
|
||||
}
|
||||
} catch (IllegalArgumentException ex) {
|
||||
|
@ -800,6 +800,14 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithA
|
|||
return getParametersString(parameters);
|
||||
}
|
||||
|
||||
private static List<String> 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<MapWithA
|
|||
return getParametersString(this.conflationParameters);
|
||||
}
|
||||
|
||||
private static List<String> 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<MapWithA
|
|||
sb.append(url);
|
||||
if (MapWithAIType.ESRI_FEATURE_SERVER.equals(type)) {
|
||||
if (!url.endsWith("/")) {
|
||||
sb.append("/");
|
||||
sb.append('/');
|
||||
}
|
||||
sb.append("query?geometryType=esriGeometryEnvelope&geometry={bbox}&inSR=4326&f=geojson&outfields=*");
|
||||
}
|
||||
|
|
|
@ -164,7 +164,7 @@ public class MapWithAILayerInfo {
|
|||
private MapWithAISourceReader reader;
|
||||
private boolean canceled;
|
||||
private boolean loadError;
|
||||
private FinishListener listener;
|
||||
private final FinishListener listener;
|
||||
|
||||
DefaultEntryLoader(boolean clearCache, boolean fastFail, FinishListener listener) {
|
||||
super(tr("Update default entries"));
|
||||
|
@ -302,13 +302,8 @@ public class MapWithAILayerInfo {
|
|||
next = "-1";
|
||||
}
|
||||
}
|
||||
Comparator<MapWithAIInfo> comparator = new Comparator<MapWithAIInfo>() {
|
||||
|
||||
@Override
|
||||
public int compare(MapWithAIInfo o1, MapWithAIInfo o2) {
|
||||
return o1.getCategory().getDescription().compareTo(o2.getCategory().getDescription());
|
||||
}
|
||||
};
|
||||
Comparator<MapWithAIInfo> 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<String, String> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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<MapWithAIDownloadReader.MapWithAIDownloadData> {
|
||||
|
||||
|
@ -45,7 +47,14 @@ public class MapWithAIDownloadReader implements DownloadSource<MapWithAIDownload
|
|||
task.setZoomAfterDownload(settings.zoomToData());
|
||||
DownloadParams params = new DownloadParams();
|
||||
params.withNewLayer(settings.asNewLayer());
|
||||
task.download(params, area, null);
|
||||
try {
|
||||
task.download(params, area, null).get();
|
||||
} catch (InterruptedException e) {
|
||||
Logging.error(e);
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (ExecutionException e) {
|
||||
Logging.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -49,7 +49,6 @@ public class MapWithAIPreferences extends DefaultTabPreferenceSetting {
|
|||
private final List<PrefEntry> 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());
|
||||
|
|
|
@ -191,7 +191,7 @@ public class AddMapWithAIPanel extends JPanel {
|
|||
});
|
||||
}
|
||||
|
||||
private JsonArray convertToJsonParameterArray(Map<String, Pair<String, Boolean>> parameters) {
|
||||
private static JsonArray convertToJsonParameterArray(Map<String, Pair<String, Boolean>> parameters) {
|
||||
JsonArrayBuilder builder = Json.createArrayBuilder();
|
||||
for (Map.Entry<String, Pair<String, Boolean>> entry : parameters.entrySet()) {
|
||||
JsonObjectBuilder entryBuilder = Json.createObjectBuilder();
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.openstreetmap.josm.tools.Pair;
|
|||
public class MapWithAIParametersPanel extends JPanel {
|
||||
|
||||
private final class ParametersTableModel extends AbstractTableModel {
|
||||
private Set<Integer> disabledRows = new HashSet<>();
|
||||
private final Set<Integer> disabledRows = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public String getColumnName(int column) {
|
||||
|
@ -109,8 +109,8 @@ public class MapWithAIParametersPanel extends JPanel {
|
|||
}
|
||||
}
|
||||
|
||||
private List<Object[]> headers;
|
||||
private ParametersTableModel model;
|
||||
private final List<Object[]> headers;
|
||||
private final ParametersTableModel model;
|
||||
|
||||
/**
|
||||
* Creates empty table
|
||||
|
|
|
@ -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<AreaListener> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<MapWithAIInfo> 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<MapWithAIInfo> parseJson(JsonObject jsonObject) {
|
||||
return jsonObject.entrySet().stream().map(MapWithAISourceReader::parse).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static MapWithAIInfo parse(Map.Entry<String, JsonValue> entry) {
|
||||
String name = entry.getKey();
|
||||
if (JsonValue.ValueType.OBJECT.equals(entry.getValue().getValueType())) {
|
||||
|
|
|
@ -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<MapWithAIInfo> infoList = source.parse();
|
||||
assertFalse(infoList.isEmpty());
|
||||
for (MapWithAIType type : Arrays.asList(MapWithAIType.FACEBOOK, MapWithAIType.THIRD_PARTY)) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Future<?>> futures = new ArrayList<>(swingMocker.futureTasks);
|
||||
Assertions.assertDoesNotThrow(() -> {
|
||||
for (Future<?> future : futures) {
|
||||
|
|
|
@ -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()),
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -21,7 +21,12 @@ public class MapWithAIInfoTest {
|
|||
assertEquals(type, i.getSourceType());
|
||||
}
|
||||
|
||||
private static Stream<Arguments> provideMapWithAIInfoInitializers() {
|
||||
/**
|
||||
* Provide initializers for the tests, along with expected arguments.
|
||||
*
|
||||
* @return A stream of arguments for assertInitializersWorked
|
||||
*/
|
||||
protected static Stream<Arguments> provideMapWithAIInfoInitializers() {
|
||||
String name = "TEST";
|
||||
String url = "https://test.url";
|
||||
String id = "a;lkdjfadl;ksfj";
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<ReplacementPreferenceTable> {
|
||||
protected static final class ReplacementPreferenceTableMock extends MockUp<ReplacementPreferenceTable> {
|
||||
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
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Ładowanie…
Reference in New Issue