From b09c7594fb301428ed6c6de44ca0029880c8d112 Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Sat, 11 Aug 2018 15:30:39 +0100
Subject: [PATCH v1 1/2] ExitActionTest: mock out JCSCacheManager.shutdown() to
prevent this annoyance from leaking to later tests
also fix assertions to actually run, remove isHeadless() guards around ImageProvider.shutdown(...)
---
.../openstreetmap/josm/actions/ExitActionTest.java | 35 +++++++++++++++++-----
1 file changed, 28 insertions(+), 7 deletions(-)
diff --git a/test/unit/org/openstreetmap/josm/actions/ExitActionTest.java b/test/unit/org/openstreetmap/josm/actions/ExitActionTest.java
index f4c5f47ed..d5aab9ef9 100644
a
|
b
|
import org.junit.Rule;
|
7 | 7 | import org.junit.Test; |
8 | 8 | import org.junit.contrib.java.lang.system.ExpectedSystemExit; |
9 | 9 | import org.openstreetmap.josm.TestUtils; |
| 10 | import org.openstreetmap.josm.data.cache.JCSCacheManager; |
10 | 11 | import org.openstreetmap.josm.gui.MainApplication; |
11 | 12 | import org.openstreetmap.josm.gui.progress.swing.ProgressMonitorExecutor; |
12 | 13 | import org.openstreetmap.josm.testutils.JOSMTestRules; |
… |
… |
public final class ExitActionTest {
|
45 | 46 | |
46 | 47 | boolean[] workerShutdownCalled = {false}; |
47 | 48 | boolean[] workerShutdownNowCalled = {false}; |
48 | | boolean[] imageProviderShutdownCalled = {false}; |
| 49 | boolean[] imageProviderShutdownCalledNowFalse = {false}; |
| 50 | boolean[] imageProviderShutdownCalledNowTrue = {false}; |
| 51 | boolean[] jcsCacheManagerShutdownCalled = {false}; |
49 | 52 | |
50 | 53 | // critically we don't proceed into the actual implementation in any of these mock methods - |
51 | 54 | // that would be quite annoying for tests following this one which were expecting to use any |
… |
… |
public final class ExitActionTest {
|
69 | 72 | }; |
70 | 73 | new MockUp<ImageProvider>() { |
71 | 74 | @Mock |
| 75 | private void shutdown(Invocation invocation, boolean now) { |
| 76 | if (now) { |
| 77 | // should have already been called with now = false |
| 78 | assertTrue(imageProviderShutdownCalledNowFalse[0]); |
| 79 | imageProviderShutdownCalledNowTrue[0] = true; |
| 80 | } else { |
| 81 | imageProviderShutdownCalledNowFalse[0] = true; |
| 82 | } |
| 83 | } |
| 84 | }; |
| 85 | new MockUp<JCSCacheManager>() { |
| 86 | @Mock |
72 | 87 | private void shutdown(Invocation invocation) { |
73 | | imageProviderShutdownCalled[0] = true; |
| 88 | jcsCacheManagerShutdownCalled[0] = true; |
74 | 89 | } |
75 | 90 | }; |
76 | 91 | |
77 | 92 | // No layer |
78 | 93 | |
79 | | new ExitAction().actionPerformed(null); |
80 | | |
81 | | assertTrue(workerShutdownCalled[0]); |
82 | | assertTrue(workerShutdownNowCalled[0]); |
83 | | assertTrue(imageProviderShutdownCalled[0]); |
| 94 | try { |
| 95 | new ExitAction().actionPerformed(null); |
| 96 | } finally { |
| 97 | // ExpectedSystemExit presumably works using an exception, so executing anything after the |
| 98 | // previous line requires it to be put in a finally block |
| 99 | assertTrue(workerShutdownCalled[0]); |
| 100 | assertTrue(workerShutdownNowCalled[0]); |
| 101 | assertTrue(imageProviderShutdownCalledNowFalse[0]); |
| 102 | assertTrue(imageProviderShutdownCalledNowTrue[0]); |
| 103 | assertTrue(jcsCacheManagerShutdownCalled[0]); |
| 104 | } |
84 | 105 | } |
85 | 106 | } |