Ticket #16590: v1-0001-ExitActionTest-mock-out-JCSCacheManager.shutdown-.patch

File v1-0001-ExitActionTest-mock-out-JCSCacheManager.shutdown-.patch, 3.4 KB (added by ris, 7 years ago)
  • test/unit/org/openstreetmap/josm/actions/ExitActionTest.java

    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;  
    77import org.junit.Test;
    88import org.junit.contrib.java.lang.system.ExpectedSystemExit;
    99import org.openstreetmap.josm.TestUtils;
     10import org.openstreetmap.josm.data.cache.JCSCacheManager;
    1011import org.openstreetmap.josm.gui.MainApplication;
    1112import org.openstreetmap.josm.gui.progress.swing.ProgressMonitorExecutor;
    1213import org.openstreetmap.josm.testutils.JOSMTestRules;
    public final class ExitActionTest {  
    4546
    4647        boolean[] workerShutdownCalled = {false};
    4748        boolean[] workerShutdownNowCalled = {false};
    48         boolean[] imageProviderShutdownCalled = {false};
     49        boolean[] imageProviderShutdownCalledNowFalse = {false};
     50        boolean[] imageProviderShutdownCalledNowTrue = {false};
     51        boolean[] jcsCacheManagerShutdownCalled = {false};
    4952
    5053        // critically we don't proceed into the actual implementation in any of these mock methods -
    5154        // that would be quite annoying for tests following this one which were expecting to use any
    public final class ExitActionTest {  
    6972        };
    7073        new MockUp<ImageProvider>() {
    7174            @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
    7287            private void shutdown(Invocation invocation) {
    73                 imageProviderShutdownCalled[0] = true;
     88                jcsCacheManagerShutdownCalled[0] = true;
    7489            }
    7590        };
    7691
    7792        // No layer
    7893
    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        }
    84105    }
    85106}