1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 |
|
---|
6 | import java.io.FileInputStream;
|
---|
7 | import java.io.IOException;
|
---|
8 | import java.io.InputStream;
|
---|
9 |
|
---|
10 | import org.junit.BeforeClass;
|
---|
11 | import org.junit.Test;
|
---|
12 | import org.openstreetmap.josm.JOSMFixture;
|
---|
13 | import org.openstreetmap.josm.Main;
|
---|
14 | import org.openstreetmap.josm.TestUtils;
|
---|
15 | import org.openstreetmap.josm.actions.search.SearchAction;
|
---|
16 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
17 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
18 | import org.openstreetmap.josm.io.IllegalDataException;
|
---|
19 | import org.openstreetmap.josm.io.OsmReader;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Unit tests of {@link JoinAreasAction} class.
|
---|
23 | */
|
---|
24 | public class JoinAreasActionTest {
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Setup test.
|
---|
28 | */
|
---|
29 | @BeforeClass
|
---|
30 | public static void setUp() {
|
---|
31 | JOSMFixture.createUnitTestFixture().init(true);
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Non-regression test for bug #10511.
|
---|
36 | * @throws IOException if any I/O error occurs
|
---|
37 | * @throws IllegalDataException if OSM parsing fails
|
---|
38 | */
|
---|
39 | @Test
|
---|
40 | public void testTicket10511() throws IOException, IllegalDataException {
|
---|
41 | try (InputStream is = new FileInputStream(TestUtils.getRegressionDataFile(10511, "10511_mini.osm"))) {
|
---|
42 | DataSet ds = OsmReader.parseDataSet(is, null);
|
---|
43 | Main.map.mapView.addLayer(new OsmDataLayer(ds, null, null));
|
---|
44 | // FIXME enable this test after we fix the bug. Test disabled for now
|
---|
45 | // new JoinAreasAction().join(ds.getWays());
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Non-regression test for bug #11992.
|
---|
51 | * @throws IOException if any I/O error occurs
|
---|
52 | * @throws IllegalDataException if OSM parsing fails
|
---|
53 | */
|
---|
54 | @Test
|
---|
55 | public void testTicket11992() throws IOException, IllegalDataException {
|
---|
56 | try (InputStream is = new FileInputStream(TestUtils.getRegressionDataFile(11992, "shapes.osm"))) {
|
---|
57 | DataSet ds = OsmReader.parseDataSet(is, null);
|
---|
58 | assertEquals(10, ds.getWays().size());
|
---|
59 | Main.map.mapView.addLayer(new OsmDataLayer(ds, null, null));
|
---|
60 | for (String ref : new String[]{"A", "B", "C", "D", "E"}) {
|
---|
61 | System.out.print("Joining ways " + ref);
|
---|
62 | SearchAction.search("type:way ref="+ref, SearchAction.SearchMode.replace);
|
---|
63 | assertEquals(2, ds.getSelectedWays().size());
|
---|
64 | Main.main.menu.joinAreas.join(ds.getSelectedWays());
|
---|
65 | assertEquals(1, ds.getSelectedWays().size());
|
---|
66 | System.out.println(" ==> OK");
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|