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

Last change on this file since 9504 was 8863, checked in by Don-vip, 9 years ago

major code cleanup/refactoring of tagging presets: slay the monster TaggingPresetItems (60 Kb, 1600 lines) and extract all its internal classes to a new package gui.tagging.presets.items

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