source: josm/trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReaderTest.java@ 14138

Last change on this file since 14138 was 14138, checked in by Don-vip, 6 years ago

see #15229 - deprecate Main.platform and related methods - new class PlatformManager

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging.presets;
3
4import static org.CustomMatchers.hasSize;
5import static org.junit.Assert.assertEquals;
6import static org.junit.Assert.assertThat;
7import static org.junit.Assert.assertTrue;
8
9import java.io.IOException;
10import java.util.Collection;
11import java.util.List;
12import java.util.stream.Collectors;
13
14import org.junit.Assert;
15import org.junit.Rule;
16import org.junit.Test;
17import org.openstreetmap.josm.TestUtils;
18import org.openstreetmap.josm.gui.tagging.presets.items.Check;
19import org.openstreetmap.josm.gui.tagging.presets.items.Key;
20import org.openstreetmap.josm.testutils.JOSMTestRules;
21import org.xml.sax.SAXException;
22
23import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
24
25/**
26 * Unit tests of {@link TaggingPresetReader} class.
27 */
28public class TaggingPresetReaderTest {
29
30 /**
31 * Setup rule
32 */
33 @Rule
34 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
35 public JOSMTestRules test = new JOSMTestRules();
36
37 /**
38 * #8954 - last checkbox in the preset is not added
39 * @throws SAXException if any XML error occurs
40 * @throws IOException if any I/O error occurs
41 */
42 @Test
43 public void testTicket8954() throws SAXException, IOException {
44 String presetfile = TestUtils.getRegressionDataFile(8954, "preset.xml");
45 final Collection<TaggingPreset> presets = TaggingPresetReader.readAll(presetfile, false);
46 Assert.assertEquals("Number of preset items", 1, presets.size());
47 final TaggingPreset preset = presets.iterator().next();
48 Assert.assertEquals("Number of entries", 1, preset.data.size());
49 final TaggingPresetItem item = preset.data.get(0);
50 Assert.assertTrue("Entry is not checkbox", item instanceof Check);
51 }
52
53 /**
54 * Test nested chunks
55 * @throws SAXException if any XML error occurs
56 * @throws IOException if any I/O error occurs
57 */
58 @Test
59 public void testNestedChunks() throws SAXException, IOException {
60 final Collection<TaggingPreset> presets = TaggingPresetReader.readAll(TestUtils.getTestDataRoot() + "preset_chunk.xml", true);
61 assertThat(presets, hasSize(1));
62 final TaggingPreset abc = presets.iterator().next();
63 assertTrue(abc.data.stream().allMatch(Key.class::isInstance));
64 final List<String> keys = abc.data.stream().map(x -> ((Key) x).key).collect(Collectors.toList());
65 assertEquals("[A1, A2, A3, B1, B2, B3, C1, C2, C3]", keys.toString());
66 }
67
68 /**
69 * Validate internal presets
70 * See #9027
71 * @throws SAXException if any XML error occurs
72 * @throws IOException if any I/O error occurs
73 */
74 @Test
75 public void testReadDefaulPresets() throws SAXException, IOException {
76 String presetfile = "resource://data/defaultpresets.xml";
77 final Collection<TaggingPreset> presets = TaggingPresetReader.readAll(presetfile, true);
78 Assert.assertTrue("Default presets are empty", presets.size() > 0);
79 }
80}
Note: See TracBrowser for help on using the repository browser.