-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #21953: Remember custom overpass servers
This was caused by not adding the new server to the HistoryComboBox list prior to saving the list. git-svn-id: https://josm.openstreetmap.de/svn/trunk@18403 0c6e7542-c601-0410-84e7-c038aed88b3b
- Loading branch information
taylor.smock
committed
Mar 21, 2022
1 parent
2b1e212
commit 623c629
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
test/unit/org/openstreetmap/josm/gui/preferences/server/OverpassServerPanelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// License: GPL. For details, see LICENSE file. | ||
package org.openstreetmap.josm.gui.preferences.server; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import org.openstreetmap.josm.gui.widgets.HistoryComboBox; | ||
import org.openstreetmap.josm.io.OverpassDownloadReader; | ||
import org.openstreetmap.josm.testutils.annotations.BasicPreferences; | ||
|
||
/** | ||
* Test class for {@link OverpassServerPanel} | ||
* @author Taylor Smock | ||
* @since 18403 | ||
*/ | ||
@BasicPreferences | ||
class OverpassServerPanelTest { | ||
/** | ||
* Non-regression test for <a href="https://josm.openstreetmap.de/ticket/21953">#21953</a> | ||
*/ | ||
@ParameterizedTest | ||
@ValueSource(strings = {"https://something.example.com/api", "https://something.example.com/api/"}) | ||
void testOverpassApiServerSaved(final String someRandomUrl) { | ||
// We expect the API to have a trailing / | ||
final String expected = someRandomUrl.endsWith("/") ? someRandomUrl : someRandomUrl + '/'; | ||
final OverpassServerPanel panel = new OverpassServerPanel(); | ||
panel.initFromPreferences(); | ||
final HistoryComboBox historyComboBox = Stream.of(panel.getComponents()).filter(HistoryComboBox.class::isInstance) | ||
.map(HistoryComboBox.class::cast).findFirst().orElseGet(() -> fail("No HistoryComboBox found")); | ||
assertEquals(OverpassDownloadReader.OVERPASS_SERVER.get(), historyComboBox.getText()); | ||
assertAll(OverpassDownloadReader.OVERPASS_SERVER_HISTORY.get().stream() | ||
.map(server -> () -> assertNotNull(historyComboBox.getModel().find(server), "Server " + server + " not found"))); | ||
historyComboBox.setText(someRandomUrl); | ||
panel.saveToPreferences(); | ||
panel.initFromPreferences(); | ||
assertEquals(OverpassDownloadReader.OVERPASS_SERVER.get(), historyComboBox.getText()); | ||
assertAll(OverpassDownloadReader.OVERPASS_SERVER_HISTORY.get().stream() | ||
.map(server -> () -> assertNotNull(historyComboBox.getModel().find(server), "Server " + server + " not found"))); | ||
assertEquals(expected, OverpassDownloadReader.OVERPASS_SERVER.get()); | ||
assertTrue(OverpassDownloadReader.OVERPASS_SERVER_HISTORY.get().contains(expected), | ||
String.join(";", OverpassDownloadReader.OVERPASS_SERVER_HISTORY.get())); | ||
} | ||
} |