kopia lustrzana https://github.com/JOSM/MapWithAI
Fix an issue where an NPE occurred during tests, and prevent crashes if icons are missing
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
22504d91df
commit
c78074a929
|
@ -11,7 +11,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
@ -172,7 +172,8 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImageIcon getIcon() {
|
public Icon getIcon() {
|
||||||
return ImageProvider.get("mapwithai", ImageProvider.ImageSizes.LAYER);
|
return ImageProvider.getIfAvailable("mapwithai") == null ? super.getIcon()
|
||||||
|
: ImageProvider.get("mapwithai", ImageProvider.ImageSizes.LAYER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Map;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
|
@ -31,7 +32,6 @@ import org.openstreetmap.josm.gui.mappaint.StyleSource;
|
||||||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||||
|
|
||||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||||
import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
|
||||||
|
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
|
|
||||||
|
@ -40,12 +40,11 @@ public class MapWithAIDataUtilsTest {
|
||||||
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||||
public JOSMTestRules test = new JOSMTestRules().preferences().main().projection();
|
public JOSMTestRules test = new JOSMTestRules().preferences().main().projection();
|
||||||
|
|
||||||
@Rule
|
WireMockServer wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock"));
|
||||||
public WireMockRule wireMockRule = new WireMockRule(options().usingFilesUnderDirectory("test/resources/wiremock"));
|
|
||||||
WireMockServer wireMockServer;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
wireMock.start();
|
||||||
MapWithAIPreferenceHelper.setMapWithAIURLs(MapWithAIPreferenceHelper.getMapWithAIURLs().stream().map(map -> {
|
MapWithAIPreferenceHelper.setMapWithAIURLs(MapWithAIPreferenceHelper.getMapWithAIURLs().stream().map(map -> {
|
||||||
map.put("url", getDefaultMapWithAIAPIForTest(
|
map.put("url", getDefaultMapWithAIAPIForTest(
|
||||||
map.getOrDefault("url", MapWithAIPreferenceHelper.DEFAULT_MAPWITHAI_API)));
|
map.getOrDefault("url", MapWithAIPreferenceHelper.DEFAULT_MAPWITHAI_API)));
|
||||||
|
@ -53,12 +52,17 @@ public class MapWithAIDataUtilsTest {
|
||||||
}).collect(Collectors.toList()));
|
}).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
wireMock.stop();
|
||||||
|
}
|
||||||
|
|
||||||
private String getDefaultMapWithAIAPIForTest(String url) {
|
private String getDefaultMapWithAIAPIForTest(String url) {
|
||||||
return getDefaultMapWithAIAPIForTest(url, "https://www.facebook.com");
|
return getDefaultMapWithAIAPIForTest(url, "https://www.facebook.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDefaultMapWithAIAPIForTest(String url, String wireMockReplace) {
|
private String getDefaultMapWithAIAPIForTest(String url, String wireMockReplace) {
|
||||||
return url.replace(wireMockReplace, wireMockRule.baseUrl());
|
return url.replace(wireMockReplace, wireMock.baseUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Ładowanie…
Reference in New Issue