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

Last change on this file since 9279 was 9279, checked in by Don-vip, 5 years ago

fix groovy scripts broken by r9278

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