source: josm/trunk/test/unit/org/openstreetmap/josm/actions/JoinAreasActionTest.java@ 10956

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

convert more unit tests to JOSMTestRules

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.junit.Assert.assertEquals;
5
6import java.io.IOException;
7import java.io.InputStream;
8import java.util.Collection;
9
10import org.junit.Rule;
11import org.junit.Test;
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.TestUtils;
14import org.openstreetmap.josm.actions.search.SearchAction;
15import org.openstreetmap.josm.data.osm.DataSet;
16import org.openstreetmap.josm.data.osm.OsmPrimitive;
17import org.openstreetmap.josm.data.osm.Way;
18import org.openstreetmap.josm.gui.layer.Layer;
19import org.openstreetmap.josm.gui.layer.OsmDataLayer;
20import org.openstreetmap.josm.io.IllegalDataException;
21import org.openstreetmap.josm.io.OsmReader;
22import org.openstreetmap.josm.testutils.JOSMTestRules;
23import org.openstreetmap.josm.tools.Utils;
24
25import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
26
27/**
28 * Unit tests of {@link JoinAreasAction} class.
29 */
30public class JoinAreasActionTest {
31
32 /**
33 * Setup test.
34 */
35 @Rule
36 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
37 public JOSMTestRules test = new JOSMTestRules().commands();
38
39 /**
40 * Non-regression test for bug #10511.
41 * @throws IOException if any I/O error occurs
42 * @throws IllegalDataException if OSM parsing fails
43 */
44 @Test
45 public void testTicket10511() throws IOException, IllegalDataException {
46 try (InputStream is = TestUtils.getRegressionDataStream(10511, "10511_mini.osm")) {
47 DataSet ds = OsmReader.parseDataSet(is, null);
48 Layer layer = new OsmDataLayer(ds, null, null);
49 Main.getLayerManager().addLayer(layer);
50 // FIXME enable this test after we fix the bug. Test disabled for now
51 // try {
52 // new JoinAreasAction().join(ds.getWays());
53 // } finally {
54 // Ensure we clean the place before leaving, even if test fails.
55 Main.getLayerManager().removeLayer(layer);
56 // }
57 }
58 }
59
60 /**
61 * Non-regression test for bug #11992.
62 * @throws IOException if any I/O error occurs
63 * @throws IllegalDataException if OSM parsing fails
64 */
65 @Test
66 public void testTicket11992() throws IOException, IllegalDataException {
67 try (InputStream is = TestUtils.getRegressionDataStream(11992, "shapes.osm")) {
68 DataSet ds = OsmReader.parseDataSet(is, null);
69 assertEquals(10, ds.getWays().size());
70 Layer layer = new OsmDataLayer(ds, null, null);
71 Main.getLayerManager().addLayer(layer);
72 for (String ref : new String[]{"A", "B", "C", "D", "E"}) {
73 System.out.print("Joining ways " + ref);
74 Collection<OsmPrimitive> found = SearchAction.searchAndReturn("type:way ref="+ref, SearchAction.SearchMode.replace);
75 assertEquals(2, found.size());
76
77 Main.main.menu.joinAreas.join(Utils.filteredCollection(found, Way.class));
78
79 Collection<OsmPrimitive> found2 = SearchAction.searchAndReturn("type:way ref="+ref, SearchAction.SearchMode.replace);
80 assertEquals(1, found2.size());
81 System.out.println(" ==> OK");
82 }
83 }
84 }
85}
Note: See TracBrowser for help on using the repository browser.