1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.datatransfer;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 |
|
---|
7 | import java.util.Collections;
|
---|
8 |
|
---|
9 | import org.junit.Rule;
|
---|
10 | import org.junit.Test;
|
---|
11 | import org.openstreetmap.josm.actions.CopyAction;
|
---|
12 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
13 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
14 | import org.openstreetmap.josm.data.osm.Node;
|
---|
15 | import org.openstreetmap.josm.data.projection.ProjectionRegistry;
|
---|
16 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
17 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
18 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
19 |
|
---|
20 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Unit tests of {@link OsmTransferHandler} class.
|
---|
24 | */
|
---|
25 | public class OsmTransferHandlerTest {
|
---|
26 | /**
|
---|
27 | * Prefs to use OSM primitives
|
---|
28 | */
|
---|
29 | @Rule
|
---|
30 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
31 | public JOSMTestRules test = new JOSMTestRules().preferences().projection().main().platform();
|
---|
32 |
|
---|
33 | private final OsmTransferHandler transferHandler = new OsmTransferHandler();
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Test of {@link OsmTransferHandler#pasteOn} method
|
---|
37 | */
|
---|
38 | @Test
|
---|
39 | public void testPasteOn() {
|
---|
40 | DataSet ds1 = new DataSet();
|
---|
41 | Node n1 = new Node(new LatLon(43, 1));
|
---|
42 | ds1.addPrimitive(n1);
|
---|
43 | OsmDataLayer source = new OsmDataLayer(ds1, "source", null);
|
---|
44 |
|
---|
45 | CopyAction.copy(source, Collections.singleton(n1));
|
---|
46 |
|
---|
47 | DataSet ds2 = new DataSet();
|
---|
48 | OsmDataLayer target = new OsmDataLayer(ds2, "target", null);
|
---|
49 |
|
---|
50 | transferHandler.pasteOn(target, null);
|
---|
51 | assertTrue(n1.getCoor().equalsEpsilon(ds2.getNodes().iterator().next().getCoor()));
|
---|
52 |
|
---|
53 | ds2.clear();
|
---|
54 | assertTrue(ds2.getNodes().isEmpty());
|
---|
55 |
|
---|
56 | LatLon pos = new LatLon(55, -5);
|
---|
57 | transferHandler.pasteOn(target, ProjectionRegistry.getProjection().latlon2eastNorth(pos));
|
---|
58 | assertTrue(pos.equalsEpsilon(ds2.getNodes().iterator().next().getCoor()));
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Test of {@link OsmTransferHandler#pasteTags} method
|
---|
63 | */
|
---|
64 | @Test
|
---|
65 | public void testPasteTags() {
|
---|
66 | Node n = new Node(LatLon.ZERO);
|
---|
67 | MainApplication.getLayerManager().addLayer(new OsmDataLayer(new DataSet(n), "testPasteTags", null));
|
---|
68 |
|
---|
69 | ClipboardUtils.copyString("test=ok");
|
---|
70 | transferHandler.pasteTags(Collections.singleton(n));
|
---|
71 |
|
---|
72 | assertEquals("ok", n.get("test"));
|
---|
73 | }
|
---|
74 | }
|
---|