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