1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.layer;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
---|
7 | import static org.junit.jupiter.api.Assertions.assertNull;
|
---|
8 |
|
---|
9 | import java.io.InputStream;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.TestUtils;
|
---|
12 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
13 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
14 | import org.openstreetmap.josm.io.OsmReader;
|
---|
15 | import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
---|
16 |
|
---|
17 | import org.junit.jupiter.api.Test;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Unit tests of {@link DuplicateAction} class.
|
---|
21 | */
|
---|
22 | // TMS layer needs prefs. Platform for LayerListDialog shortcuts.
|
---|
23 | @BasicPreferences
|
---|
24 | class DuplicateActionTest {
|
---|
25 | /**
|
---|
26 | * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/4539">#4539</a>.
|
---|
27 | * @throws Exception if an error occurs
|
---|
28 | */
|
---|
29 | @Test
|
---|
30 | void testTicket4539() throws Exception {
|
---|
31 | try (InputStream is = TestUtils.getRegressionDataStream(4539, "josm_error_#4539.osm.zip")) {
|
---|
32 | OsmDataLayer layer = new OsmDataLayer(OsmReader.parseDataSet(is, null), null, null);
|
---|
33 | OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
|
---|
34 | assertNull(editLayer);
|
---|
35 | try {
|
---|
36 | new DuplicateAction(layer, null).actionPerformed(null);
|
---|
37 | editLayer = MainApplication.getLayerManager().getEditLayer();
|
---|
38 | assertNotNull(editLayer);
|
---|
39 | assertNotEquals(layer, editLayer);
|
---|
40 | assertEquals(layer.data.getNodes().size(), editLayer.data.getNodes().size());
|
---|
41 | assertEquals(layer.data.getWays().size(), editLayer.data.getWays().size());
|
---|
42 | assertEquals(layer.data.getRelations().size(), editLayer.data.getRelations().size());
|
---|
43 | } finally {
|
---|
44 | // Ensure we clean the place before leaving, even if test fails.
|
---|
45 | if (editLayer != null) {
|
---|
46 | MainApplication.getLayerManager().removeLayer(editLayer);
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|