Changeset 14062 in josm for trunk/test


Ignore:
Timestamp:
2018-07-28T20:28:36+02:00 (6 years ago)
Author:
Don-vip
Message:

see #16010 - bugfixes (patch by ris)

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongTrackActionTest.java

    r12636 r14062  
    22package org.openstreetmap.josm.gui.layer.gpx;
    33
     4import static org.junit.Assert.assertEquals;
    45import static org.junit.Assert.assertNotNull;
    56import static org.junit.Assert.assertNull;
     
    1516import org.openstreetmap.josm.io.GpxReaderTest;
    1617import org.openstreetmap.josm.testutils.JOSMTestRules;
     18import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker;
     19
     20import com.google.common.collect.ImmutableMap;
    1721
    1822import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    3135
    3236    private static PleaseWaitRunnable createTask(String file) throws Exception {
     37        // click "Download" when presented with the appropriate HelpAwareOptionPane
     38        final HelpAwareOptionPaneMocker haMocker = new HelpAwareOptionPaneMocker(ImmutableMap.of(
     39            "DownloadAlongPanel", "Download"
     40        )) {
     41            // expected "message" for HelpAwareOptionPane call is not a simple string, so instead
     42            // just detect the class name of the message object
     43            @Override
     44            protected String getStringFromMessage(final Object message) {
     45                return message instanceof String ? (String) message : message.getClass().getSimpleName();
     46            }
     47        };
     48
    3349        final OsmDataLayer layer = new OsmDataLayer(new DataSet(), DownloadAlongTrackActionTest.class.getName(), null);
    3450        try {
     
    3652            // Perform action
    3753            final GpxData gpx = GpxReaderTest.parseGpxData(TestUtils.getTestDataRoot() + file);
    38             return new DownloadAlongTrackAction(gpx).createTask();
     54            final PleaseWaitRunnable retval = new DownloadAlongTrackAction(gpx).createTask();
     55
     56            // assert that we were indeed presented with the expected HelpAwareOptionPane
     57            assertEquals(1, haMocker.getInvocationLog().size());
     58            assertEquals(0, haMocker.getInvocationLog().get(0)[0]);
     59            assertEquals("DownloadAlongPanel", haMocker.getInvocationLog().get(0)[1]);
     60            assertEquals("Download from OSM along this track", haMocker.getInvocationLog().get(0)[2]);
     61
     62            return retval;
    3963        } finally {
    4064            // Ensure we clean the place before leaving, even if test fails.
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferenceHighLevelTest.java

    r14054 r14062  
    232232        assertEquals(1, haMocker.getInvocationLog().size());
    233233        Object[] invocationLogEntry = haMocker.getInvocationLog().get(0);
    234         assertEquals(2, (int) invocationLogEntry[0]);
     234        assertEquals(1, (int) invocationLogEntry[0]);
    235235        assertEquals("Restart", invocationLogEntry[2]);
    236236
     
    354354        assertEquals(1, haMocker.getInvocationLog().size());
    355355        Object[] invocationLogEntry = haMocker.getInvocationLog().get(0);
    356         assertEquals(2, (int) invocationLogEntry[0]);
     356        assertEquals(1, (int) invocationLogEntry[0]);
    357357        assertEquals("Restart", invocationLogEntry[2]);
    358358
  • trunk/test/unit/org/openstreetmap/josm/testutils/mockers/HelpAwareOptionPaneMocker.java

    r14052 r14062  
    101101                ));
    102102            }
    103             // buttons are numbered with 1-based indexing
    104             return optIndex.getAsInt() + 1;
     103            return optIndex.getAsInt();
    105104        }
    106105    }
     
    162161                    retval
    163162                ));
    164             } else if (retval > (options == null ? 0 : options.length)) {  // NOTE 1-based indexing
     163            } else if (retval > (options == null ? 0 : options.length-1)) {
    165164                fail(String.format(
    166165                    "Invalid result for HelpAwareOptionPane: %s (in call with options = %s)",
Note: See TracChangeset for help on using the changeset viewer.