Changeset 17090 in josm for trunk/test
- Timestamp:
- 2020-10-07T07:46:55+02:00 (4 years ago)
- 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 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.