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

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

sonar - squid:S3578 - Test methods should comply with a naming convention

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