source: josm/trunk/test/unit/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandlerTest.java@ 14120

Last change on this file since 14120 was 14120, checked in by Don-vip, 6 years ago

see #15229 - deprecate all Main methods related to projections. New ProjectionRegistry class

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.datatransfer;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertTrue;
6
7import java.util.Collections;
8
9import org.junit.Rule;
10import org.junit.Test;
11import org.openstreetmap.josm.actions.CopyAction;
12import org.openstreetmap.josm.data.coor.LatLon;
13import org.openstreetmap.josm.data.osm.DataSet;
14import org.openstreetmap.josm.data.osm.Node;
15import org.openstreetmap.josm.data.projection.ProjectionRegistry;
16import org.openstreetmap.josm.gui.MainApplication;
17import org.openstreetmap.josm.gui.layer.OsmDataLayer;
18import org.openstreetmap.josm.testutils.JOSMTestRules;
19
20import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
21
22/**
23 * Unit tests of {@link OsmTransferHandler} class.
24 */
25public 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}
Note: See TracBrowser for help on using the repository browser.