1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertNull;
|
---|
6 |
|
---|
7 | import java.util.Arrays;
|
---|
8 | import java.util.Collections;
|
---|
9 |
|
---|
10 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
11 | import org.junit.jupiter.api.Test;
|
---|
12 | import org.openstreetmap.josm.data.osm.Node;
|
---|
13 | import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy;
|
---|
14 | import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy;
|
---|
15 | import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.StaticLabelCompositionStrategy;
|
---|
16 | import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.TagLookupCompositionStrategy;
|
---|
17 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
18 |
|
---|
19 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Unit tests of {@link LabelCompositionStrategy}.
|
---|
23 | */
|
---|
24 | class 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 | }
|
---|