Changeset 17090 in josm
- Timestamp:
- 2020-10-07T07:46:55+02:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ivy.xml
r17085 r17090 51 51 </dependency> 52 52 <!-- jmockit->default - Don't upgrade JMockit until https://josm.openstreetmap.de/ticket/18200 is resolved --> 53 <dependency conf="jmockit->default" org="org.jmockit" name="jmockit" rev="1.4 4"/>53 <dependency conf="jmockit->default" org="org.jmockit" name="jmockit" rev="1.49"/> 54 54 <!-- test->default --> 55 55 <dependency conf="test->default" org="com.github.spotbugs" name="spotbugs-annotations" rev="4.0.1"/> -
trunk/src/org/openstreetmap/josm/gui/MapViewState.java
r16919 r17090 132 132 } 133 133 134 private static Point findTopLeftInWindow(JComponent position) { 134 /** 135 * This is visible for JMockit. 136 * 137 * @param position The component to get the top left position of its window 138 * @return the top left point in window 139 */ 140 static Point findTopLeftInWindow(JComponent position) { 135 141 Point result = new Point(); 136 142 // better than using swing utils, since this allows us to use the method if no screen is present. … … 144 150 } 145 151 146 private static Point findTopLeftOnScreen(JComponent position) { 152 /** 153 * This is visible for JMockit. 154 * 155 * @param position The component to get the top left position of its screen 156 * @return the top left point on screen 157 */ 158 static Point findTopLeftOnScreen(JComponent position) { 147 159 try { 148 160 return position.getLocationOnScreen(); -
trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java
r16438 r17090 204 204 } 205 205 206 private static void handleEDTException(Throwable t) { 206 /** 207 * Handle exceptions in the EDT. This should only be used in {@link GuiHelper} 208 * and {@code org.openstreetmap.josm.testutils.mockers.EDTAssertionMocker}. 209 * 210 * @param t The throwable to handle 211 */ 212 static void handleEDTException(Throwable t) { 207 213 Logging.logWithStackTrace(Logging.LEVEL_ERROR, t, "Exception raised in EDT"); 208 214 } -
trunk/test/unit/org/openstreetmap/josm/testutils/mockers/EDTAssertionMocker.java
r14052 r17090 14 14 public class EDTAssertionMocker extends MockUp<GuiHelper> { 15 15 @Mock 16 private static void handleEDTException(final Invocation invocation, final Throwable t){16 static void handleEDTException(final Invocation invocation, final Throwable t) throws Throwable { 17 17 final Throwable cause = t.getCause(); 18 18 if (cause instanceof AssertionError) { -
trunk/test/unit/org/openstreetmap/josm/testutils/mockers/ExtendedDialogMocker.java
r14604 r17090 6 6 import java.awt.Component; 7 7 import java.awt.GraphicsEnvironment; 8 import java.lang.reflect.Field; 8 9 import java.util.Arrays; 9 10 import java.util.Map; 11 import java.util.NoSuchElementException; 10 12 import java.util.Optional; 11 13 import java.util.WeakHashMap; 12 14 15 import org.junit.platform.commons.util.ReflectionUtils; 13 16 import org.openstreetmap.josm.TestUtils; 14 17 import org.openstreetmap.josm.gui.ExtendedDialog; 15 18 import org.openstreetmap.josm.tools.Logging; 16 19 17 import mockit.Deencapsulation;18 20 import mockit.Invocation; 19 21 import mockit.Mock; 20 import mockit.internal.reflection.FieldReflection;21 22 22 23 /** … … 77 78 78 79 protected int getButtonPositionFromLabel(final ExtendedDialog instance, final String label) { 79 final String[] bTexts = Deencapsulation.getField(instance, "bTexts"); 80 final String[] bTexts = (String[]) ReflectionUtils.tryToReadFieldValue(ExtendedDialog.class, "bTexts", instance) 81 .toOptional().orElseThrow(NoSuchElementException::new); 80 82 final int position = Arrays.asList(bTexts).indexOf(label); 81 83 if (position == -1) { … … 151 153 152 154 @Mock 153 private void setVisible(final Invocation invocation, final boolean value) {155 private void setVisible(final Invocation invocation, final boolean value) throws Throwable { 154 156 if (value == true) { 155 157 try { … … 158 160 final int mockResult = this.getMockResult(instance); 159 161 // TODO check validity of mockResult? 160 FieldReflection.setField(instance.getClass(), instance, "result", mockResult); 162 Field resultField = instance.getClass().getDeclaredField("result"); 163 resultField.setAccessible(true); 164 resultField.set(instance, mockResult); 161 165 Logging.info( 162 166 "{0} answering {1} to ExtendedDialog with content {2}", … … 166 170 ); 167 171 this.getInvocationLogInternal().add(this.getInvocationLogEntry(instance, mockResult)); 168 } catch (AssertionError e) {172 } catch (AssertionError | NoSuchFieldException | IllegalAccessException e) { 169 173 // in case this exception gets ignored by the calling thread we want to signify this failure 170 174 // in the invocation log. it's hard to know what to add to the log in these cases as it's -
trunk/test/unit/org/openstreetmap/josm/testutils/mockers/WindowlessMapViewStateMocker.java
r14052 r17090 17 17 public class WindowlessMapViewStateMocker extends MockUp<MapViewState> { 18 18 @Mock 19 privatestatic Point findTopLeftInWindow(JComponent position) {19 static Point findTopLeftInWindow(JComponent position) { 20 20 return new Point(); 21 21 } 22 22 23 23 @Mock 24 privatestatic Point findTopLeftOnScreen(JComponent position) {24 static Point findTopLeftOnScreen(JComponent position) { 25 25 // in our imaginary universe the window is always (10, 10) from the top left of the screen 26 26 Point topLeftInWindow = findTopLeftInWindow(position);
Note:
See TracChangeset
for help on using the changeset viewer.