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