From 3fdb8b0560030e0860bf465e5c45340854512c60 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Wed, 26 Jul 2023 08:30:01 -0600 Subject: [PATCH] Only reset MapWithAILayerInfo if the @Territories annotation is ued Signed-off-by: Taylor Smock --- .../testutils/annotations/Wiremock.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/annotations/Wiremock.java b/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/annotations/Wiremock.java index 3fc04e88..856c26e8 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/annotations/Wiremock.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/annotations/Wiremock.java @@ -12,6 +12,7 @@ import org.awaitility.Durations; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.platform.commons.support.AnnotationSupport; import org.openstreetmap.josm.plugins.mapwithai.backend.DataAvailability; import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIConflationCategory; import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo; @@ -108,13 +109,14 @@ public void afterAll(ExtensionContext context) throws Exception { try { super.afterAll(context); } finally { - resetMapWithAILayerInfo(); + resetMapWithAILayerInfo(context); } } @Override public void beforeAll(ExtensionContext context) throws Exception { super.beforeAll(context); + MapWithAILayerInfo.setImageryLayersSites(null); AtomicBoolean finished = new AtomicBoolean(); MapWithAILayerInfo.getInstance().clear(); @@ -122,14 +124,15 @@ public void beforeAll(ExtensionContext context) throws Exception { Awaitility.await().atMost(Durations.TEN_SECONDS).until(finished::get); } - private static void resetMapWithAILayerInfo() { - // This should probably only be run if territories is initialized - // TODO update if @Territories becomes an annotation + private static void resetMapWithAILayerInfo(ExtensionContext context) { synchronized (MapWithAILayerInfo.class) { - MapWithAILayerInfo.getInstance().clear(); - MapWithAILayerInfo.getInstance().getDefaultLayers().stream().filter(MapWithAIInfo::isDefaultEntry) - .forEach(MapWithAILayerInfo.getInstance()::add); - MapWithAILayerInfo.getInstance().save(); + final var info = MapWithAILayerInfo.getInstance(); + info.clear(); + if (false && AnnotationSupport.isAnnotated(context.getTestClass(), Territories.class)) { + // This should probably only be run if territories is initialized + info.getDefaultLayers().stream().filter(MapWithAIInfo::isDefaultEntry).forEach(info::add); + } + info.save(); } }