source: josm/trunk/test/unit/org/openstreetmap/josm/gui/mappaint/LabelCompositionStrategyTest.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.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertNull;
6
7import java.util.Arrays;
8import java.util.Collections;
9
10import org.junit.jupiter.api.extension.RegisterExtension;
11import org.junit.jupiter.api.Test;
12import org.openstreetmap.josm.data.osm.Node;
13import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy;
14import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy;
15import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.StaticLabelCompositionStrategy;
16import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.TagLookupCompositionStrategy;
17import org.openstreetmap.josm.testutils.JOSMTestRules;
18
19import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
20
21/**
22 * Unit tests of {@link LabelCompositionStrategy}.
23 */
24class LabelCompositionStrategyTest {
25
26 /**
27 * Setup rule
28 */
29 @RegisterExtension
30 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
31 public JOSMTestRules test = new JOSMTestRules();
32
33 /**
34 * Test {@link StaticLabelCompositionStrategy}.
35 */
36 @Test
37 void testCreateStaticLabelCompositionStrategy() {
38 Node n = new Node();
39
40 LabelCompositionStrategy strat = new StaticLabelCompositionStrategy(null);
41 assertNull(strat.compose(n));
42
43 strat = new StaticLabelCompositionStrategy("a label");
44 assertEquals("a label", strat.compose(n));
45 }
46
47 /**
48 * Test {@link TagLookupCompositionStrategy}.
49 */
50 @Test
51 void testCreateTagLookupCompositionStrategy() {
52 Node n = new Node();
53 n.put("my-tag", "my-value");
54
55 LabelCompositionStrategy strat = new TagLookupCompositionStrategy(null);
56 assertNull(strat.compose(n));
57
58 strat = new TagLookupCompositionStrategy("name");
59 assertNull(strat.compose(n));
60
61 strat = new TagLookupCompositionStrategy("my-tag");
62 assertEquals("my-value", strat.compose(n));
63 }
64
65 /**
66 * Test {@link DeriveLabelFromNameTagsCompositionStrategy}.
67 */
68 @Test
69 void testCreateDeriveLabelFromNameTagsCompositionStrategy() {
70 DeriveLabelFromNameTagsCompositionStrategy strat = new DeriveLabelFromNameTagsCompositionStrategy();
71 strat.setNameTags(null);
72 assertEquals(Collections.emptyList(), strat.getNameTags());
73
74 strat = new DeriveLabelFromNameTagsCompositionStrategy();
75 strat.setNameTags(Arrays.asList("name", "brand"));
76 assertEquals(Arrays.asList("name", "brand"), strat.getNameTags());
77
78 Node n = new Node();
79 n.put("brand", "my brand");
80 assertEquals("my brand", strat.compose(n));
81
82 n = new Node();
83 n.put("name", "my name");
84 n.put("brand", "my brand");
85 assertEquals("my name", strat.compose(n));
86 }
87}
Note: See TracBrowser for help on using the repository browser.