Changeset 16672 in josm for trunk/test/unit


Ignore:
Timestamp:
2020-06-17T21:47:17+02:00 (4 years ago)
Author:
simon04
Message:

see #19381 - Upload dialog: make warnings less intrusive

Location:
trunk/test/unit/org/openstreetmap/josm/gui/io
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/io/UploadDialogTest.java

    r16160 r16672  
    1515import java.util.function.Supplier;
    1616
    17 import javax.swing.JButton;
    1817import javax.swing.JOptionPane;
    1918
     
    2120import org.junit.Test;
    2221import org.openstreetmap.josm.TestUtils;
    23 import org.openstreetmap.josm.gui.ExtendedDialog;
    2422import org.openstreetmap.josm.gui.io.UploadDialog.UploadAction;
    2523import org.openstreetmap.josm.io.UploadStrategySpecification;
    2624import org.openstreetmap.josm.spi.preferences.Config;
    2725import org.openstreetmap.josm.testutils.JOSMTestRules;
    28 import org.openstreetmap.josm.testutils.mockers.ExtendedDialogMocker;
    2926import org.openstreetmap.josm.testutils.mockers.WindowMocker;
    3027
    3128import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    32 import mockit.Invocation;
    33 import mockit.Mock;
    3429
    3530/**
     
    119114        MockUploadDialog uploadDialog = new MockUploadDialog(null, null);
    120115        new UploadDialog.CancelAction(uploadDialog).actionPerformed(null);
    121     }
    122 
    123     /**
    124      * Test of {@link UploadDialog.UploadAction} class.
    125      */
    126     @Test
    127     public void testUploadAction() {
    128         TestUtils.assumeWorkingJMockit();
    129         ExtendedDialogMocker edMocker = new ExtendedDialogMocker() {
    130             @Mock
    131             void setupDialog(Invocation invocation) throws Exception {
    132                 if (GraphicsEnvironment.isHeadless()) {
    133                     final int nButtons = ((String[]) TestUtils.getPrivateField(
    134                             ExtendedDialog.class, invocation.getInvokedInstance(), "bTexts")).length;
    135                     @SuppressWarnings("unchecked")
    136                     final List<JButton> buttons = (List<JButton>) TestUtils.getPrivateField(
    137                             ExtendedDialog.class, invocation.getInvokedInstance(), "buttons");
    138 
    139                     for (int i = 0; i < nButtons; i++) {
    140                         buttons.add(new JButton());
    141                     }
    142                 } else {
    143                     invocation.proceed();
    144                 }
    145             }
    146         };
    147         edMocker.getMockResultMap().put("<html>Your upload comment is <i>empty</i>, or <i>very short</i>.<br /><br />This is "
    148                 + "technically allowed, but please consider that many users who are<br />watching changes "
    149                 + "in their area depend on meaningful changeset comments<br />to understand what is going "
    150                 + "on!<br /><br />If you spend a minute now to explain your change, you will make life<br />"
    151                 + "easier for many other mappers.</html>", "Revise");
    152         edMocker.getMockResultMap().put("<html>You did not specify a source for your changes.<br />It is technically allowed, "
    153                 + "but this information helps<br />other users to understand the origins of the data."
    154                 + "<br /><br />If you spend a minute now to explain your change, you will make life"
    155                 + "<br />easier for many other mappers.</html>", "Revise");
    156 
    157         MockUploadDialog uploadDialog = new MockUploadDialog("comment", "source");
    158         new UploadDialog.UploadAction(uploadDialog).actionPerformed(null);
    159 
    160         assertEquals(1, uploadDialog.handleMissingCommentCalls);
    161         assertEquals(0, uploadDialog.handleMissingSourceCalls);
    162         assertEquals(1, edMocker.getInvocationLog().size());
    163         Object[] invocationLogEntry = edMocker.getInvocationLog().get(0);
    164         assertEquals(1, (int) invocationLogEntry[0]);
    165         assertEquals("Please revise upload comment", invocationLogEntry[2]);
    166         edMocker.resetInvocationLog();
    167 
    168         uploadDialog = new MockUploadDialog("", "source");
    169         new UploadDialog.UploadAction(uploadDialog).actionPerformed(null);
    170 
    171         assertEquals(1, uploadDialog.handleMissingCommentCalls);
    172         assertEquals(0, uploadDialog.handleMissingSourceCalls);
    173         assertEquals(1, edMocker.getInvocationLog().size());
    174         invocationLogEntry = edMocker.getInvocationLog().get(0);
    175         assertEquals(1, (int) invocationLogEntry[0]);
    176         assertEquals("Please revise upload comment", invocationLogEntry[2]);
    177         edMocker.resetInvocationLog();
    178 
    179         uploadDialog = new MockUploadDialog("comment", "");
    180         new UploadDialog.UploadAction(uploadDialog).actionPerformed(null);
    181 
    182         assertEquals(1, uploadDialog.handleMissingCommentCalls);
    183         assertEquals(0, uploadDialog.handleMissingSourceCalls);
    184         assertEquals(1, edMocker.getInvocationLog().size());
    185         invocationLogEntry = edMocker.getInvocationLog().get(0);
    186         assertEquals(1, (int) invocationLogEntry[0]);
    187         assertEquals("Please revise upload comment", invocationLogEntry[2]);
    188         edMocker.resetInvocationLog();
    189 
    190         uploadDialog = new MockUploadDialog("a comment long enough", "");
    191         new UploadDialog.UploadAction(uploadDialog).actionPerformed(null);
    192 
    193         assertEquals(0, uploadDialog.handleMissingCommentCalls);
    194         assertEquals(1, uploadDialog.handleMissingSourceCalls);
    195         assertEquals(1, edMocker.getInvocationLog().size());
    196         invocationLogEntry = edMocker.getInvocationLog().get(0);
    197         assertEquals(1, (int) invocationLogEntry[0]);
    198         assertEquals("Please specify a changeset source", invocationLogEntry[2]);
    199         edMocker.resetInvocationLog();
    200 
    201         uploadDialog = new MockUploadDialog("a comment long enough", "a source long enough");
    202         new UploadDialog.UploadAction(uploadDialog).actionPerformed(null);
    203 
    204         assertEquals(0, uploadDialog.handleMissingCommentCalls);
    205         assertEquals(0, uploadDialog.handleMissingSourceCalls);
    206         assertEquals(0, edMocker.getInvocationLog().size());
    207116    }
    208117
Note: See TracChangeset for help on using the changeset viewer.