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
|
|
| 2 | 2 | package org.openstreetmap.josm.testutils; |
| 3 | 3 | |
| 4 | 4 | import java.awt.Color; |
| | 5 | import java.awt.Window; |
| | 6 | import java.awt.event.WindowEvent; |
| 5 | 7 | import java.io.ByteArrayInputStream; |
| 6 | 8 | import java.io.File; |
| 7 | 9 | import java.io.IOException; |
| 8 | 10 | import java.security.GeneralSecurityException; |
| 9 | 11 | import java.text.MessageFormat; |
| | 12 | import java.util.Arrays; |
| 10 | 13 | import java.util.TimeZone; |
| 11 | 14 | |
| 12 | 15 | import org.junit.rules.TemporaryFolder; |
| … |
… |
public class JOSMTestRules implements TestRule {
|
| 575 | 578 | TestUtils.setPrivateStaticField(Version.class, "instance", this.originalVersion); |
| 576 | 579 | } |
| 577 | 580 | |
| | 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 | |
| 578 | 596 | // Parts of JOSM uses weak references - destroy them. |
| 579 | 597 | System.gc(); |
| 580 | 598 | } |