Changeset 14380 in josm
- Timestamp:
- 2018-10-28T20:30:47+01:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/ConditionalOptionPaneUtil.java
r14052 r14380 5 5 6 6 import java.awt.Component; 7 import java.awt.GraphicsEnvironment;8 7 import java.awt.GridBagLayout; 9 8 import java.util.HashMap; … … 116 115 * @return the option selected by user. 117 116 * {@link JOptionPane#CLOSED_OPTION} if the dialog was closed. 118 * {@link JOptionPane#YES_OPTION} if <code>GraphicsEnvironment.isHeadless</code> returns <code>true</code>119 117 */ 120 118 public static int showOptionDialog(String preferenceKey, Component parent, Object message, String title, int optionType, … … 124 122 return ret; 125 123 MessagePanel pnl = new MessagePanel(message, isInBulkOperation(preferenceKey)); 126 if (GraphicsEnvironment.isHeadless()) { 127 // for unit tests 128 ret = JOptionPane.YES_OPTION; 129 } else { 130 ret = JOptionPane.showOptionDialog(parent, pnl, title, optionType, messageType, null, options, defaultOption); 131 } 124 ret = JOptionPane.showOptionDialog(parent, pnl, title, optionType, messageType, null, options, defaultOption); 132 125 if (isYesOrNo(ret)) { 133 126 pnl.getNotShowAgain().store(preferenceKey, ret); … … 162 155 * 163 156 * @return true, if the selected option is equal to <code>trueOption</code>, otherwise false. 164 * {@code trueOption} if <code>GraphicsEnvironment.isHeadless</code> returns <code>true</code>165 157 * 166 158 * @see JOptionPane#INFORMATION_MESSAGE … … 174 166 return ret == trueOption; 175 167 MessagePanel pnl = new MessagePanel(message, isInBulkOperation(preferenceKey)); 176 if (GraphicsEnvironment.isHeadless()) { 177 // for unit tests 178 ret = trueOption; 179 } else { 180 ret = JOptionPane.showConfirmDialog(parent, pnl, title, optionType, messageType); 181 } 168 ret = JOptionPane.showConfirmDialog(parent, pnl, title, optionType, messageType); 182 169 if (isYesOrNo(ret)) { 183 170 pnl.getNotShowAgain().store(preferenceKey, ret); -
trunk/src/org/openstreetmap/josm/tools/bugreport/ReportedException.java
r14095 r14380 49 49 private String methodWarningFrom; 50 50 51 ReportedException(Throwable exception) { 51 /** 52 * Constructs a new {@code ReportedException}. 53 * @param exception the cause (which is saved for later retrieval by the {@link #getCause()} method) 54 * @since 14380 55 */ 56 public ReportedException(Throwable exception) { 52 57 this(exception, Thread.currentThread()); 53 58 } 54 59 55 ReportedException(Throwable exception, Thread caughtOnThread) { 60 /** 61 * Constructs a new {@code ReportedException}. 62 * @param exception the cause (which is saved for later retrieval by the {@link #getCause()} method) 63 * @param caughtOnThread thread where the exception was caugth 64 * @since 14380 65 */ 66 public ReportedException(Throwable exception, Thread caughtOnThread) { 56 67 super(exception); 57 68 -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/actions/RelationEditorActionsTest.java
r14028 r14380 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.dialogs.relation.actions; 3 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertTrue; 6 7 import java.awt.Component; 8 import java.awt.Container; 9 import javax.swing.Icon; 10 import javax.swing.JOptionPane; 11 import javax.swing.text.JTextComponent; 12 13 import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker; 14 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 15 16 import com.google.common.collect.ImmutableMap; 17 18 import mockit.Mock; 19 import mockit.MockUp; 3 20 4 21 import org.junit.Test; … … 10 27 11 28 /** 12 * Check that all actions do not crash.29 * Check that all dialog-less actions do not crash. 13 30 */ 14 31 @Test 15 public void test AllActions() {32 public void testNoDialogActions() { 16 33 new AddSelectedAfterSelection(relationEditorAccess).actionPerformed(null); 17 34 new AddSelectedBeforeSelection(relationEditorAccess).actionPerformed(null); … … 28 45 29 46 new SelectAction(relationEditorAccess).actionPerformed(null); 30 new DeleteCurrentRelationAction(relationEditorAccess).actionPerformed(null);31 47 32 48 new DownloadIncompleteMembersAction(relationEditorAccess, "downloadincomplete").actionPerformed(null); … … 48 64 new SortBelowAction(relationEditorAccess).actionPerformed(null); 49 65 new ReverseAction(relationEditorAccess).actionPerformed(null); 66 } 67 68 /** 69 * Test DeleteCurrentRelationAction 70 */ 71 @Test 72 public void testDeleteCurrentRelationAction() { 73 final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker( 74 ImmutableMap.<String, Object>of( 75 "<html>\n <head>\n \n </head>\n <body>\n You are about to delete 1 " 76 + "relation:\n\n " 77 + "<ul>\n <li>\n incomplete\n </li>\n </ul>\n <br>\n " 78 + "This step is rarely necessary and cannot be undone easily after being \n " 79 + "uploaded to the server.<br>Do you really want to delete?\n </body>\n</html>\n", JOptionPane.YES_OPTION, 80 "<html>\n <head>\n \n </head>\n <body>\n You are about to delete incomplete " 81 + "objects.<br>This will cause problems \n because you don\'t see the real object.<br>" 82 + "Do you really want to delete?\n </body>\n</html>\n", 83 JOptionPane.YES_OPTION 84 ) 85 ) { 86 public String getStringFromOriginalMessage(Object originalMessage) { 87 return ((JTextComponent) ((Container) originalMessage).getComponent(0)).getText(); 88 } 89 }; 90 91 new DeleteCurrentRelationAction(relationEditorAccess).actionPerformed(null); 92 93 assertEquals(2, jopsMocker.getInvocationLog().size()); 94 95 Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(0); 96 assertEquals(JOptionPane.YES_OPTION, (int) invocationLogEntry[0]); 97 assertEquals("Delete relation?", invocationLogEntry[2]); 98 99 invocationLogEntry = jopsMocker.getInvocationLog().get(1); 100 assertEquals(JOptionPane.YES_OPTION, (int) invocationLogEntry[0]); 101 assertEquals("Delete confirmation", invocationLogEntry[2]); 102 } 103 104 /** 105 * Test SetRoleAction 106 */ 107 @Test 108 public void testSetRoleAction() { 109 final JOptionPaneSimpleMocker.MessagePanelMocker mpMocker = new JOptionPaneSimpleMocker.MessagePanelMocker(); 110 // JOptionPaneSimpleMocker doesn't handle showOptionDialog calls because of their potential 111 // complexity, but this is quite a simple use of showOptionDialog which we can mock from scratch. 112 final boolean[] jopMockerCalled = new boolean[] {false}; 113 final MockUp<JOptionPane> jopMocker = new MockUp<JOptionPane>() { 114 @Mock 115 public int showOptionDialog( 116 Component parentComponent, 117 Object message, 118 String title, 119 int optionType, 120 int messageType, 121 Icon icon, 122 Object[] options, 123 Object initialValue 124 ) { 125 assertEquals( 126 "<html>You are setting an empty role on 0 objects.<br>This is equal to deleting the " 127 + "roles of these objects.<br>Do you really want to apply the new role?</html>", 128 mpMocker.getOriginalMessage((ConditionalOptionPaneUtil.MessagePanel) message).toString() 129 ); 130 assertEquals( 131 "Confirm empty role", 132 title 133 ); 134 jopMockerCalled[0] = true; 135 return JOptionPane.YES_OPTION; 136 } 137 }; 50 138 51 139 new SetRoleAction(relationEditorAccess).actionPerformed(null); 140 141 assertTrue(jopMockerCalled[0]); 52 142 } 53 143 } -
trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
r14273 r14380 8 8 import java.io.File; 9 9 import java.io.IOException; 10 import java.io.PrintWriter; 11 import java.io.StringWriter; 10 12 import java.lang.annotation.Documented; 11 13 import java.lang.annotation.ElementType; … … 61 63 import org.openstreetmap.josm.tools.RightAndLefthandTraffic; 62 64 import org.openstreetmap.josm.tools.Territories; 65 import org.openstreetmap.josm.tools.bugreport.ReportedException; 63 66 import org.openstreetmap.josm.tools.date.DateUtils; 64 67 … … 674 677 throw exception; 675 678 } else { 676 Logging.debug("Thread state at timeout: {0}", Thread.getAllStackTraces()); 679 if (Logging.isLoggingEnabled(Logging.LEVEL_DEBUG)) { 680 // i.e. skip expensive formatting of stack trace if it won't be shown 681 final StringWriter sw = new StringWriter(); 682 new ReportedException(exception).printReportThreadsTo(new PrintWriter(sw)); 683 Logging.debug("Thread state at timeout: {0}", sw); 684 } 677 685 throw new Exception(MessageFormat.format("Test timed out after {0}ms", timeout)); 678 686 }
Note:
See TracChangeset
for help on using the changeset viewer.