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

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

Location:
trunk/test/unit/org/openstreetmap/josm/testutils/mockers
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 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.