Add more tests for restartless updates

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2019-11-19 07:55:23 -07:00
rodzic dada489816
commit 1b4970dad8
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
2 zmienionych plików z 26 dodań i 2 usunięć

Wyświetl plik

@ -41,7 +41,7 @@ public final class MapWithAIPlugin extends Plugin implements Destroyable {
/** The name of the plugin */
public static final String NAME = "MapWithAI";
private static final String PAINTSTYLE_PREEXISTS = NAME.concat(".paintstyleprexists");
protected static final String PAINTSTYLE_PREEXISTS = NAME.concat(".paintstyleprexists");
private static String versionInfo;
private final PreferenceSetting preferenceSetting;
@ -142,7 +142,7 @@ public final class MapWithAIPlugin extends Plugin implements Destroyable {
MainApplication.getLayerManager().getLayersOfType(MapWithAILayer.class).stream()
.forEach(layer -> MainApplication.getLayerManager().removeLayer(layer));
if (Config.getPref().getBoolean(PAINTSTYLE_PREEXISTS)) {
if (!Config.getPref().getBoolean(PAINTSTYLE_PREEXISTS)) {
MapWithAIDataUtils.removeMapWithAIPaintStyles();
}

Wyświetl plik

@ -4,9 +4,12 @@ package org.openstreetmap.josm.plugins.mapwithai;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import javax.swing.JMenu;
import org.awaitility.Awaitility;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
@ -14,6 +17,8 @@ import org.junit.Test;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
import org.openstreetmap.josm.plugins.PluginInformation;
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIDataUtils;
import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@ -61,6 +66,25 @@ public class MapWithAIPluginTest {
Assert.assertEquals(dataMenuSize + 4, dataMenu.getMenuComponentCount());
Assert.assertEquals(1, MapPaintStyles.getStyles().getStyleSources().parallelStream()
.filter(source -> source.url != null && source.name.contains("MapWithAI")).count());
for (boolean existed : Arrays.asList(false, true)) { // false, true order is important
plugin = new MapWithAIPlugin(info);
Config.getPref().putBoolean(MapWithAIPlugin.PAINTSTYLE_PREEXISTS, existed);
plugin.destroy();
Assert.assertEquals(dataMenuSize, dataMenu.getMenuComponentCount());
Awaitility.await().atMost(5, TimeUnit.SECONDS)
.until(() -> existed == MapWithAIDataUtils.checkIfMapWithAIPaintStyleExists());
Assert.assertEquals(Config.getPref().getBoolean(MapWithAIPlugin.PAINTSTYLE_PREEXISTS) ? 1 : 0,
MapPaintStyles.getStyles().getStyleSources().parallelStream()
.filter(source -> source.url != null && source.name.contains("MapWithAI")).count());
}
for (int i = 0; i < 3; i++) {
plugin = new MapWithAIPlugin(info);
Assert.assertEquals(dataMenuSize + 4, dataMenu.getMenuComponentCount());
Assert.assertEquals(1, MapPaintStyles.getStyles().getStyleSources().parallelStream()
.filter(source -> source.url != null && source.name.contains("MapWithAI")).count());
}
}
/**