Ignore:
Timestamp:
2019-04-09T01:32:56+02:00 (5 years ago)
Author:
Don-vip
Message:

ensures consistency of upload comment:

  • fix #11168 - ctrl-z/undo could reset unwanted old changeset comment
  • fix #13474 - selecting "new changeset" after having entered a changeset comment did reset it to the previous value
  • fix #17452 - ctrl-enter while typing a changeset comment did upload with the previous value
  • fix behaviour of upload.comment.max-age: values were reset after 5 months instead of intended 4 hours because seconds were compared to milliseconds
  • avoid creation of unneeded undo/redo internal classes for non-editable text fields
  • ensures consistency of upload dialog if upload.comment properties are modified manually from advanced preferences
  • add a source attribute to preference events to know which class modified the preference entry
  • refactor reflection utils
Location:
trunk/test/unit/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/TestUtils.java

    r14782 r14977  
    5454import org.openstreetmap.josm.testutils.mockers.WindowMocker;
    5555import org.openstreetmap.josm.tools.JosmRuntimeException;
     56import org.openstreetmap.josm.tools.ReflectionUtils;
    5657import org.openstreetmap.josm.tools.Utils;
    5758import org.openstreetmap.josm.tools.WikiReader;
     
    413414            Method values = enumClass.getMethod("values");
    414415            Method valueOf = enumClass.getMethod("valueOf", String.class);
    415             Utils.setObjectsAccessible(values, valueOf);
     416            ReflectionUtils.setObjectsAccessible(values, valueOf);
    416417            for (Object o : (Object[]) values.invoke(null)) {
    417418                assertEquals(o, valueOf.invoke(null, ((Enum<?>) o).name()));
  • trunk/test/unit/org/openstreetmap/josm/actions/CreateCircleActionTest.java

    r14542 r14977  
    2121import org.openstreetmap.josm.tools.GeoPropertyIndex;
    2222import org.openstreetmap.josm.tools.Geometry;
     23import org.openstreetmap.josm.tools.ReflectionUtils;
    2324import org.openstreetmap.josm.tools.RightAndLefthandTraffic;
    24 import org.openstreetmap.josm.tools.Utils;
    2525
    2626import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    118118        // Mock left/right hand traffic database
    119119        Field rlCache = RightAndLefthandTraffic.class.getDeclaredField("rlCache");
    120         Utils.setObjectsAccessible(rlCache);
     120        ReflectionUtils.setObjectsAccessible(rlCache);
    121121        Object origRlCache = rlCache.get(null);
    122122        rlCache.set(null, new GeoPropertyIndex<>(new ConstantTrafficHand(true), 24));
  • trunk/test/unit/org/openstreetmap/josm/actions/mapmode/SelectActionTest.java

    r14138 r14977  
    2727import org.openstreetmap.josm.spi.preferences.Config;
    2828import org.openstreetmap.josm.testutils.JOSMTestRules;
    29 import org.openstreetmap.josm.tools.Utils;
     29import org.openstreetmap.josm.tools.ReflectionUtils;
    3030
    3131import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    4242            super(mapFrame);
    4343            Field mv = SelectAction.class.getDeclaredField("mv");
    44             Utils.setObjectsAccessible(mv);
     44            ReflectionUtils.setObjectsAccessible(mv);
    4545            mv.set(this, new MapViewMock(new MainLayerManager()));
    4646        }
  • trunk/test/unit/org/openstreetmap/josm/gui/TableCellRendererTest.java

    r14138 r14977  
    2020import org.openstreetmap.josm.testutils.JOSMTestRules;
    2121import org.openstreetmap.josm.tools.Logging;
    22 import org.openstreetmap.josm.tools.Utils;
     22import org.openstreetmap.josm.tools.ReflectionUtils;
    2323
    2424import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    9999            c = klass.getDeclaredConstructor();
    100100        }
    101         Utils.setObjectsAccessible(c);
     101        ReflectionUtils.setObjectsAccessible(c);
    102102        if (needOuterClass) {
    103103            return c.newInstance(createInstance(klass.getDeclaringClass()));
  • trunk/test/unit/org/openstreetmap/josm/gui/io/UploadDialogTest.java

    r14355 r14977  
    44import static org.junit.Assert.assertEquals;
    55import static org.junit.Assert.assertFalse;
     6import static org.junit.Assert.assertNull;
    67import static org.junit.Assert.assertTrue;
    78
    89import java.awt.GraphicsEnvironment;
     10import java.util.Arrays;
    911import java.util.List;
    1012import java.util.Map;
    1113import java.util.concurrent.ConcurrentHashMap;
     14import java.util.function.Supplier;
     15
    1216import javax.swing.JButton;
    1317import javax.swing.JOptionPane;
     
    1519import org.junit.Rule;
    1620import org.junit.Test;
     21import org.openstreetmap.josm.TestUtils;
    1722import org.openstreetmap.josm.gui.ExtendedDialog;
    18 import org.openstreetmap.josm.TestUtils;
    1923import org.openstreetmap.josm.io.UploadStrategySpecification;
     24import org.openstreetmap.josm.spi.preferences.Config;
    2025import org.openstreetmap.josm.testutils.JOSMTestRules;
    2126import org.openstreetmap.josm.testutils.mockers.ExtendedDialogMocker;
    2227import org.openstreetmap.josm.testutils.mockers.WindowMocker;
    2328
     29import com.google.common.collect.ImmutableMap;
     30
     31import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2432import mockit.Invocation;
    2533import mockit.Mock;
    26 
    27 import com.google.common.collect.ImmutableMap;
    28 
    29 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    3034
    3135/**
     
    96100        public Map<String, String> getTags(boolean keepEmpty) {
    97101            return new ConcurrentHashMap<>();
     102        }
     103
     104        @Override
     105        public void forceUpdateActiveField() {
     106            // Do nothing
    98107        }
    99108    }
     
    214223        assertTrue(UploadDialog.UploadAction.isUploadCommentTooShort("\u0860"));
    215224    }
     225
     226    private static void doTestGetLastChangesetTagFromHistory(String historyKey, Supplier<String> methodToTest, String def) {
     227        Config.getPref().putList(historyKey, null);
     228        Config.getPref().putInt(BasicUploadSettingsPanel.HISTORY_LAST_USED_KEY, 0);
     229        Config.getPref().putInt(BasicUploadSettingsPanel.HISTORY_MAX_AGE_KEY, 30);
     230        assertNull(methodToTest.get());          // age NOK (history empty)
     231        Config.getPref().putList(historyKey, Arrays.asList("foo"));
     232        assertNull(methodToTest.get());          // age NOK (history not empty)
     233        Config.getPref().putLong(BasicUploadSettingsPanel.HISTORY_LAST_USED_KEY, System.currentTimeMillis() / 1000);
     234        assertEquals("foo", methodToTest.get()); // age OK, history not empty
     235        Config.getPref().putList(historyKey, null);
     236        assertEquals(def, methodToTest.get());   // age OK, history empty
     237    }
     238
     239    /**
     240     * Test of {@link UploadDialog#getLastChangesetCommentFromHistory} method.
     241     */
     242    @Test
     243    public void testGetLastChangesetCommentFromHistory() {
     244        doTestGetLastChangesetTagFromHistory(
     245                BasicUploadSettingsPanel.HISTORY_KEY,
     246                UploadDialog::getLastChangesetCommentFromHistory,
     247                null);
     248    }
     249
     250    /**
     251     * Test of {@link UploadDialog#getLastChangesetSourceFromHistory} method.
     252     */
     253    @Test
     254    public void testGetLastChangesetSourceFromHistory() {
     255        doTestGetLastChangesetTagFromHistory(
     256                BasicUploadSettingsPanel.SOURCE_HISTORY_KEY,
     257                UploadDialog::getLastChangesetSourceFromHistory,
     258                BasicUploadSettingsPanel.getDefaultSources().get(0));
     259    }
    216260}
Note: See TracChangeset for help on using the changeset viewer.