Changeset 19261 in josm for trunk/test
- Timestamp:
- 2024-11-25T23:08:52+01:00 (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/TextTest.java
r18918 r19261 3 3 4 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertInstanceOf; 5 6 import static org.junit.jupiter.api.Assertions.assertTrue; 6 7 8 import java.text.MessageFormat; 9 import java.util.ArrayList; 10 import java.util.Collection; 11 import java.util.Collections; 12 import java.util.List; 13 import java.util.Map; 14 15 import javax.swing.JComponent; 7 16 import javax.swing.JPanel; 8 17 9 18 import org.junit.jupiter.api.Test; 19 import org.junit.jupiter.params.ParameterizedTest; 20 import org.junit.jupiter.params.provider.ValueSource; 21 import org.openstreetmap.josm.data.osm.Tag; 22 import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; 10 23 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 11 24 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest; 25 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType; 26 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; 27 import org.openstreetmap.josm.gui.widgets.JosmTextField; 12 28 import org.openstreetmap.josm.testutils.annotations.Main; 13 29 … … 33 49 assertTrue(p.getComponentCount() > 0); 34 50 } 51 52 @org.openstreetmap.josm.testutils.annotations.TaggingPresets 53 @ParameterizedTest 54 @ValueSource(strings = {"\n\n\n\t\r {0}\n\n\n", "{0}"}) 55 void testNonRegression24023(String inscription) { 56 // There is a bit of "extra" whitespace in the string (` \n`). It is somewhat deliberate. We probably ought to remove the ` ` at some time. 57 final String expected = "This is a \nsample \ninscription"; 58 final String toTest = MessageFormat.format(inscription, expected).replace("sample ", "sample "); 59 final Collection<TaggingPreset> presets = TaggingPresets.getMatchingPresets(Collections.singleton(TaggingPresetType.NODE), Map.of("historic", "boundary_stone", "inscription", "bar"), false); 60 assertEquals(1, presets.size()); 61 final TaggingPreset preset = presets.iterator().next(); 62 final Text text = assertInstanceOf(Text.class, preset.data.get(5)); 63 final List<Tag> changeCommands = new ArrayList<>(1); 64 final JPanel panel = new JPanel(); 65 text.addToPanel(panel, TaggingPresetItemGuiSupport.create(false)); 66 JComponent value = assertInstanceOf(JComponent.class, panel.getComponent(1)); 67 while (value instanceof JPanel) { 68 value = (JComponent) value.getComponent(0); 69 } 70 final JosmTextField textField = assertInstanceOf(JosmTextField.class, value, "Until we support multiline editing, this should be a text field"); 71 textField.setText(toTest); 72 text.addCommands(changeCommands); 73 assertTrue(text.multiline); 74 assertTrue(text.normalize); 75 assertEquals(1, changeCommands.size()); 76 assertEquals(expected, changeCommands.get(0).getValue(), "If the only difference is a trailing space was removed, update the test."); 77 } 35 78 }
Note:
See TracChangeset
for help on using the changeset viewer.