source: josm/trunk/test/unit/org/openstreetmap/josm/gui/mappaint/LabelCompositionStrategyTest.groovy@ 3989

Last change on this file since 3989 was 3988, checked in by bastiK, 14 years ago

added tests (patch by anonymous, see #6107)

File size: 4.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint
3
4import org.junit.*
5import org.openstreetmap.josm.fixtures.JOSMFixture;
6import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy
7import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.StaticLabelCompositionStrategy;
8import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.TagLookupCompositionStrategy
9import org.openstreetmap.josm.data.osm.Node;
10
11class 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// License: GPL. For details, see LICENSE file.
68package org.openstreetmap.josm.gui.mappaint
69
70import org.junit.*
71import org.openstreetmap.josm.fixtures.JOSMFixture;
72import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy
73import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.StaticLabelCompositionStrategy;
74import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.TagLookupCompositionStrategy
75import org.openstreetmap.josm.data.osm.Node;
76
77class LabelCompositionStrategyTest {
78
79 @BeforeClass
80 public static void createJOSMFixture(){
81 JOSMFixture.createUnitTestFixture().init()
82 }
83
84 @Test
85 public void createStaticLabelCompositionStrategy() {
86 def n = new Node()
87
88 def strat = new StaticLabelCompositionStrategy(null)
89 assert strat.compose(n) == null
90
91 strat = new StaticLabelCompositionStrategy("a label")
92 assert strat.compose(n) == "a label"
93 }
94
95 @Test
96 public void createTagLookupCompositionStrategy() {
97 def n = new Node()
98 n.put("my-tag", "my-value")
99
100 def strat = new TagLookupCompositionStrategy(null)
101 assert strat.compose(n) == null
102
103 strat = new TagLookupCompositionStrategy("name")
104 assert strat.compose(n) == null
105
106 strat = new TagLookupCompositionStrategy("my-tag")
107 assert strat.compose(n) == "my-value"
108 }
109
110 @Test
111 public void createDeriveLabelFromNameTagsCompositionStrategy() {
112 def n
113 def strat
114
115 strat = new DeriveLabelFromNameTagsCompositionStrategy()
116 strat.setNameTags(null)
117 assert strat.getNameTags() == []
118
119 strat = new DeriveLabelFromNameTagsCompositionStrategy()
120 strat.setNameTags(["name", "brand"])
121 assert strat.getNameTags() == ["name", "brand"]
122
123 n = new Node()
124 n.put("brand", "my brand")
125 assert strat.compose(n) == "my brand"
126
127 n = new Node()
128 n.put("name", "my name")
129 n.put("brand", "my brand")
130 assert strat.compose(n) == "my name"
131 }
132}
Note: See TracBrowser for help on using the repository browser.