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.assertFalse;
|
---|
6 | import static org.junit.Assert.assertNotNull;
|
---|
7 | import static org.junit.Assert.assertTrue;
|
---|
8 | import static org.openstreetmap.josm.gui.datatransfer.PrimitiveTransferable.PRIMITIVE_DATA;
|
---|
9 |
|
---|
10 | import java.awt.datatransfer.DataFlavor;
|
---|
11 | import java.awt.datatransfer.UnsupportedFlavorException;
|
---|
12 | import java.util.Collection;
|
---|
13 | import java.util.Collections;
|
---|
14 |
|
---|
15 | import org.junit.BeforeClass;
|
---|
16 | import org.junit.Test;
|
---|
17 | import org.openstreetmap.josm.JOSMFixture;
|
---|
18 | import org.openstreetmap.josm.data.osm.Node;
|
---|
19 | import org.openstreetmap.josm.data.osm.PrimitiveData;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Unit tests of {@link PrimitiveTransferable} class.
|
---|
23 | */
|
---|
24 | public class PrimitiveTransferableTest {
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Setup tests
|
---|
28 | */
|
---|
29 | @BeforeClass
|
---|
30 | public static void setUpBeforeClass() {
|
---|
31 | JOSMFixture.createUnitTestFixture().init();
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Test of {@link PrimitiveTransferable#getTransferDataFlavors()} method.
|
---|
36 | */
|
---|
37 | @Test
|
---|
38 | public void testGetTransferDataFlavors() {
|
---|
39 | DataFlavor[] flavors = new PrimitiveTransferable(null).getTransferDataFlavors();
|
---|
40 | assertEquals(2, flavors.length);
|
---|
41 | assertEquals(PRIMITIVE_DATA, flavors[0]);
|
---|
42 | assertEquals(DataFlavor.stringFlavor, flavors[1]);
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Test of {@link PrimitiveTransferable#isDataFlavorSupported} method.
|
---|
47 | */
|
---|
48 | @Test
|
---|
49 | public void testIsDataFlavorSupported() {
|
---|
50 | assertTrue(new PrimitiveTransferable(null).isDataFlavorSupported(PRIMITIVE_DATA));
|
---|
51 | assertFalse(new PrimitiveTransferable(null).isDataFlavorSupported(null));
|
---|
52 | }
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Test of {@link PrimitiveTransferable#getTransferData} method - nominal case.
|
---|
56 | * @throws UnsupportedFlavorException never
|
---|
57 | */
|
---|
58 | @Test
|
---|
59 | @SuppressWarnings("unchecked")
|
---|
60 | public void testGetTransferDataNominal() throws UnsupportedFlavorException {
|
---|
61 | PrimitiveTransferable pt = new PrimitiveTransferable(Collections.singleton(new Node(1)));
|
---|
62 | assertEquals("node 1 # incomplete\n", pt.getTransferData(DataFlavor.stringFlavor));
|
---|
63 | Collection<PrimitiveData> td = (Collection<PrimitiveData>) pt.getTransferData(PRIMITIVE_DATA);
|
---|
64 | assertEquals(1, td.size());
|
---|
65 | assertNotNull(td.iterator().next());
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Test of {@link PrimitiveTransferable#getTransferData} method - error case.
|
---|
70 | * @throws UnsupportedFlavorException always
|
---|
71 | */
|
---|
72 | @Test(expected = UnsupportedFlavorException.class)
|
---|
73 | public void testGetTransferDataError() throws UnsupportedFlavorException {
|
---|
74 | new PrimitiveTransferable(Collections.singleton(new Node(1))).getTransferData(null);
|
---|
75 | }
|
---|
76 | }
|
---|