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.assertTrue;
|
---|
7 |
|
---|
8 | import java.awt.datatransfer.DataFlavor;
|
---|
9 | import java.awt.datatransfer.UnsupportedFlavorException;
|
---|
10 | import java.io.IOException;
|
---|
11 | import java.util.HashMap;
|
---|
12 | import java.util.Map;
|
---|
13 |
|
---|
14 | import org.junit.Rule;
|
---|
15 | import org.junit.Test;
|
---|
16 | import org.openstreetmap.josm.gui.datatransfer.data.TagTransferData;
|
---|
17 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
18 |
|
---|
19 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Unit tests of {@link TagTransferable} class.
|
---|
23 | */
|
---|
24 | public class TagTransferableTest {
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Setup tests
|
---|
28 | */
|
---|
29 | @Rule
|
---|
30 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
31 | public JOSMTestRules test = new JOSMTestRules();
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Test of {@link TagTransferable#isDataFlavorSupported} method.
|
---|
35 | */
|
---|
36 | @Test
|
---|
37 | public void testIsDataFlavorSupported() {
|
---|
38 | TagTransferable tt = new TagTransferable(null);
|
---|
39 | assertTrue(tt.isDataFlavorSupported(TagTransferData.FLAVOR));
|
---|
40 | assertTrue(tt.isDataFlavorSupported(DataFlavor.stringFlavor));
|
---|
41 | assertFalse(tt.isDataFlavorSupported(DataFlavor.imageFlavor));
|
---|
42 | assertFalse(tt.isDataFlavorSupported(null));
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Test of {@link RelationMemberTransferable#getTransferData} method - nominal case.
|
---|
47 | * @throws Exception if an error occurs
|
---|
48 | */
|
---|
49 | @Test
|
---|
50 | public void testGetTransferDataNominal() throws Exception {
|
---|
51 | Map<String, String> tags = new HashMap<>();
|
---|
52 | tags.put("foo", "bar");
|
---|
53 | TagTransferable tt = new TagTransferable(new TagTransferData(tags));
|
---|
54 | assertEquals("foo=bar", tt.getTransferData(DataFlavor.stringFlavor));
|
---|
55 | assertEquals(tags, ((TagTransferData) tt.getTransferData(TagTransferData.FLAVOR)).getTags());
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Test of {@link TagTransferable#getTransferData} method - error case.
|
---|
60 | * @throws UnsupportedFlavorException always
|
---|
61 | * @throws IOException never
|
---|
62 | */
|
---|
63 | @Test(expected = UnsupportedFlavorException.class)
|
---|
64 | public void testGetTransferDataError() throws UnsupportedFlavorException, IOException {
|
---|
65 | new TagTransferable(null).getTransferData(null);
|
---|
66 | }
|
---|
67 | }
|
---|