source: josm/trunk/test/unit/org/openstreetmap/josm/gui/tagging/PresetClassificationsTest.java@ 8450

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

unit tests - simplify assertions

  • 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;
3
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
6
7import java.io.IOException;
8import java.util.Collection;
9import java.util.Collections;
10import java.util.EnumSet;
11import java.util.List;
12
13import org.junit.BeforeClass;
14import org.junit.Test;
15import org.openstreetmap.josm.JOSMFixture;
16import org.openstreetmap.josm.data.osm.Node;
17import org.openstreetmap.josm.data.osm.OsmPrimitive;
18import org.openstreetmap.josm.data.osm.OsmUtils;
19import org.openstreetmap.josm.data.osm.Way;
20import org.openstreetmap.josm.tools.Utils;
21import org.xml.sax.SAXException;
22
23public class PresetClassificationsTest {
24
25 final static TaggingPresetSelector.PresetClassifications classifications = new TaggingPresetSelector.PresetClassifications();
26
27 /**
28 * Setup test.
29 */
30 @BeforeClass
31 public static void setUp() throws IOException, SAXException {
32 JOSMFixture.createUnitTestFixture().init();
33 final Collection<TaggingPreset> presets = TaggingPresetReader.readAll("resource://data/defaultpresets.xml", true);
34 classifications.loadPresets(presets);
35 }
36
37 private List<TaggingPresetSelector.PresetClassification> getMatchingPresets(String searchText, OsmPrimitive w) {
38 return classifications.getMatchingPresets(searchText, true, true, EnumSet.of(TaggingPresetType.forPrimitive(w)), Collections.singleton(w));
39 }
40
41 private List<String> getMatchingPresetNames(String searchText, OsmPrimitive w) {
42 return Utils.transform(getMatchingPresets(searchText, w), new Utils.Function<TaggingPresetSelector.PresetClassification, String>() {
43 @Override
44 public String apply(TaggingPresetSelector.PresetClassification x) {
45 return x.preset.name;
46 }
47 });
48 }
49
50 @Test
51 public void testBuilding() throws Exception {
52 final Way w = new Way();
53 final Node n1 = new Node();
54 w.addNode(n1);
55 w.addNode(new Node());
56 w.addNode(new Node());
57 assertFalse("unclosed way should not match building preset", getMatchingPresetNames("building", w).contains("Building"));
58 w.addNode(n1);
59 assertTrue("closed way should match building preset", getMatchingPresetNames("building", w).contains("Building"));
60 }
61
62 @Test
63 public void testRelationsForTram() {
64 final OsmPrimitive tram = OsmUtils.createPrimitive("way railway=tram");
65 assertTrue("railway=tram should match 'Railway Route' for relation creation", getMatchingPresetNames("route", tram).contains("Railway Route"));
66 assertTrue("railway=tram should match 'Public Transport Route' for relation creation", getMatchingPresetNames("route", tram).contains("Public Transport Route"));
67 assertFalse("railway=tram should not match 'Bus route'", getMatchingPresetNames("route", tram).contains("Bus route"));
68 }
69}
Note: See TracBrowser for help on using the repository browser.