Ticket #16010: v2-0008-JOSMTestRules-attempt-to-close-all-windows-left-o.patch

File v2-0008-JOSMTestRules-attempt-to-close-all-windows-left-o.patch, 1.9 KB (added by ris, 15 months ago)
  • test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    From 98ddb963f200e9c0640aa900b40656f0aefd0261 Mon Sep 17 00:00:00 2001
    From: Robert Scott <code@humanleg.org.uk>
    Date: Mon, 26 Mar 2018 20:23:51 +0100
    Subject: [PATCH v2 08/28] JOSMTestRules: attempt to close all windows left
     open after each test
    
    ---
     .../openstreetmap/josm/testutils/JOSMTestRules.java    | 18 ++++++++++++++++++
     1 file changed, 18 insertions(+)
    
    diff --git a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
    index 03d7cb3b8..c56aad0aa 100644
    a b  
    22package org.openstreetmap.josm.testutils;
    33
    44import java.awt.Color;
     5import java.awt.Window;
     6import java.awt.event.WindowEvent;
    57import java.io.ByteArrayInputStream;
    68import java.io.File;
    79import java.io.IOException;
    810import java.security.GeneralSecurityException;
    911import java.text.MessageFormat;
     12import java.util.Arrays;
    1013import java.util.TimeZone;
    1114
    1215import org.junit.rules.TemporaryFolder;
    public class JOSMTestRules implements TestRule { 
    575578            TestUtils.setPrivateStaticField(Version.class, "instance", this.originalVersion);
    576579        }
    577580
     581        Window[] windows = Window.getWindows();
     582        if (windows.length != 0) {
     583            Logging.info(
     584                "Attempting to close {0} windows left open by tests: {1}",
     585                windows.length,
     586                Arrays.toString(windows)
     587            );
     588        }
     589        GuiHelper.runInEDTAndWait(() -> {
     590            for (Window window : windows) {
     591                window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
     592                window.dispose();
     593            }
     594        });
     595
    578596        // Parts of JOSM uses weak references - destroy them.
    579597        System.gc();
    580598    }