Changeset 14052 in josm for trunk/test/unit/org/openstreetmap/josm/actions
- Timestamp:
- 2018-07-26T22:01:31+02:00 (7 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm/actions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/actions/ExitActionTest.java
r11101 r14052 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.actions; 3 4 import static org.junit.Assert.assertTrue; 3 5 4 6 import org.junit.Rule; 5 7 import org.junit.Test; 6 8 import org.junit.contrib.java.lang.system.ExpectedSystemExit; 9 import org.openstreetmap.josm.gui.MainApplication; 10 import org.openstreetmap.josm.gui.progress.swing.ProgressMonitorExecutor; 7 11 import org.openstreetmap.josm.testutils.JOSMTestRules; 12 import org.openstreetmap.josm.tools.ImageProvider; 13 14 import mockit.Invocation; 15 import mockit.Mock; 16 import mockit.MockUp; 8 17 9 18 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 33 42 public void testActionPerformed() { 34 43 exit.expectSystemExitWithStatus(0); 44 45 boolean[] workerShutdownCalled = {false}; 46 boolean[] workerShutdownNowCalled = {false}; 47 boolean[] imageProviderShutdownCalled = {false}; 48 49 // critically we don't proceed into the actual implementation in any of these mock methods - 50 // that would be quite annoying for tests following this one which were expecting to use any 51 // of these 52 new MockUp<ProgressMonitorExecutor>() { 53 @Mock 54 private void shutdown(Invocation invocation) { 55 if (invocation.getInvokedInstance() == MainApplication.worker) { 56 workerShutdownCalled[0] = true; 57 } 58 } 59 60 @Mock 61 private void shutdownNow(Invocation invocation) { 62 if (invocation.getInvokedInstance() == MainApplication.worker) { 63 // regular shutdown should have been called first 64 assertTrue(workerShutdownCalled[0]); 65 workerShutdownNowCalled[0] = true; 66 } 67 } 68 }; 69 new MockUp<ImageProvider>() { 70 @Mock 71 private void shutdown(Invocation invocation) { 72 imageProviderShutdownCalled[0] = true; 73 } 74 }; 75 35 76 // No layer 77 36 78 new ExitAction().actionPerformed(null); 79 80 assertTrue(workerShutdownCalled[0]); 81 assertTrue(workerShutdownNowCalled[0]); 82 assertTrue(imageProviderShutdownCalled[0]); 37 83 } 38 84 } -
trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/PluginDownloadTaskTest.java
r13300 r14052 56 56 @Test 57 57 public void testUpdatePluginValid() throws Exception { 58 this.pluginPath = "plugin/dummy_plugin.jar"; 58 this.pluginPath = "plugin/dummy_plugin.v31772.jar"; 59 59 this.mockHttp(); 60 60 … … 74 74 75 75 // get PluginInformation from jar file 76 final PluginInformation pluginInformation = new PluginInformation(srcPluginFile); 76 final PluginInformation pluginInformation = new PluginInformation(srcPluginFile, "dummy_plugin"); 77 77 // ...and grafting on the downloadlink 78 78 pluginInformation.downloadlink = this.getRemoteFileUrl(); … … 87 87 // the ".jar.new" file should have been deleted 88 88 assertFalse(pluginFileNew.exists()); 89 // the ".jar" file should still exist 90 assertTrue(pluginFile.exists()); 91 try ( 92 FileInputStream pluginDirPluginStream = new FileInputStream(pluginFile); 93 FileInputStream srcPluginStream = new FileInputStream(srcPluginFile); 94 ) { 95 // and its contents should equal those that were served to the task 96 assertArrayEquals( 97 ByteStreams.toByteArray(pluginDirPluginStream), 98 ByteStreams.toByteArray(srcPluginStream) 99 ); 100 } 89 // the ".jar" file should still exist and its contents should equal those that were served to the task 90 TestUtils.assertFileContentsEqual(pluginFile, srcPluginFile); 101 91 } 102 92 … … 140 130 } 141 131 142 // the ".jar.new" file should exist, even though invalid143 assertTrue(pluginFileNew.exists());132 // assert that the "corrupt" jar file made it through in tact 133 TestUtils.assertFileContentsEqual(pluginFileNew, srcPluginFile); 144 134 // the ".jar" file should still exist 145 135 assertTrue(pluginFile.exists()); 146 136 try ( 147 FileInputStream pluginDirPluginNewStream = new FileInputStream(pluginFileNew);148 137 FileInputStream pluginDirPluginStream = new FileInputStream(pluginFile); 149 FileInputStream srcPluginStream = new FileInputStream(srcPluginFile);150 138 ) { 151 139 // the ".jar" file's contents should be as before … … 154 142 ByteStreams.toByteArray(pluginDirPluginStream) 155 143 ); 156 // just assert that the "corrupt" jar file made it through in tact157 assertArrayEquals(158 ByteStreams.toByteArray(pluginDirPluginNewStream),159 ByteStreams.toByteArray(srcPluginStream)160 );161 144 } 162 145 }
Note:
See TracChangeset
for help on using the changeset viewer.