[3988] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.gui.mappaint
|
---|
[4069] | 3 | import java.awt.Color
|
---|
[3988] | 4 |
|
---|
[4069] | 5 | import org.junit.*
|
---|
[7081] | 6 | import org.openstreetmap.josm.JOSMFixture
|
---|
[7418] | 7 | import org.openstreetmap.josm.data.osm.Node
|
---|
[4074] | 8 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.TagKeyReference
|
---|
[9279] | 9 | import org.openstreetmap.josm.gui.mappaint.styleelement.TextLabel
|
---|
| 10 | import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy
|
---|
| 11 | import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.TagLookupCompositionStrategy
|
---|
[7081] | 12 |
|
---|
[3988] | 13 | class MapCSSWithExtendedTextDirectivesTest {
|
---|
| 14 |
|
---|
| 15 | @BeforeClass
|
---|
| 16 | public static void createJOSMFixture(){
|
---|
| 17 | JOSMFixture.createUnitTestFixture().init()
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | @Test
|
---|
| 21 | public void createAutoTextElement() {
|
---|
[7418] | 22 | MultiCascade mc = new MultiCascade()
|
---|
| 23 | Cascade c = mc.getOrCreateCascade("default")
|
---|
[3988] | 24 | c.put("text", new Keyword("auto"))
|
---|
[7418] | 25 | Node osm = new Node()
|
---|
| 26 | osm.put("ref", "A456");
|
---|
| 27 | Environment env = new Environment(osm, mc, "default", null)
|
---|
[7081] | 28 |
|
---|
[9279] | 29 | TextLabel te = TextLabel.create(env, Color.WHITE, false /* no default annotate */)
|
---|
[3988] | 30 | assert te.labelCompositionStrategy != null
|
---|
| 31 | assert te.labelCompositionStrategy instanceof DeriveLabelFromNameTagsCompositionStrategy
|
---|
| 32 | }
|
---|
[7081] | 33 |
|
---|
[3988] | 34 | @Test
|
---|
| 35 | public void createTextElementComposingTextFromTag() {
|
---|
[7418] | 36 | MultiCascade mc = new MultiCascade()
|
---|
| 37 | Cascade c = mc.getOrCreateCascade("default")
|
---|
[4074] | 38 | c.put("text", new TagKeyReference("my_name"))
|
---|
[7418] | 39 | Node osm = new Node()
|
---|
| 40 | osm.put("my_name", "foobar");
|
---|
| 41 | Environment env = new Environment(osm, mc, "default", null)
|
---|
[7081] | 42 |
|
---|
[9279] | 43 | TextLabel te = TextLabel.create(env, Color.WHITE, false /* no default annotate */)
|
---|
[3988] | 44 | assert te.labelCompositionStrategy != null
|
---|
| 45 | assert te.labelCompositionStrategy instanceof TagLookupCompositionStrategy
|
---|
| 46 | assert te.labelCompositionStrategy.getDefaultLabelTag() == "my_name"
|
---|
| 47 | }
|
---|
[7081] | 48 |
|
---|
[3988] | 49 | @Test
|
---|
| 50 | public void createNullStrategy() {
|
---|
[7418] | 51 | MultiCascade mc = new MultiCascade()
|
---|
| 52 | Node osm = new Node()
|
---|
| 53 | Environment env = new Environment(osm, mc, "default", null)
|
---|
[7081] | 54 |
|
---|
[9279] | 55 | TextLabel te = TextLabel.create(env, Color.WHITE, false /* no default annotate */)
|
---|
[7081] | 56 | assert te == null
|
---|
[3988] | 57 | }
|
---|
| 58 | }
|
---|