Ignore:
Timestamp:
2018-07-26T22:01:31+02:00 (6 years ago)
Author:
Don-vip
Message:

see #16010 - use JMockit to enable more extensive test coverage (patch by ris, modified)

see https://github.com/openstreetmap/josm/pull/24/commits for details

Location:
trunk/src/org/openstreetmap/josm/gui/preferences
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java

    r13431 r14052  
    2626import javax.swing.JScrollPane;
    2727import javax.swing.JTabbedPane;
    28 import javax.swing.SwingUtilities;
    2928import javax.swing.event.ChangeEvent;
    3029import javax.swing.event.ChangeListener;
     
    6059import org.openstreetmap.josm.gui.preferences.validator.ValidatorTagCheckerRulesPreference;
    6160import org.openstreetmap.josm.gui.preferences.validator.ValidatorTestsPreference;
     61import org.openstreetmap.josm.gui.util.GuiHelper;
    6262import org.openstreetmap.josm.plugins.PluginDownloadTask;
    6363import org.openstreetmap.josm.plugins.PluginHandler;
     
    175175            }
    176176
    177             Main.parent.repaint();
     177            if (Main.parent != null) {
     178                Main.parent.repaint();
     179            }
    178180        }
    179181    }
     
    421423                // by the remaining "save preferences" activites run on the Swing EDT.
    422424                MainApplication.worker.submit(task);
    423                 MainApplication.worker.submit(() -> SwingUtilities.invokeLater(continuation));
     425                MainApplication.worker.submit(() -> GuiHelper.runInEDT(continuation));
    424426            } else {
    425427                // no need for asynchronous activities. Simply run the remaining "save preference"
  • trunk/src/org/openstreetmap/josm/gui/preferences/advanced/ExportProfileAction.java

    r12881 r14052  
    5656        }
    5757        if (keys.isEmpty()) {
    58             if (!GraphicsEnvironment.isHeadless()) {
    59                 JOptionPane.showMessageDialog(Main.parent,
    60                         tr("All the preferences of this group are default, nothing to save"), tr("Warning"), JOptionPane.WARNING_MESSAGE);
    61             }
     58            JOptionPane.showMessageDialog(Main.parent,
     59                    tr("All the preferences of this group are default, nothing to save"), tr("Warning"), JOptionPane.WARNING_MESSAGE);
    6260            return;
    6361        }
  • trunk/src/org/openstreetmap/josm/gui/preferences/advanced/PreferencesTable.java

    r12987 r14052  
    88import java.awt.Component;
    99import java.awt.Font;
    10 import java.awt.GraphicsEnvironment;
    1110import java.awt.GridBagLayout;
    1211import java.awt.event.MouseAdapter;
     
    9695    public boolean editPreference(final JComponent gui) {
    9796        if (getSelectedRowCount() != 1) {
    98             if (!GraphicsEnvironment.isHeadless()) {
    99                 JOptionPane.showMessageDialog(
    100                         gui,
    101                         tr("Please select the row to edit."),
    102                         tr("Warning"),
    103                         JOptionPane.WARNING_MESSAGE
    104                         );
    105             }
     97            JOptionPane.showMessageDialog(
     98                    gui,
     99                    tr("Please select the row to edit."),
     100                    tr("Warning"),
     101                    JOptionPane.WARNING_MESSAGE
     102                    );
    106103            return false;
    107104        }
     
    197194        PrefEntry pe = null;
    198195        boolean ok = false;
    199         if (!GraphicsEnvironment.isHeadless() && askAddSetting(gui, p)) {
     196        if (askAddSetting(gui, p)) {
    200197            if (rbString.isSelected()) {
    201198                StringSetting sSetting = new StringSetting(null);
     
    282279    public void resetPreferences(final JComponent gui) {
    283280        if (getSelectedRowCount() == 0) {
    284             if (!GraphicsEnvironment.isHeadless()) {
    285                 JOptionPane.showMessageDialog(
    286                         gui,
    287                         tr("Please select the row to delete."),
    288                         tr("Warning"),
    289                         JOptionPane.WARNING_MESSAGE
    290                         );
    291             }
     281            JOptionPane.showMessageDialog(
     282                    gui,
     283                    tr("Please select the row to delete."),
     284                    tr("Warning"),
     285                    JOptionPane.WARNING_MESSAGE
     286                    );
    292287            return;
    293288        }
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java

    r13842 r14052  
    77import java.awt.BorderLayout;
    88import java.awt.Component;
    9 import java.awt.GraphicsEnvironment;
    109import java.awt.GridBagConstraints;
    1110import java.awt.GridBagLayout;
     
    159158        }
    160159        sb.append("</html>");
    161         if (!GraphicsEnvironment.isHeadless()) {
    162             GuiHelper.runInEDTAndWait(() -> HelpAwareOptionPane.showOptionDialog(
    163                     parent,
    164                     sb.toString(),
    165                     tr("Update plugins"),
    166                     !failed.isEmpty() ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE,
    167                             HelpUtil.ht("/Preferences/Plugins")
    168                     ));
    169         }
     160        GuiHelper.runInEDTAndWait(() -> HelpAwareOptionPane.showOptionDialog(
     161                parent,
     162                sb.toString(),
     163                tr("Update plugins"),
     164                !failed.isEmpty() ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE,
     165                        HelpUtil.ht("/Preferences/Plugins")
     166                ));
    170167    }
    171168
     
    212209    }
    213210
     211    private static Component addButton(JPanel pnl, JButton button, String buttonName) {
     212        button.setName(buttonName);
     213        return pnl.add(button);
     214    }
     215
    214216    private JPanel buildActionPanel() {
    215217        JPanel pnl = new JPanel(new GridLayout(1, 4));
    216218
    217         pnl.add(new JButton(new DownloadAvailablePluginsAction()));
    218         pnl.add(new JButton(new UpdateSelectedPluginsAction()));
    219         ExpertToggleAction.addVisibilitySwitcher(pnl.add(new JButton(new SelectByListAction())));
    220         ExpertToggleAction.addVisibilitySwitcher(pnl.add(new JButton(new ConfigureSitesAction())));
     219        // assign some component names to these as we go to aid testing
     220        addButton(pnl, new JButton(new DownloadAvailablePluginsAction()), "downloadListButton");
     221        addButton(pnl, new JButton(new UpdateSelectedPluginsAction()), "updatePluginsButton");
     222        ExpertToggleAction.addVisibilitySwitcher(addButton(pnl, new JButton(new SelectByListAction()), "loadFromListButton"));
     223        ExpertToggleAction.addVisibilitySwitcher(addButton(pnl, new JButton(new ConfigureSitesAction()), "configureSitesButton"));
    221224        return pnl;
    222225    }
Note: See TracChangeset for help on using the changeset viewer.