Changeset 17090 in josm


Ignore:
Timestamp:
2020-10-07T07:46:55+02:00 (5 months ago)
Author:
simon04
Message:

fix #18200 - Update to JMockit 1.49 (patch by taylor.smock, modified)

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/ivy.xml

    r17085 r17090  
    5151        </dependency>
    5252        <!-- 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.44"/>
     53        <dependency conf="jmockit->default" org="org.jmockit" name="jmockit" rev="1.49"/>
    5454        <!-- test->default -->
    5555        <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  
    132132    }
    133133
    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) {
    135141        Point result = new Point();
    136142        // better than using swing utils, since this allows us to use the method if no screen is present.
     
    144150    }
    145151
    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) {
    147159        try {
    148160            return position.getLocationOnScreen();
  • trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java

    r16438 r17090  
    204204    }
    205205
    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) {
    207213        Logging.logWithStackTrace(Logging.LEVEL_ERROR, t, "Exception raised in EDT");
    208214    }
  • trunk/test/unit/org/openstreetmap/josm/testutils/mockers/EDTAssertionMocker.java

    r14052 r17090  
    1414public class EDTAssertionMocker extends MockUp<GuiHelper> {
    1515    @Mock
    16     private static void handleEDTException(final Invocation invocation, final Throwable t) {
     16    static void handleEDTException(final Invocation invocation, final Throwable t) throws Throwable {
    1717        final Throwable cause = t.getCause();
    1818        if (cause instanceof AssertionError) {
  • trunk/test/unit/org/openstreetmap/josm/testutils/mockers/ExtendedDialogMocker.java

    r14604 r17090  
    66import java.awt.Component;
    77import java.awt.GraphicsEnvironment;
     8import java.lang.reflect.Field;
    89import java.util.Arrays;
    910import java.util.Map;
     11import java.util.NoSuchElementException;
    1012import java.util.Optional;
    1113import java.util.WeakHashMap;
    1214
     15import org.junit.platform.commons.util.ReflectionUtils;
    1316import org.openstreetmap.josm.TestUtils;
    1417import org.openstreetmap.josm.gui.ExtendedDialog;
    1518import org.openstreetmap.josm.tools.Logging;
    1619
    17 import mockit.Deencapsulation;
    1820import mockit.Invocation;
    1921import mockit.Mock;
    20 import mockit.internal.reflection.FieldReflection;
    2122
    2223/**
     
    7778
    7879    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);
    8082        final int position = Arrays.asList(bTexts).indexOf(label);
    8183        if (position == -1) {
     
    151153
    152154    @Mock
    153     private void setVisible(final Invocation invocation, final boolean value) {
     155    private void setVisible(final Invocation invocation, final boolean value) throws Throwable {
    154156        if (value == true) {
    155157            try {
     
    158160                final int mockResult = this.getMockResult(instance);
    159161                // 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);
    161165                Logging.info(
    162166                    "{0} answering {1} to ExtendedDialog with content {2}",
     
    166170                );
    167171                this.getInvocationLogInternal().add(this.getInvocationLogEntry(instance, mockResult));
    168             } catch (AssertionError e) {
     172            } catch (AssertionError | NoSuchFieldException | IllegalAccessException e) {
    169173                // in case this exception gets ignored by the calling thread we want to signify this failure
    170174                // 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  
    1717public class WindowlessMapViewStateMocker extends MockUp<MapViewState> {
    1818    @Mock
    19     private static Point findTopLeftInWindow(JComponent position) {
     19    static Point findTopLeftInWindow(JComponent position) {
    2020        return new Point();
    2121    }
    2222
    2323    @Mock
    24     private static Point findTopLeftOnScreen(JComponent position) {
     24    static Point findTopLeftOnScreen(JComponent position) {
    2525        // in our imaginary universe the window is always (10, 10) from the top left of the screen
    2626        Point topLeftInWindow = findTopLeftInWindow(position);
Note: See TracChangeset for help on using the changeset viewer.