source: josm/trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorterTest.java@ 15034

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

checkstyle/PMD

  • 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.dialogs.relation.sort;
3
4import java.io.IOException;
5import java.io.InputStream;
6import java.nio.file.Files;
7import java.nio.file.Paths;
8import java.util.List;
9
10import org.junit.Assert;
11import org.junit.Before;
12import org.junit.Rule;
13import org.junit.Test;
14import org.openstreetmap.josm.data.osm.DataSet;
15import org.openstreetmap.josm.data.osm.Relation;
16import org.openstreetmap.josm.data.osm.RelationMember;
17import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
18import org.openstreetmap.josm.io.IllegalDataException;
19import org.openstreetmap.josm.io.OsmReader;
20import org.openstreetmap.josm.testutils.JOSMTestRules;
21
22import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
23
24/**
25 * Unit tests of {@link RelationSorter} class.
26 */
27public class RelationSorterTest {
28
29 private final RelationSorter sorter = new RelationSorter();
30 private DataSet testDataset;
31
32 /**
33 * Use Mercator projection
34 */
35 @Rule
36 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
37 public JOSMTestRules test = new JOSMTestRules().preferences().projection();
38
39 /**
40 * Load the test data set
41 * @throws IllegalDataException if an error was found while parsing the data
42 * @throws IOException in case of I/O error
43 */
44 @Before
45 public void loadData() throws IllegalDataException, IOException {
46 if (testDataset == null) {
47 try (InputStream fis = Files.newInputStream(Paths.get("data_nodist/relation_sort.osm"))) {
48 testDataset = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
49 }
50 }
51 }
52
53 private Relation getRelation(String testType) {
54 for (Relation r: testDataset.getRelations()) {
55 if (testType.equals(r.get("test")))
56 return r;
57 }
58 return null;
59 }
60
61 private String[] getNames(List<RelationMember> members) {
62 String[] result = new String[members.size()];
63 for (int i = 0; i < result.length; i++) {
64 result[i] = members.get(i).getMember().get("name");
65 }
66 return result;
67 }
68
69 @Test
70 public void testGeneric() {
71 String[] actual = getNames(sorter.sortMembers(getRelation("generic").getMembers()));
72 final String[] expected = {"t1w4", "t1w3", "t1w2", "t1w1", "t1w7", "t1w6", "t1w5", "t1n1", "t1n2"};
73 // expect nodes to be sorted correctly
74 Assert.assertEquals(expected[7], actual[7]);
75 Assert.assertEquals(expected[8], actual[8]);
76 }
77
78 @Test
79 public void testAssociatedStreet() {
80 String[] actual = getNames(sorter.sortMembers(getRelation("associatedStreet").getMembers()));
81 Assert.assertArrayEquals(new String[] {"t2w1", "t2w2", "t2n1", "t2n2", "t2n3", "t2n4"}, actual);
82 }
83
84 @Test
85 public void testStreet() {
86 String[] actual = getNames(sorter.sortMembers(getRelation("street").getMembers()));
87 Assert.assertArrayEquals(new String[]{"t2w1", "t2w2", "t2n1", "t2n2", "t2n3", "t2n4", "playground", "tree"}, actual);
88 }
89}
Note: See TracBrowser for help on using the repository browser.