Changeset 18173 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2021-08-24T02:43:50+02:00 (3 years ago)
- 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 2 2 package org.openstreetmap.josm.gui.io; 3 3 4 import static org.junit.jupiter.api.Assertions.assertEquals; 4 5 import static org.junit.jupiter.api.Assertions.assertNotNull; 6 import static org.junit.jupiter.api.Assertions.assertNull; 7 8 import java.util.Arrays; 9 import java.util.List; 10 11 import org.openstreetmap.josm.spi.preferences.Config; 5 12 6 13 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; … … 18 25 @Test 19 26 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()); 21 64 } 22 65 } -
trunk/test/unit/org/openstreetmap/josm/gui/io/ChangesetManagementPanelTest.java
r18037 r18173 5 5 6 6 import org.junit.jupiter.api.Test; 7 7 8 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 8 9 … … 17 18 @Test 18 19 void testChangesetManagementPanel() { 19 assertNotNull(new ChangesetManagementPanel(new ChangesetCommentModel()));20 assertNotNull(new ChangesetManagementPanel(new UploadDialogModel())); 20 21 } 21 22 } -
trunk/test/unit/org/openstreetmap/josm/gui/io/UploadDialogTest.java
r18037 r18173 13 13 import java.util.Map; 14 14 import java.util.concurrent.ConcurrentHashMap; 15 import java.util.function.Supplier;16 15 17 16 import javax.swing.JOptionPane; … … 19 18 import org.junit.jupiter.api.Test; 20 19 import org.openstreetmap.josm.TestUtils; 21 import org.openstreetmap.josm.data.osm.DataSet;22 20 import org.openstreetmap.josm.gui.io.UploadDialog.UploadAction; 23 21 import org.openstreetmap.josm.io.UploadStrategySpecification; … … 82 80 return new ConcurrentHashMap<>(); 83 81 } 84 85 @Override86 public void forceUpdateActiveField() {87 // Do nothing88 }89 82 } 90 83 … … 114 107 // test with unassigned unicode characters ==> no unicode block 115 108 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 empty127 Config.getPref().putList(historyKey, null);128 assertEquals(def, methodToTest.get()); // age OK, history empty129 }130 131 /**132 * Test of {@link UploadDialog#getLastChangesetCommentFromHistory} method.133 */134 @Test135 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 @Test146 void testGetLastChangesetSourceFromHistory() {147 doTestGetLastChangesetTagFromHistory(148 BasicUploadSettingsPanel.SOURCE_HISTORY_KEY,149 UploadDialog::getLastChangesetSourceFromHistory,150 BasicUploadSettingsPanel.getDefaultSources().get(0));151 109 } 152 110 … … 186 144 doTestValidateUploadTag("upload.source"); 187 145 } 188 189 @Test190 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 }199 146 }
Note:
See TracChangeset
for help on using the changeset viewer.