source: josm/trunk/test/unit/org/openstreetmap/josm/gui/datatransfer/TagTransferableTest.java@ 17360

Last change on this file since 17360 was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.datatransfer;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertFalse;
6import static org.junit.jupiter.api.Assertions.assertTrue;
7import static org.junit.jupiter.api.Assertions.assertThrows;
8
9import java.awt.datatransfer.DataFlavor;
10import java.awt.datatransfer.UnsupportedFlavorException;
11import java.util.HashMap;
12import java.util.Map;
13
14import org.junit.jupiter.api.Test;
15import org.junit.jupiter.api.extension.RegisterExtension;
16import org.openstreetmap.josm.gui.datatransfer.data.TagTransferData;
17import org.openstreetmap.josm.testutils.JOSMTestRules;
18
19import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
20
21/**
22 * Unit tests of {@link TagTransferable} class.
23 */
24class TagTransferableTest {
25
26 /**
27 * Setup tests
28 */
29 @RegisterExtension
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 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 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 */
61 @Test
62 void testGetTransferDataError() {
63 assertThrows(UnsupportedFlavorException.class, () -> new TagTransferable(null).getTransferData(null));
64 }
65}
Note: See TracBrowser for help on using the repository browser.