Skip to content

Commit

Permalink
Only reset MapWithAILayerInfo if the @Territories annotation is ued
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Jul 26, 2023
1 parent 35bad2f commit 3fdb8b0
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -108,28 +109,30 @@ 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();
MapWithAILayerInfo.getInstance().load(false, () -> finished.set(true));
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();
}
}

Expand Down

0 comments on commit 3fdb8b0

Please sign in to comment.