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.assertNotNull;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertNull;
|
---|
7 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
8 |
|
---|
9 | import java.awt.Color;
|
---|
10 |
|
---|
11 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
12 | import org.junit.jupiter.api.Test;
|
---|
13 | import org.openstreetmap.josm.data.osm.Node;
|
---|
14 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.TagKeyReference;
|
---|
15 | import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy;
|
---|
16 | import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.TagLookupCompositionStrategy;
|
---|
17 | import org.openstreetmap.josm.gui.mappaint.styleelement.TextLabel;
|
---|
18 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
19 |
|
---|
20 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Extended text directives tests.
|
---|
24 | */
|
---|
25 | class MapCSSWithExtendedTextDirectivesTest {
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Setup rule
|
---|
29 | */
|
---|
30 | @RegisterExtension
|
---|
31 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
32 | public JOSMTestRules test = new JOSMTestRules();
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Test {@link DeriveLabelFromNameTagsCompositionStrategy}
|
---|
36 | */
|
---|
37 | @Test
|
---|
38 | void testCreateAutoTextElement() {
|
---|
39 | MultiCascade mc = new MultiCascade();
|
---|
40 | Cascade c = mc.getOrCreateCascade("default");
|
---|
41 | c.put("text", new Keyword("auto"));
|
---|
42 | Node osm = new Node();
|
---|
43 | osm.put("ref", "A456");
|
---|
44 | Environment env = new Environment(osm, mc, "default", null);
|
---|
45 |
|
---|
46 | TextLabel te = TextLabel.create(env, Color.WHITE, false /* no default annotate */);
|
---|
47 | assertNotNull(te.labelCompositionStrategy);
|
---|
48 | assertTrue(te.labelCompositionStrategy instanceof DeriveLabelFromNameTagsCompositionStrategy);
|
---|
49 | }
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Test {@link TagLookupCompositionStrategy}.
|
---|
53 | */
|
---|
54 | @Test
|
---|
55 | void testCreateTextElementComposingTextFromTag() {
|
---|
56 | MultiCascade mc = new MultiCascade();
|
---|
57 | Cascade c = mc.getOrCreateCascade("default");
|
---|
58 | c.put("text", new TagKeyReference("my_name"));
|
---|
59 | Node osm = new Node();
|
---|
60 | osm.put("my_name", "foobar");
|
---|
61 | Environment env = new Environment(osm, mc, "default", null);
|
---|
62 |
|
---|
63 | TextLabel te = TextLabel.create(env, Color.WHITE, false /* no default annotate */);
|
---|
64 | assertNotNull(te.labelCompositionStrategy);
|
---|
65 | assertTrue(te.labelCompositionStrategy instanceof TagLookupCompositionStrategy);
|
---|
66 | assertEquals("my_name", ((TagLookupCompositionStrategy) te.labelCompositionStrategy).getDefaultLabelTag());
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Test null strategy.
|
---|
71 | */
|
---|
72 | @Test
|
---|
73 | void testCreateNullStrategy() {
|
---|
74 | MultiCascade mc = new MultiCascade();
|
---|
75 | Node osm = new Node();
|
---|
76 | Environment env = new Environment(osm, mc, "default", null);
|
---|
77 |
|
---|
78 | TextLabel te = TextLabel.create(env, Color.WHITE, false /* no default annotate */);
|
---|
79 | assertNull(te);
|
---|
80 | }
|
---|
81 | }
|
---|