Changeset 10064 in josm


Ignore:
Timestamp:
2016-03-28T02:57:02+02:00 (22 months ago)
Author:
Don-vip
Message:

see #12652, see #11924 - re-add a unit test in BugReportExceptionHandler, empty test class causes an error with Java 9

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportExceptionHandler.java

    r10062 r10064  
    3535 *
    3636 * @author imi
     37 * @since 40
    3738 */
    3839public final class BugReportExceptionHandler implements Thread.UncaughtExceptionHandler {
     
    183184    private static void askForBugReport(final Throwable e) {
    184185        try {
    185             StringWriter stack = new StringWriter();
    186             e.printStackTrace(new PrintWriter(stack));
    187 
    188             String text = ShowStatusReportAction.getReportHeader() + stack.getBuffer().toString();
    189             text = text.replaceAll("\r", "");
    190 
    191             JPanel p = new JPanel(new GridBagLayout());
    192             p.add(new JMultilineLabel(
    193                     tr("You have encountered an error in JOSM. Before you file a bug report " +
    194                             "make sure you have updated to the latest version of JOSM here:")),
    195                             GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    196             p.add(new UrlLabel(Main.getJOSMWebsite(), 2), GBC.eop().insets(8, 0, 0, 0));
    197             p.add(new JMultilineLabel(
    198                     tr("You should also update your plugins. If neither of those help please " +
    199                             "file a bug report in our bugtracker using this link:")),
    200                             GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    201             p.add(new JButton(new ReportBugAction(text)), GBC.eop().insets(8, 0, 0, 0));
    202             p.add(new JMultilineLabel(
    203                     tr("There the error information provided below should already be " +
    204                             "filled in for you. Please include information on how to reproduce " +
    205                             "the error and try to supply as much detail as possible.")),
    206                             GBC.eop().fill(GridBagConstraints.HORIZONTAL));
    207             p.add(new JMultilineLabel(
    208                     tr("Alternatively, if that does not work you can manually fill in the information " +
    209                             "below at this URL:")), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    210             p.add(new UrlLabel(Main.getJOSMWebsite()+"/newticket", 2), GBC.eop().insets(8, 0, 0, 0));
    211 
    212             // Wiki formatting for manual copy-paste
    213             DebugTextDisplay textarea = new DebugTextDisplay(text);
    214 
    215             if (textarea.copyToClippboard()) {
    216                 p.add(new JLabel(tr("(The text has already been copied to your clipboard.)")),
    217                         GBC.eop().fill(GridBagConstraints.HORIZONTAL));
    218             }
    219 
    220             p.add(textarea, GBC.eop().fill());
    221 
    222             for (Component c: p.getComponents()) {
    223                 if (c instanceof JMultilineLabel) {
    224                     ((JMultilineLabel) c).setMaxWidth(400);
    225                 }
    226             }
    227 
     186            JPanel p = buildPanel(e);
    228187            JOptionPane.showMessageDialog(Main.parent, p, tr("You have encountered a bug in JOSM"), JOptionPane.ERROR_MESSAGE);
    229188        } catch (Exception e1) {
    230189            Main.error(e1);
    231190        }
     191    }
     192
     193    static JPanel buildPanel(final Throwable e) {
     194        StringWriter stack = new StringWriter();
     195        e.printStackTrace(new PrintWriter(stack));
     196
     197        String text = ShowStatusReportAction.getReportHeader() + stack.getBuffer().toString();
     198        text = text.replaceAll("\r", "");
     199
     200        JPanel p = new JPanel(new GridBagLayout());
     201        p.add(new JMultilineLabel(
     202                tr("You have encountered an error in JOSM. Before you file a bug report " +
     203                        "make sure you have updated to the latest version of JOSM here:")),
     204                        GBC.eol().fill(GridBagConstraints.HORIZONTAL));
     205        p.add(new UrlLabel(Main.getJOSMWebsite(), 2), GBC.eop().insets(8, 0, 0, 0));
     206        p.add(new JMultilineLabel(
     207                tr("You should also update your plugins. If neither of those help please " +
     208                        "file a bug report in our bugtracker using this link:")),
     209                        GBC.eol().fill(GridBagConstraints.HORIZONTAL));
     210        p.add(new JButton(new ReportBugAction(text)), GBC.eop().insets(8, 0, 0, 0));
     211        p.add(new JMultilineLabel(
     212                tr("There the error information provided below should already be " +
     213                        "filled in for you. Please include information on how to reproduce " +
     214                        "the error and try to supply as much detail as possible.")),
     215                        GBC.eop().fill(GridBagConstraints.HORIZONTAL));
     216        p.add(new JMultilineLabel(
     217                tr("Alternatively, if that does not work you can manually fill in the information " +
     218                        "below at this URL:")), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
     219        p.add(new UrlLabel(Main.getJOSMWebsite()+"/newticket", 2), GBC.eop().insets(8, 0, 0, 0));
     220
     221        // Wiki formatting for manual copy-paste
     222        DebugTextDisplay textarea = new DebugTextDisplay(text);
     223
     224        if (textarea.copyToClippboard()) {
     225            p.add(new JLabel(tr("(The text has already been copied to your clipboard.)")),
     226                    GBC.eop().fill(GridBagConstraints.HORIZONTAL));
     227        }
     228
     229        p.add(textarea, GBC.eop().fill());
     230
     231        for (Component c: p.getComponents()) {
     232            if (c instanceof JMultilineLabel) {
     233                ((JMultilineLabel) c).setMaxWidth(400);
     234            }
     235        }
     236        return p;
    232237    }
    233238
  • trunk/test/unit/org/openstreetmap/josm/tools/bugreport/BugReportExceptionHandlerTest.java

    r10062 r10064  
    22package org.openstreetmap.josm.tools.bugreport;
    33
     4import static org.junit.Assert.assertNotNull;
     5
    46import org.junit.Before;
     7import org.junit.Test;
    58import org.openstreetmap.josm.JOSMFixture;
    69
    710/**
    8  * Bug report unit tests.
     11 * Unit tests of {@link BugReportExceptionHandler} class.
    912 */
    1013public class BugReportExceptionHandlerTest {
     
    1720        JOSMFixture.createUnitTestFixture().init();
    1821    }
     22
     23    /**
     24     * Unit test for {@link BugReportExceptionHandler#buildPanel} method.
     25     */
     26    @Test
     27    public void testBuildPanel() {
     28        assertNotNull(BugReportExceptionHandler.buildPanel(new Exception()));
     29    }
    1930}
Note: See TracChangeset for help on using the changeset viewer.