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