[3988] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.gui.mappaint
|
---|
| 3 |
|
---|
| 4 | import org.junit.*
|
---|
| 5 | import org.openstreetmap.josm.fixtures.JOSMFixture;
|
---|
| 6 | import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy
|
---|
| 7 | import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.StaticLabelCompositionStrategy;
|
---|
| 8 | import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.TagLookupCompositionStrategy
|
---|
| 9 | import org.openstreetmap.josm.data.osm.Node;
|
---|
| 10 |
|
---|
| 11 | class LabelCompositionStrategyTest {
|
---|
| 12 |
|
---|
| 13 | @BeforeClass
|
---|
| 14 | public static void createJOSMFixture(){
|
---|
| 15 | JOSMFixture.createUnitTestFixture().init()
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | @Test
|
---|
| 19 | public void createStaticLabelCompositionStrategy() {
|
---|
| 20 | def n = new Node()
|
---|
| 21 |
|
---|
| 22 | def strat = new StaticLabelCompositionStrategy(null)
|
---|
| 23 | assert strat.compose(n) == null
|
---|
| 24 |
|
---|
| 25 | strat = new StaticLabelCompositionStrategy("a label")
|
---|
| 26 | assert strat.compose(n) == "a label"
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | @Test
|
---|
| 30 | public void createTagLookupCompositionStrategy() {
|
---|
| 31 | def n = new Node()
|
---|
| 32 | n.put("my-tag", "my-value")
|
---|
| 33 |
|
---|
| 34 | def strat = new TagLookupCompositionStrategy(null)
|
---|
| 35 | assert strat.compose(n) == null
|
---|
| 36 |
|
---|
| 37 | strat = new TagLookupCompositionStrategy("name")
|
---|
| 38 | assert strat.compose(n) == null
|
---|
| 39 |
|
---|
| 40 | strat = new TagLookupCompositionStrategy("my-tag")
|
---|
| 41 | assert strat.compose(n) == "my-value"
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | @Test
|
---|
| 45 | public void createDeriveLabelFromNameTagsCompositionStrategy() {
|
---|
| 46 | def n
|
---|
| 47 | def strat
|
---|
| 48 |
|
---|
| 49 | strat = new DeriveLabelFromNameTagsCompositionStrategy()
|
---|
| 50 | strat.setNameTags(null)
|
---|
| 51 | assert strat.getNameTags() == []
|
---|
| 52 |
|
---|
| 53 | strat = new DeriveLabelFromNameTagsCompositionStrategy()
|
---|
| 54 | strat.setNameTags(["name", "brand"])
|
---|
| 55 | assert strat.getNameTags() == ["name", "brand"]
|
---|
| 56 |
|
---|
| 57 | n = new Node()
|
---|
| 58 | n.put("brand", "my brand")
|
---|
| 59 | assert strat.compose(n) == "my brand"
|
---|
| 60 |
|
---|
| 61 | n = new Node()
|
---|
| 62 | n.put("name", "my name")
|
---|
| 63 | n.put("brand", "my brand")
|
---|
| 64 | assert strat.compose(n) == "my name"
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|