Ignore:
Timestamp:
2021-08-24T02:43:50+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #20690 - fix #21240 - Refactoring of UploadDialog, HistoryComboBox and AutoCompletingComboBox (patch by marcello)

Location:
trunk/test/unit/org/openstreetmap/josm/gui
Files:
3 added
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/io/BasicUploadSettingsPanelTest.java

    r18037 r18173  
    22package org.openstreetmap.josm.gui.io;
    33
     4import static org.junit.jupiter.api.Assertions.assertEquals;
    45import static org.junit.jupiter.api.Assertions.assertNotNull;
     6import static org.junit.jupiter.api.Assertions.assertNull;
     7
     8import java.util.Arrays;
     9import java.util.List;
     10
     11import org.openstreetmap.josm.spi.preferences.Config;
    512
    613import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     
    1825    @Test
    1926    void testBasicUploadSettingsPanel() {
    20         assertNotNull(new BasicUploadSettingsPanel(new ChangesetCommentModel(), new ChangesetCommentModel(), new ChangesetReviewModel()));
     27        assertNotNull(new BasicUploadSettingsPanel(new UploadDialogModel()));
     28    }
     29
     30    private static void doTestGetLastChangesetTagFromHistory(String historyKey, List<String> def) {
     31        Config.getPref().putList(historyKey, null);
     32        Config.getPref().putInt(BasicUploadSettingsPanel.COMMENT_LAST_USED_KEY, 0);
     33        Config.getPref().putInt(BasicUploadSettingsPanel.COMMENT_MAX_AGE_KEY, 30);
     34        assertNull(BasicUploadSettingsPanel.getLastChangesetTagFromHistory(historyKey, def));          // age NOK (history empty)
     35
     36        Config.getPref().putList(historyKey, Arrays.asList("foo", "bar"));
     37        assertNull(BasicUploadSettingsPanel.getLastChangesetTagFromHistory(historyKey, def));          // age NOK (history not empty)
     38
     39        Config.getPref().putLong(BasicUploadSettingsPanel.COMMENT_LAST_USED_KEY, System.currentTimeMillis() / 1000);
     40        assertEquals("foo", BasicUploadSettingsPanel.getLastChangesetTagFromHistory(historyKey, def)); // age OK, history not empty
     41
     42        Config.getPref().putList(historyKey, null);
     43        assertEquals(def.get(0), BasicUploadSettingsPanel.getLastChangesetTagFromHistory(historyKey, def));   // age OK, history empty
     44    }
     45
     46    /**
     47     * Test of {@link BasicUploadSettingsPanel#getLastChangesetTagFromHistory} method.
     48     */
     49    @Test
     50    void testGetLastChangesetCommentFromHistory() {
     51        doTestGetLastChangesetTagFromHistory(
     52                BasicUploadSettingsPanel.COMMENT_HISTORY_KEY,
     53                Arrays.asList("baz", "quux"));
     54    }
     55
     56    /**
     57     * Test of {@link BasicUploadSettingsPanel#getLastChangesetTagFromHistory} method.
     58     */
     59    @Test
     60    void testGetLastChangesetSourceFromHistory() {
     61        doTestGetLastChangesetTagFromHistory(
     62                BasicUploadSettingsPanel.SOURCE_HISTORY_KEY,
     63                BasicUploadSettingsPanel.getDefaultSources());
    2164    }
    2265}
  • trunk/test/unit/org/openstreetmap/josm/gui/io/ChangesetManagementPanelTest.java

    r18037 r18173  
    55
    66import org.junit.jupiter.api.Test;
     7
    78import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    89
     
    1718    @Test
    1819    void testChangesetManagementPanel() {
    19         assertNotNull(new ChangesetManagementPanel(new ChangesetCommentModel()));
     20        assertNotNull(new ChangesetManagementPanel(new UploadDialogModel()));
    2021    }
    2122}
  • trunk/test/unit/org/openstreetmap/josm/gui/io/UploadDialogTest.java

    r18037 r18173  
    1313import java.util.Map;
    1414import java.util.concurrent.ConcurrentHashMap;
    15 import java.util.function.Supplier;
    1615
    1716import javax.swing.JOptionPane;
     
    1918import org.junit.jupiter.api.Test;
    2019import org.openstreetmap.josm.TestUtils;
    21 import org.openstreetmap.josm.data.osm.DataSet;
    2220import org.openstreetmap.josm.gui.io.UploadDialog.UploadAction;
    2321import org.openstreetmap.josm.io.UploadStrategySpecification;
     
    8280            return new ConcurrentHashMap<>();
    8381        }
    84 
    85         @Override
    86         public void forceUpdateActiveField() {
    87             // Do nothing
    88         }
    8982    }
    9083
     
    114107        // test with unassigned unicode characters ==> no unicode block
    115108        assertTrue(UploadDialog.UploadAction.isUploadCommentTooShort("\u0860"));
    116     }
    117 
    118     private static void doTestGetLastChangesetTagFromHistory(String historyKey, Supplier<String> methodToTest, String def) {
    119         Config.getPref().putList(historyKey, null);
    120         Config.getPref().putInt(BasicUploadSettingsPanel.HISTORY_LAST_USED_KEY, 0);
    121         Config.getPref().putInt(BasicUploadSettingsPanel.HISTORY_MAX_AGE_KEY, 30);
    122         assertNull(methodToTest.get());          // age NOK (history empty)
    123         Config.getPref().putList(historyKey, Arrays.asList("foo"));
    124         assertNull(methodToTest.get());          // age NOK (history not empty)
    125         Config.getPref().putLong(BasicUploadSettingsPanel.HISTORY_LAST_USED_KEY, System.currentTimeMillis() / 1000);
    126         assertEquals("foo", methodToTest.get()); // age OK, history not empty
    127         Config.getPref().putList(historyKey, null);
    128         assertEquals(def, methodToTest.get());   // age OK, history empty
    129     }
    130 
    131     /**
    132      * Test of {@link UploadDialog#getLastChangesetCommentFromHistory} method.
    133      */
    134     @Test
    135     void testGetLastChangesetCommentFromHistory() {
    136         doTestGetLastChangesetTagFromHistory(
    137                 BasicUploadSettingsPanel.HISTORY_KEY,
    138                 UploadDialog::getLastChangesetCommentFromHistory,
    139                 null);
    140     }
    141 
    142     /**
    143      * Test of {@link UploadDialog#getLastChangesetSourceFromHistory} method.
    144      */
    145     @Test
    146     void testGetLastChangesetSourceFromHistory() {
    147         doTestGetLastChangesetTagFromHistory(
    148                 BasicUploadSettingsPanel.SOURCE_HISTORY_KEY,
    149                 UploadDialog::getLastChangesetSourceFromHistory,
    150                 BasicUploadSettingsPanel.getDefaultSources().get(0));
    151109    }
    152110
     
    186144        doTestValidateUploadTag("upload.source");
    187145    }
    188 
    189     @Test
    190     void testGetCommentWithDataSetHashTag() {
    191         assertEquals("", UploadDialog.getCommentWithDataSetHashTag(null, null));
    192         DataSet ds = new DataSet();
    193         assertEquals("foo", UploadDialog.getCommentWithDataSetHashTag("foo", ds));
    194         ds.getChangeSetTags().put("hashtags", "bar");
    195         assertEquals("foo #bar", UploadDialog.getCommentWithDataSetHashTag("foo", ds));
    196         ds.getChangeSetTags().put("hashtags", "bar;baz;#bar");
    197         assertEquals("foo #bar #baz", UploadDialog.getCommentWithDataSetHashTag("foo", ds));
    198     }
    199146}
Note: See TracChangeset for help on using the changeset viewer.