source: josm/trunk/test/unit/org/openstreetmap/josm/gui/mappaint/MapCSSWithExtendedTextDirectivesTest.groovy @ 7938

Last change on this file since 7938 was 7938, checked in by bastiK, 5 years ago

add more subversion property svn:eol=native

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint
3import java.awt.Color
4
5import org.junit.*
6import org.openstreetmap.josm.JOSMFixture
7import org.openstreetmap.josm.data.osm.Node
8import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy
9import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.TagLookupCompositionStrategy
10import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.TagKeyReference
11
12class MapCSSWithExtendedTextDirectivesTest {
13
14    @BeforeClass
15    public static void createJOSMFixture(){
16        JOSMFixture.createUnitTestFixture().init()
17    }
18
19    @Test
20    public void createAutoTextElement() {
21        MultiCascade mc = new MultiCascade()
22        Cascade c = mc.getOrCreateCascade("default")
23        c.put("text", new Keyword("auto"))
24        Node osm = new Node()
25        osm.put("ref", "A456");
26        Environment env = new Environment(osm, mc, "default", null)
27
28        TextElement te = TextElement.create(env, Color.WHITE, false /* no default annotate */)
29        assert te.labelCompositionStrategy != null
30        assert te.labelCompositionStrategy instanceof DeriveLabelFromNameTagsCompositionStrategy
31    }
32
33    @Test
34    public void createTextElementComposingTextFromTag() {
35        MultiCascade mc = new MultiCascade()
36        Cascade c = mc.getOrCreateCascade("default")
37        c.put("text", new TagKeyReference("my_name"))
38        Node osm = new Node()
39        osm.put("my_name", "foobar");
40        Environment env = new Environment(osm, mc, "default", null)
41
42        TextElement te = TextElement.create(env, Color.WHITE, false /* no default annotate */)
43        assert te.labelCompositionStrategy != null
44        assert te.labelCompositionStrategy instanceof TagLookupCompositionStrategy
45        assert te.labelCompositionStrategy.getDefaultLabelTag() == "my_name"
46    }
47
48    @Test
49    public void createNullStrategy() {
50        MultiCascade mc = new MultiCascade()
51        Node osm = new Node()
52        Environment env = new Environment(osm, mc, "default", null)
53
54        TextElement te = TextElement.create(env, Color.WHITE, false /* no default annotate */)
55        assert te == null
56    }
57}
Note: See TracBrowser for help on using the repository browser.