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

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

fix/cleanup unit tests

  • 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.actions;
3
4import static org.junit.Assert.assertEquals;
5
6import java.io.IOException;
7import java.io.InputStream;
8
9import org.junit.BeforeClass;
10import org.junit.Test;
11import org.openstreetmap.josm.JOSMFixture;
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.gui.layer.Layer;
17import org.openstreetmap.josm.gui.layer.OsmDataLayer;
18import org.openstreetmap.josm.io.IllegalDataException;
19import org.openstreetmap.josm.io.OsmReader;
20
21/**
22 * Unit tests of {@link JoinAreasAction} class.
23 */
24public 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 = TestUtils.getRegressionDataStream(10511, "10511_mini.osm")) {
42 DataSet ds = OsmReader.parseDataSet(is, null);
43 Layer layer = new OsmDataLayer(ds, null, null);
44 Main.main.addLayer(layer);
45 // FIXME enable this test after we fix the bug. Test disabled for now
46 // try {
47 // new JoinAreasAction().join(ds.getWays());
48 // } finally {
49 // Ensure we clean the place before leaving, even if test fails.
50 Main.main.removeLayer(layer);
51 // }
52 }
53 }
54
55 /**
56 * Non-regression test for bug #11992.
57 * @throws IOException if any I/O error occurs
58 * @throws IllegalDataException if OSM parsing fails
59 */
60 @Test
61 public void testTicket11992() throws IOException, IllegalDataException {
62 try (InputStream is = TestUtils.getRegressionDataStream(11992, "shapes.osm")) {
63 DataSet ds = OsmReader.parseDataSet(is, null);
64 assertEquals(10, ds.getWays().size());
65 Layer layer = new OsmDataLayer(ds, null, null);
66 Main.main.addLayer(layer);
67 try {
68 for (String ref : new String[]{"A", "B", "C", "D", "E"}) {
69 System.out.print("Joining ways " + ref);
70 SearchAction.search("type:way ref="+ref, SearchAction.SearchMode.replace);
71 assertEquals(2, ds.getSelectedWays().size());
72 Main.main.menu.joinAreas.join(ds.getSelectedWays());
73 assertEquals(1, ds.getSelectedWays().size());
74 System.out.println(" ==> OK");
75 }
76 } finally {
77 // Ensure we clean the place before leaving, even if test fails.
78 Main.main.removeLayer(layer);
79 }
80 }
81 }
82}
Note: See TracBrowser for help on using the repository browser.