| | 1 | // License: GPL. For details, see LICENSE file. |
| | 2 | package org.openstreetmap.josm.gui.tagging; |
| | 3 | |
| | 4 | import java.io.IOException; |
| | 5 | import java.util.Collection; |
| | 6 | |
| | 7 | import org.junit.Assert; |
| | 8 | import org.junit.BeforeClass; |
| | 9 | import org.junit.Test; |
| | 10 | import org.openstreetmap.josm.Main; |
| | 11 | import org.openstreetmap.josm.data.Preferences; |
| | 12 | import org.xml.sax.SAXException; |
| | 13 | |
| | 14 | /** |
| | 15 | * Unit tests of {@link TaggingPresetReader} class. |
| | 16 | */ |
| | 17 | public class TaggingPresetReaderTest { |
| | 18 | /** |
| | 19 | * path to test data root directory |
| | 20 | */ |
| | 21 | private static String testdataroot; |
| | 22 | |
| | 23 | @BeforeClass |
| | 24 | public static void setUpClass() { |
| | 25 | Main.pref = new Preferences(); |
| | 26 | testdataroot = System.getProperty("josm.test.data"); |
| | 27 | if (testdataroot == null || testdataroot.isEmpty()) { |
| | 28 | testdataroot = "test/data"; |
| | 29 | System.out.println("System property josm.test.data is not set, using '" + testdataroot + "'"); |
| | 30 | } |
| | 31 | } |
| | 32 | |
| | 33 | /** |
| | 34 | * Gets path to test data directory for given ticketid. |
| | 35 | * @param ticketid |
| | 36 | * @return |
| | 37 | */ |
| | 38 | protected static String getRegressionDataDir(int ticketid) { |
| | 39 | return testdataroot + "/regress/" + ticketid; |
| | 40 | } |
| | 41 | |
| | 42 | /** |
| | 43 | * Gets path to given file in test data directory for given ticketid. |
| | 44 | * @param ticketid |
| | 45 | * @param filename |
| | 46 | * @return |
| | 47 | */ |
| | 48 | protected static String getRegressionDataFile(int ticketid, String filename) { |
| | 49 | return getRegressionDataDir(ticketid) + '/' + filename; |
| | 50 | } |
| | 51 | |
| | 52 | /** |
| | 53 | * #8954 - last checkbox in the preset is not added |
| | 54 | */ |
| | 55 | @Test |
| | 56 | public void test8954() throws SAXException, IOException { |
| | 57 | String presetfile = getRegressionDataFile(8954, "preset.xml"); |
| | 58 | final Collection<TaggingPreset> presets = TaggingPresetReader.readAll(presetfile, false); |
| | 59 | Assert.assertEquals("Number of preset items", 1, presets.size()); |
| | 60 | final TaggingPreset preset = presets.iterator().next(); |
| | 61 | Assert.assertEquals("Number of entries", 1, preset.data.size()); |
| | 62 | final TaggingPresetItem item = preset.data.get(0); |
| | 63 | Assert.assertTrue("Entry is not checkbox", item instanceof TaggingPresetItems.Check); |
| | 64 | } |
| | 65 | |
| | 66 | } |