From 817b3c0c094af6201cf2f32e95980e4e07a58ab0 Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Sat, 11 Nov 2017 21:33:40 +0000
Subject: [PATCH 6/6] MinimapDialogTest: make use of Awaitility to replace
calls to Thread.sleep()
this commit depends on awaitility-3.0.0.jar being present in test/lib/
---
.../josm/gui/dialogs/MinimapDialogTest.java | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java b/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java
index 3635b3448..2fbb0a1fb 100644
|
a
|
b
|
import static org.junit.Assert.assertFalse;
|
| 6 | 6 | import static org.junit.Assert.assertTrue; |
| 7 | 7 | import static org.junit.Assert.fail; |
| 8 | 8 | |
| | 9 | import static java.util.concurrent.TimeUnit.MILLISECONDS; |
| | 10 | |
| 9 | 11 | import java.awt.Color; |
| 10 | 12 | import java.awt.Component; |
| 11 | 13 | import java.awt.Graphics2D; |
| … |
… |
import java.awt.image.BufferedImage;
|
| 14 | 16 | import javax.swing.JMenuItem; |
| 15 | 17 | import javax.swing.JPopupMenu; |
| 16 | 18 | |
| | 19 | import java.util.concurrent.Callable; |
| | 20 | |
| 17 | 21 | import org.junit.Rule; |
| 18 | 22 | import org.junit.Test; |
| 19 | 23 | import org.openstreetmap.josm.Main; |
| … |
… |
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
| 24 | 28 | |
| 25 | 29 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| 26 | 30 | |
| | 31 | import org.awaitility.Awaitility; |
| | 32 | |
| 27 | 33 | /** |
| 28 | 34 | * Unit tests of {@link MinimapDialog} class. |
| 29 | 35 | */ |
| … |
… |
public class MinimapDialogTest {
|
| 119 | 125 | this.slippyMap.paintAll(g); |
| 120 | 126 | } |
| 121 | 127 | |
| | 128 | protected Callable<Boolean> slippyMapTasksFinished() { |
| | 129 | return () -> !this.slippyMap.getTileController().getTileLoader().hasOutstandingTasks(); |
| | 130 | } |
| | 131 | |
| 122 | 132 | /** |
| 123 | 133 | * Tests to switch imagery source. |
| 124 | 134 | * @throws Exception if any error occurs |
| … |
… |
public class MinimapDialogTest {
|
| 133 | 143 | // an initial paint operation is required to trigger the tile fetches |
| 134 | 144 | this.paintSlippyMap(); |
| 135 | 145 | |
| 136 | | Thread.sleep(500); |
| | 146 | Awaitility.await().atMost(1000, MILLISECONDS).until(this.slippyMapTasksFinished()); |
| 137 | 147 | |
| 138 | 148 | this.paintSlippyMap(); |
| 139 | 149 | |
| … |
… |
public class MinimapDialogTest {
|
| 146 | 156 | // call paint to trigger new tile fetch |
| 147 | 157 | this.paintSlippyMap(); |
| 148 | 158 | |
| 149 | | Thread.sleep(500); |
| | 159 | Awaitility.await().atMost(1000, MILLISECONDS).until(this.slippyMapTasksFinished()); |
| 150 | 160 | |
| 151 | 161 | this.paintSlippyMap(); |
| 152 | 162 | |
| … |
… |
public class MinimapDialogTest {
|
| 157 | 167 | // call paint to trigger new tile fetch |
| 158 | 168 | this.paintSlippyMap(); |
| 159 | 169 | |
| 160 | | Thread.sleep(500); |
| | 170 | Awaitility.await().atMost(1000, MILLISECONDS).until(this.slippyMapTasksFinished()); |
| 161 | 171 | |
| 162 | 172 | this.paintSlippyMap(); |
| 163 | 173 | |
| … |
… |
public class MinimapDialogTest {
|
| 181 | 191 | // an initial paint operation is required to trigger the tile fetches |
| 182 | 192 | this.paintSlippyMap(); |
| 183 | 193 | |
| 184 | | Thread.sleep(500); |
| | 194 | Awaitility.await().atMost(1000, MILLISECONDS).until(this.slippyMapTasksFinished()); |
| 185 | 195 | |
| 186 | 196 | this.paintSlippyMap(); |
| 187 | 197 | |
| … |
… |
public class MinimapDialogTest {
|
| 208 | 218 | // an initial paint operation is required to trigger the tile fetches |
| 209 | 219 | this.paintSlippyMap(); |
| 210 | 220 | |
| 211 | | Thread.sleep(500); |
| | 221 | Awaitility.await().atMost(1000, MILLISECONDS).until(this.slippyMapTasksFinished()); |
| 212 | 222 | |
| 213 | 223 | this.paintSlippyMap(); |
| 214 | 224 | |