source: josm/trunk/test/unit/org/openstreetmap/josm/gui/datatransfer/PrimitiveTransferableTest.java@ 9585

Last change on this file since 9585 was 9563, checked in by Don-vip, 8 years ago

see #12300 - add javadoc, unit tests

File size: 2.8 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.assertFalse;
6import static org.junit.Assert.assertNotNull;
7import static org.junit.Assert.assertTrue;
8import static org.openstreetmap.josm.gui.datatransfer.PrimitiveTransferable.PRIMITIVE_DATA;
9
10import java.awt.datatransfer.DataFlavor;
11import java.awt.datatransfer.UnsupportedFlavorException;
12import java.util.Collection;
13import java.util.Collections;
14
15import org.junit.BeforeClass;
16import org.junit.Test;
17import org.openstreetmap.josm.JOSMFixture;
18import org.openstreetmap.josm.data.osm.Node;
19import org.openstreetmap.josm.data.osm.PrimitiveData;
20
21/**
22 * Unit tests of {@link PrimitiveTransferable} class.
23 */
24public 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}
Note: See TracBrowser for help on using the repository browser.