Ignore:
Timestamp:
2018-10-14T17:30:28+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #16841 - MergeLayerActionTest, DownloadWmsAlongTrackActionTest: fix for non-headless mode by properly mocking dialogs (patch by ris)

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

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/testutils/mockers/ExtendedDialogMocker.java

    r14052 r14332  
    1111import java.util.WeakHashMap;
    1212
     13import org.openstreetmap.josm.TestUtils;
    1314import org.openstreetmap.josm.gui.ExtendedDialog;
    1415import org.openstreetmap.josm.tools.Logging;
     
    108109    }
    109110
     111    /**
     112     * Target for overriding, similar to {@link #getMockResult} except with the implication it will only
     113     * be invoked once per dialog display, therefore ideal opportunity to perform any mutating actions,
     114     * e.g. making a selection on a widget.
     115     * @param instance dialog instance
     116     */
     117    protected void act(final ExtendedDialog instance) {
     118        // Override in sub-classes
     119    }
     120
    110121    protected Object[] getInvocationLogEntry(final ExtendedDialog instance, final int mockResult) {
    111122        return new Object[] {
     
    114125            instance.getTitle()
    115126        };
     127    }
     128
     129    /**
     130     * A convenience method to access {@link ExtendedDialog#content} without exception-catching boilerplate
     131     * @param instance dialog instance
     132     * @return dialog content component
     133     */
     134    protected Component getContent(final ExtendedDialog instance) {
     135        try {
     136            return (Component) TestUtils.getPrivateField(instance, "content");
     137        } catch (ReflectiveOperationException e) {
     138            throw new RuntimeException(e);
     139        }
    116140    }
    117141
     
    130154            try {
    131155                final ExtendedDialog instance = invocation.getInvokedInstance();
     156                this.act(instance);
    132157                final int mockResult = this.getMockResult(instance);
    133158                // TODO check validity of mockResult?
  • trunk/test/unit/org/openstreetmap/josm/testutils/mockers/HelpAwareOptionPaneMocker.java

    r14201 r14332  
    7676        }
    7777        return this.getMockResultMap().get(messageString);
     78    }
     79
     80    /**
     81     * Target for overriding, similar to {@link #getMockResultForMessage} except with the implication it
     82     * will only be invoked once per dialog display, therefore ideal opportunity to perform any mutating
     83     * actions, e.g. making a selection on a widget.
     84     * @param message message
     85     */
     86    protected void act(final Object message) {
     87        // Override in sub-classes
    7888    }
    7989
     
    134144    ) {
    135145        try {
     146            this.act(msg);
    136147            final Object result = this.getMockResultForMessage(msg);
    137148
  • trunk/test/unit/org/openstreetmap/josm/testutils/mockers/JOptionPaneSimpleMocker.java

    r14052 r14332  
    134134    }
    135135
     136    /**
     137     * Target for overriding, similar to {@link #getMockResultForMessage} except with the implication it
     138     * will only be invoked once per dialog display, therefore ideal opportunity to perform any mutating
     139     * actions, e.g. making a selection on a widget.
     140     * @param message message
     141     */
     142    protected void act(final Object message) {
     143        // Override in sub-classes
     144    }
     145
    136146    protected Object[] getInvocationLogEntry(
    137147        final Object message,
     
    162172    ) {
    163173        try {
     174            this.act(message);
    164175            final Object result = this.getMockResultForMessage(message);
    165176            if (selectionValues == null) {
     
    216227    ) {
    217228        try {
     229            this.act(message);
    218230            // why look up a "result" for a message dialog which can only have one possible result? it's
    219231            // a good opportunity to assert its contents
     
    263275    ) {
    264276        try {
     277            this.act(message);
    265278            final Object result = this.getMockResultForMessage(message);
    266279            if (!(result instanceof Integer && Ints.contains(optionTypePermittedResults.get(optionType), (int) result))) {
Note: See TracChangeset for help on using the changeset viewer.