Changeset 32409 in osm
- Timestamp:
- 2016-06-26T15:53:08+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions
- Files:
-
- 7 edited
-
TurnRestrictionBuilderTest.groovy (modified) (8 diffs)
-
editor/ExceptValueModelTest.groovy (modified) (1 diff)
-
editor/JosmSelectionListModelTest.groovy (modified) (2 diffs)
-
editor/TurnRestrictionEditorModelUnitTest.groovy (modified) (1 diff)
-
editor/TurnRestrictionLegEditorUnitTest.groovy (modified) (1 diff)
-
editor/TurnRestrictionTypeRendererTest.groovy (modified) (1 diff)
-
editor/TurnRestrictionTypeTest.groovy (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionBuilderTest.groovy
r32361 r32409 1 1 package org.openstreetmap.josm.plugins.turnrestrictions; 2 2 3 import java.util.Arrays; 4 5 import groovy.util.GroovyTestCase; 6 7 import static org.junit.Assert.*; 8 import org.junit.*; 9 import org.openstreetmap.josm.data.osm.Node; 10 import org.openstreetmap.josm.data.osm.Way; 11 import org.openstreetmap.josm.data.osm.Relation; 12 import org.openstreetmap.josm.data.osm.RelationMember; 13 import org.openstreetmap.josm.JOSMFixture; 14 import org.openstreetmap.josm.data.coor.LatLon; 3 import static org.junit.Assert.* 15 4 import static org.openstreetmap.josm.plugins.turnrestrictions.TurnRestrictionBuilder.* 5 6 import org.junit.* 7 import org.openstreetmap.josm.data.coor.LatLon 8 import org.openstreetmap.josm.data.osm.Node 9 import org.openstreetmap.josm.data.osm.Relation 10 import org.openstreetmap.josm.data.osm.RelationMember 11 import org.openstreetmap.josm.data.osm.Way 16 12 import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionType 17 import org.openstreetmap.josm.testutils.JOSMTestRules ;;13 import org.openstreetmap.josm.testutils.JOSMTestRules 18 14 19 15 class TurnRestrictionBuilderTest{ 20 16 21 17 @Rule 22 18 public JOSMTestRules rules = new JOSMTestRules().preferences(); … … 24 20 def TurnRestrictionBuilder builder = new TurnRestrictionBuilder(); 25 21 26 def boolean hasExactlyOneMemberWithRole(Relation r, String role ){27 return r.getMembers().find {RelationMember rm -> rm.getRole() == role} != null28 }29 30 def memberWithRole(Relation r, String role) {31 def RelationMember rm = r.getMembers().find {RelationMember rm -> rm.getRole() == role}32 return rm.getMember()33 }34 35 def void assertEmptyTurnRestriction(Relation r){36 assert r != null37 assert r.get("type") == "restriction"38 assert r.getMembersCount() == 039 }40 41 /**42 * Selection consist of one way and the start node of the way ->43 * propose a No-U-Turn restriction44 * 45 */46 @Test47 public void noUTurn_1() {48 Way w = new Way(1)49 Node n1 = new Node(1)50 Node n2 = new Node(2)51 w.setNodes([n1,n2])52 53 def sel = [w,n1]54 TurnRestrictionBuilder builder = new TurnRestrictionBuilder()55 Relation r = builder.build(sel)56 57 assert r != null58 assert r.getMembersCount() == 359 assert hasExactlyOneMemberWithRole(r, "from")60 assert hasExactlyOneMemberWithRole(r, "to")61 assert hasExactlyOneMemberWithRole(r, "via")62 assert memberWithRole(r, "from") == w63 assert memberWithRole(r, "to") == w64 assert memberWithRole(r, "via") == n165 assert r.get("restriction") == "no_u_turn"66 }67 68 69 /**70 * Selection consist of one way and the end node of the way ->71 * propose a No-U-Turn restriction72 *73 */22 def boolean hasExactlyOneMemberWithRole(Relation r, String role ){ 23 return r.getMembers().find {RelationMember rm -> rm.getRole() == role} != null 24 } 25 26 def memberWithRole(Relation r, String role) { 27 def RelationMember rm = r.getMembers().find {RelationMember rm -> rm.getRole() == role} 28 return rm.getMember() 29 } 30 31 def void assertEmptyTurnRestriction(Relation r){ 32 assert r != null 33 assert r.get("type") == "restriction" 34 assert r.getMembersCount() == 0 35 } 36 37 /** 38 * Selection consist of one way and the start node of the way -> 39 * propose a No-U-Turn restriction 40 * 41 */ 42 @Test 43 public void noUTurn_1() { 44 Way w = new Way(1) 45 Node n1 = new Node(1) 46 Node n2 = new Node(2) 47 w.setNodes([n1,n2]) 48 49 def sel = [w,n1] 50 TurnRestrictionBuilder builder = new TurnRestrictionBuilder() 51 Relation r = builder.build(sel) 52 53 assert r != null 54 assert r.getMembersCount() == 3 55 assert hasExactlyOneMemberWithRole(r, "from") 56 assert hasExactlyOneMemberWithRole(r, "to") 57 assert hasExactlyOneMemberWithRole(r, "via") 58 assert memberWithRole(r, "from") == w 59 assert memberWithRole(r, "to") == w 60 assert memberWithRole(r, "via") == n1 61 assert r.get("restriction") == "no_u_turn" 62 } 63 64 65 /** 66 * Selection consist of one way and the end node of the way -> 67 * propose a No-U-Turn restriction 68 * 69 */ 74 70 @Test 75 71 public void noUTurn_2() { 76 Way w = new Way(1)77 Node n1 = new Node(1)78 Node n2 = new Node(2)79 w.setNodes([n1,n2])80 81 def sel = [w,n2]82 TurnRestrictionBuilder builder = new TurnRestrictionBuilder()83 Relation r = builder.build(sel)84 85 assert r != null86 assert r.getMembersCount() == 387 assert hasExactlyOneMemberWithRole(r, "from")88 assert hasExactlyOneMemberWithRole(r, "to")89 assert hasExactlyOneMemberWithRole(r, "via")90 assert memberWithRole(r, "from") == w91 assert memberWithRole(r, "to") == w92 assert memberWithRole(r, "via") == n293 assert r.get("restriction") == "no_u_turn"94 } 95 72 Way w = new Way(1) 73 Node n1 = new Node(1) 74 Node n2 = new Node(2) 75 w.setNodes([n1,n2]) 76 77 def sel = [w,n2] 78 TurnRestrictionBuilder builder = new TurnRestrictionBuilder() 79 Relation r = builder.build(sel) 80 81 assert r != null 82 assert r.getMembersCount() == 3 83 assert hasExactlyOneMemberWithRole(r, "from") 84 assert hasExactlyOneMemberWithRole(r, "to") 85 assert hasExactlyOneMemberWithRole(r, "via") 86 assert memberWithRole(r, "from") == w 87 assert memberWithRole(r, "to") == w 88 assert memberWithRole(r, "via") == n2 89 assert r.get("restriction") == "no_u_turn" 90 } 91 96 92 @Test 97 93 public void nullSelection() { 98 def tr = builder.build(null)99 assertEmptyTurnRestriction(tr)100 } 101 94 def tr = builder.build(null) 95 assertEmptyTurnRestriction(tr) 96 } 97 102 98 @Test 103 99 public void emptySelection() { 104 def tr = builder.build([])105 assertEmptyTurnRestriction(tr)106 } 107 100 def tr = builder.build([]) 101 assertEmptyTurnRestriction(tr) 102 } 103 108 104 /** 109 105 * One selected way -> build a turn restriction with a "from" leg … … 112 108 @Test 113 109 public void oneSelectedWay() { 114 Way w = new Way(1)115 Relation tr = builder.build([w])116 assert tr != null117 assert tr.get("type") == "restriction"118 assert tr.getMembersCount() == 1119 assert memberWithRole(tr, "from") == w120 } 121 110 Way w = new Way(1) 111 Relation tr = builder.build([w]) 112 assert tr != null 113 assert tr.get("type") == "restriction" 114 assert tr.getMembersCount() == 1 115 assert memberWithRole(tr, "from") == w 116 } 117 122 118 /** 123 119 * Two unconnected ways in the selection. The first one becomes the from leg, … … 126 122 @Test 127 123 public void twoUnconnectedWays() { 128 Way w1 = new Way(1)129 w1.setNodes([new Node(11), new Node(12)])130 Way w2 = new Way(2)131 w2.setNodes([new Node(21), new Node(22)])132 133 Relation tr = builder.build([w1,w2])134 assert tr != null135 assert tr.get("type") == "restriction"136 assert ! tr.hasKey("restriction")137 assert tr.getMembersCount() == 2138 assert memberWithRole(tr, "from") == w1139 assert memberWithRole(tr, "to") == w2140 } 141 124 Way w1 = new Way(1) 125 w1.setNodes([new Node(11), new Node(12)]) 126 Way w2 = new Way(2) 127 w2.setNodes([new Node(21), new Node(22)]) 128 129 Relation tr = builder.build([w1,w2]) 130 assert tr != null 131 assert tr.get("type") == "restriction" 132 assert ! tr.hasKey("restriction") 133 assert tr.getMembersCount() == 2 134 assert memberWithRole(tr, "from") == w1 135 assert memberWithRole(tr, "to") == w2 136 } 137 142 138 /** 143 * Two connected ways. end node of the first way connects to start node of 144 * the second way. 145 * w2 139 * Two connected ways. end node of the first way connects to start node of 140 * the second way. 141 * w2 146 142 * --------> 147 * ^ 143 * ^ 148 144 * | w1 149 145 * | … … 151 147 @Test 152 148 public void twoConnectedWays_1() { 153 Node n1 = new Node(1)154 n1.setCoor(new LatLon(1,1))155 Node n2 = new Node(2)156 n2.setCoor(new LatLon(2,1))157 Node n3 = new Node(3)158 n3.setCoor(new LatLon(2,2))159 160 Way w1 = new Way(1)161 w1.setNodes([n1,n2])162 Way w2 = new Way(2)163 w2.setNodes([n2,n3])164 165 assert builder.phi(w1) == Math.toRadians(90)166 assert builder.phi(w2) == Math.toRadians(0)167 168 Relation tr = builder.build([w1,w2,n2])169 170 assert tr != null171 assert tr.get("type") == "restriction"172 assert tr.getMembersCount() == 3173 assert memberWithRole(tr, "from") == w1174 assert memberWithRole(tr, "to") == w2175 assert memberWithRole(tr, "via") == n2176 177 assert tr.get("restriction") == "no_right_turn"178 179 /*180 * opposite order, from w2 to w1. In this case we have left turn.181 */182 183 tr = builder.build([w2,w1,n2])184 185 double a = intersectionAngle(w2, w1)186 println "a=" + Math.toDegrees(a)187 188 assert tr != null189 assert tr.get("type") == "restriction"190 assert tr.getMembersCount() == 3191 assert memberWithRole(tr, "from") == w2192 assert memberWithRole(tr, "to") == w1193 assert memberWithRole(tr, "via") == n2194 195 assert tr.get("restriction") == "no_left_turn"196 } 197 149 Node n1 = new Node(1) 150 n1.setCoor(new LatLon(1,1)) 151 Node n2 = new Node(2) 152 n2.setCoor(new LatLon(2,1)) 153 Node n3 = new Node(3) 154 n3.setCoor(new LatLon(2,2)) 155 156 Way w1 = new Way(1) 157 w1.setNodes([n1,n2]) 158 Way w2 = new Way(2) 159 w2.setNodes([n2,n3]) 160 161 assert builder.phi(w1) == Math.toRadians(90) 162 assert builder.phi(w2) == Math.toRadians(0) 163 164 Relation tr = builder.build([w1,w2,n2]) 165 166 assert tr != null 167 assert tr.get("type") == "restriction" 168 assert tr.getMembersCount() == 3 169 assert memberWithRole(tr, "from") == w1 170 assert memberWithRole(tr, "to") == w2 171 assert memberWithRole(tr, "via") == n2 172 173 assert tr.get("restriction") == "no_right_turn" 174 175 /* 176 * opposite order, from w2 to w1. In this case we have left turn. 177 */ 178 179 tr = builder.build([w2,w1,n2]) 180 181 double a = intersectionAngle(w2, w1) 182 println "a=" + Math.toDegrees(a) 183 184 assert tr != null 185 assert tr.get("type") == "restriction" 186 assert tr.getMembersCount() == 3 187 assert memberWithRole(tr, "from") == w2 188 assert memberWithRole(tr, "to") == w1 189 assert memberWithRole(tr, "via") == n2 190 191 assert tr.get("restriction") == "no_left_turn" 192 } 193 198 194 /** 199 * Two connected ways. end node of the first way connects to end node of200 * the second way. left turn.201 * 202 * w2203 * (7,2) -------> (7,5)204 * ^205 * | w1206 * |207 * (5,5)208 */195 * Two connected ways. end node of the first way connects to end node of 196 * the second way. left turn. 197 * 198 * w2 199 * (7,2) -------> (7,5) 200 * ^ 201 * | w1 202 * | 203 * (5,5) 204 */ 209 205 @Test 210 206 public void twoConnectedWays_2() { 211 Node n1 = new Node(1)212 n1.setCoor(new LatLon(5,5))213 Node n2 = new Node(2)214 n2.setCoor(new LatLon(7,5))215 Node n3 = new Node(3)216 n3.setCoor(new LatLon(7,2))217 218 Way w1 = new Way(1)219 w1.setNodes([n1,n2])220 Way w2 = new Way(2)221 w2.setNodes([n3,n2])222 223 assert builder.phi(w1) == Math.toRadians(90)224 assert builder.phi(w2) == Math.toRadians(0)225 assert builder.phi(w2,true) == Math.toRadians(180)226 227 Relation tr = builder.build([w1,w2,n2])228 229 assert tr != null230 assert tr.get("type") == "restriction"231 assert tr.getMembersCount() == 3232 assert memberWithRole(tr, "from") == w1233 assert memberWithRole(tr, "to") == w2234 assert memberWithRole(tr, "via") == n2235 236 assert tr.get("restriction") == "no_left_turn"237 238 /*239 * opposite order, from w2 to w1. In this case we have right turn.240 */241 tr = builder.build([w2,w1,n2])242 243 assert tr != null244 assert tr.get("type") == "restriction"245 assert tr.getMembersCount() == 3246 assert memberWithRole(tr, "from") == w2247 assert memberWithRole(tr, "to") == w1248 assert memberWithRole(tr, "via") == n2249 assert tr.get("restriction") == "no_right_turn"250 } 251 207 Node n1 = new Node(1) 208 n1.setCoor(new LatLon(5,5)) 209 Node n2 = new Node(2) 210 n2.setCoor(new LatLon(7,5)) 211 Node n3 = new Node(3) 212 n3.setCoor(new LatLon(7,2)) 213 214 Way w1 = new Way(1) 215 w1.setNodes([n1,n2]) 216 Way w2 = new Way(2) 217 w2.setNodes([n3,n2]) 218 219 assert builder.phi(w1) == Math.toRadians(90) 220 assert builder.phi(w2) == Math.toRadians(0) 221 assert builder.phi(w2,true) == Math.toRadians(180) 222 223 Relation tr = builder.build([w1,w2,n2]) 224 225 assert tr != null 226 assert tr.get("type") == "restriction" 227 assert tr.getMembersCount() == 3 228 assert memberWithRole(tr, "from") == w1 229 assert memberWithRole(tr, "to") == w2 230 assert memberWithRole(tr, "via") == n2 231 232 assert tr.get("restriction") == "no_left_turn" 233 234 /* 235 * opposite order, from w2 to w1. In this case we have right turn. 236 */ 237 tr = builder.build([w2,w1,n2]) 238 239 assert tr != null 240 assert tr.get("type") == "restriction" 241 assert tr.getMembersCount() == 3 242 assert memberWithRole(tr, "from") == w2 243 assert memberWithRole(tr, "to") == w1 244 assert memberWithRole(tr, "via") == n2 245 assert tr.get("restriction") == "no_right_turn" 246 } 247 252 248 /** 253 249 * Two connected ways. end node of the first way connects to end node of 254 250 * the second way. left turn. 255 251 * 256 * 252 * 257 253 * (7,5) - 258 254 * ^ - w2 … … 263 259 @Test 264 260 public void twoConnectedWays_3() { 265 Node n1 = new Node(1)266 n1.setCoor(new LatLon(5,5))267 Node n2 = new Node(2)268 n2.setCoor(new LatLon(7,5))269 Node n3 = new Node(3)270 n3.setCoor(new LatLon(6,7))271 272 Way w1 = new Way(1)273 w1.setNodes([n1,n2])274 Way w2 = new Way(2)275 w2.setNodes([n2,n3])276 277 Relation tr = builder.build([w1,w2,n2])278 279 assert tr != null280 assert tr.get("type") == "restriction"281 assert tr.getMembersCount() == 3282 assert memberWithRole(tr, "from") == w1283 assert memberWithRole(tr, "to") == w2284 assert memberWithRole(tr, "via") == n2285 286 assert tr.get("restriction") == "no_right_turn"261 Node n1 = new Node(1) 262 n1.setCoor(new LatLon(5,5)) 263 Node n2 = new Node(2) 264 n2.setCoor(new LatLon(7,5)) 265 Node n3 = new Node(3) 266 n3.setCoor(new LatLon(6,7)) 267 268 Way w1 = new Way(1) 269 w1.setNodes([n1,n2]) 270 Way w2 = new Way(2) 271 w2.setNodes([n2,n3]) 272 273 Relation tr = builder.build([w1,w2,n2]) 274 275 assert tr != null 276 assert tr.get("type") == "restriction" 277 assert tr.getMembersCount() == 3 278 assert memberWithRole(tr, "from") == w1 279 assert memberWithRole(tr, "to") == w2 280 assert memberWithRole(tr, "via") == n2 281 282 assert tr.get("restriction") == "no_right_turn" 287 283 } 288 289 284 285 290 286 /** 291 287 * Two connected ways. end node of the first way connects to end node of 292 288 * the second way. left turn. 293 289 * 294 * 290 * 295 291 * (10,10) 296 * \ 297 * \ 292 * \ 293 * \ 298 294 * \ 299 * v 295 * v 300 296 * (8,15) 301 * / 297 * / 302 298 * / 303 299 * / … … 307 303 @Test 308 304 public void twoConnectedWays_4() { 309 Node n1 = new Node(1)310 n1.setCoor(new LatLon(10,10))311 Node n2 = new Node(2)312 n2.setCoor(new LatLon(8,15))313 Node n3 = new Node(3)314 n3.setCoor(new LatLon(5,11))315 316 Way w1 = new Way(1)317 w1.setNodes([n1,n2])318 Way w2 = new Way(2)319 w2.setNodes([n2,n3])320 321 Relation tr = builder.build([w1,w2,n2])322 323 assert tr != null324 assert tr.get("type") == "restriction"325 assert tr.getMembersCount() == 3326 assert memberWithRole(tr, "from") == w1327 assert memberWithRole(tr, "to") == w2328 assert memberWithRole(tr, "via") == n2329 330 assert tr.get("restriction") == "no_right_turn"331 332 333 /*334 * opposite order, from w2 to w1. In this case we have left turn.335 */336 tr = builder.build([w2,w1,n2])337 338 assert tr != null339 assert tr.get("type") == "restriction"340 assert tr.getMembersCount() == 3341 assert memberWithRole(tr, "from") == w2342 assert memberWithRole(tr, "to") == w1343 assert memberWithRole(tr, "via") == n2344 345 assert tr.get("restriction") == "no_left_turn"346 }347 348 305 Node n1 = new Node(1) 306 n1.setCoor(new LatLon(10,10)) 307 Node n2 = new Node(2) 308 n2.setCoor(new LatLon(8,15)) 309 Node n3 = new Node(3) 310 n3.setCoor(new LatLon(5,11)) 311 312 Way w1 = new Way(1) 313 w1.setNodes([n1,n2]) 314 Way w2 = new Way(2) 315 w2.setNodes([n2,n3]) 316 317 Relation tr = builder.build([w1,w2,n2]) 318 319 assert tr != null 320 assert tr.get("type") == "restriction" 321 assert tr.getMembersCount() == 3 322 assert memberWithRole(tr, "from") == w1 323 assert memberWithRole(tr, "to") == w2 324 assert memberWithRole(tr, "via") == n2 325 326 assert tr.get("restriction") == "no_right_turn" 327 328 329 /* 330 * opposite order, from w2 to w1. In this case we have left turn. 331 */ 332 tr = builder.build([w2,w1,n2]) 333 334 assert tr != null 335 assert tr.get("type") == "restriction" 336 assert tr.getMembersCount() == 3 337 assert memberWithRole(tr, "from") == w2 338 assert memberWithRole(tr, "to") == w1 339 assert memberWithRole(tr, "via") == n2 340 341 assert tr.get("restriction") == "no_left_turn" 342 } 343 344 349 345 def Node nn(id, lat, lon) { 350 Node n = new Node(id)351 n.setCoor(new LatLon(lat, lon))352 return n353 } 354 355 def Way nw(id, Node... nodes) {356 Way w = new Way(id)357 w.setNodes(Arrays.asList(nodes))358 return w359 }360 361 /**362 * n3363 * (10,10)364 * ^365 * | to366 * n1 from |367 * (5,5) --------------> (5,10) n2368 */369 @Test370 public void intersectionAngle_1() {371 Node n1 = nn(1,5,5)372 Node n2 = nn(2,5,10)373 Node n3 = nn(3,10,10)374 Way from = nw(1,n1,n2)375 Way to = nw(2,n2,n3)376 377 double a = TurnRestrictionBuilder.intersectionAngle(from, to)378 RelativeWayJoinOrientation o = TurnRestrictionBuilder.determineWayJoinOrientation(from,to)379 assert Math.toDegrees(a) == -90380 assert o == RelativeWayJoinOrientation.LEFT381 382 /*383 * if reversed from, the intersection angle is still -90�384 */385 from = nw(1,n2,n1)386 to = nw(2,n2,n3)387 a = TurnRestrictionBuilder.intersectionAngle(from, to)388 o = TurnRestrictionBuilder.determineWayJoinOrientation(from,to)389 assert Math.toDegrees(a) == -90390 assert o == RelativeWayJoinOrientation.LEFT391 392 /*393 * if reversed to, the intersection angle is still -90�394 */395 from = nw(1,n1,n2)396 to = nw(2,n3,n2)397 a = TurnRestrictionBuilder.intersectionAngle(from, to)398 o = TurnRestrictionBuilder.determineWayJoinOrientation(from,to)399 assert Math.toDegrees(a) == -90400 assert o == RelativeWayJoinOrientation.LEFT401 402 /*403 * if reversed both, the intersection angle is still -90�404 */405 from = nw(1,n2,n1)406 to = nw(2,n3,n2)407 a = TurnRestrictionBuilder.intersectionAngle(from, to)408 o = TurnRestrictionBuilder.determineWayJoinOrientation(from,to)409 assert Math.toDegrees(a) == -90410 assert o == RelativeWayJoinOrientation.LEFT411 }412 413 /**414 * n1 from415 * (5,5) --------------> (5,10) n2416 * |417 * | to418 * |419 * v420 * (2,10)421 * n3422 * 423 */424 @Test425 public void intersectionAngle_2() {426 Node n1 = nn(1,5,5)427 Node n2 = nn(2,5,10)428 Node n3 = nn(3,2,10)429 Way from = nw(1,n1,n2)430 Way to = nw(2,n2,n3)431 432 double a = TurnRestrictionBuilder.intersectionAngle(from, to)433 assert Math.toDegrees(a) == 90434 435 /*436 * if reversed from, the intersection angle is still 90�437 */438 from = nw(1,n2,n1)439 to = nw(2,n2,n3)440 a = TurnRestrictionBuilder.intersectionAngle(from, to)441 assert Math.toDegrees(a) == 90442 443 /*444 * if reversed to, the intersection angle is still 90�445 */446 from = nw(1,n1,n2)447 to = nw(2,n3,n2)448 a = TurnRestrictionBuilder.intersectionAngle(from, to)449 assert Math.toDegrees(a) == 90450 451 /*452 * if reversed both, the intersection angle is still 90�453 */454 from = nw(1,n2,n1)455 to = nw(2,n3,n2)456 a = TurnRestrictionBuilder.intersectionAngle(from, to)457 assert Math.toDegrees(a) == 90458 }459 460 461 /**462 * 463 * 464 * (-1,-6) (n3)465 * ^466 * /467 * / to468 * /469 * (-5, -10) n2346 Node n = new Node(id) 347 n.setCoor(new LatLon(lat, lon)) 348 return n 349 } 350 351 def Way nw(id, Node... nodes) { 352 Way w = new Way(id) 353 w.setNodes(Arrays.asList(nodes)) 354 return w 355 } 356 357 /** 358 * n3 359 * (10,10) 360 * ^ 361 * | to 362 * n1 from | 363 * (5,5) --------------> (5,10) n2 364 */ 365 @Test 366 public void intersectionAngle_1() { 367 Node n1 = nn(1,5,5) 368 Node n2 = nn(2,5,10) 369 Node n3 = nn(3,10,10) 370 Way from = nw(1,n1,n2) 371 Way to = nw(2,n2,n3) 372 373 double a = TurnRestrictionBuilder.intersectionAngle(from, to) 374 RelativeWayJoinOrientation o = TurnRestrictionBuilder.determineWayJoinOrientation(from,to) 375 assert Math.toDegrees(a) == -90 376 assert o == RelativeWayJoinOrientation.LEFT 377 378 /* 379 * if reversed from, the intersection angle is still -90� 380 */ 381 from = nw(1,n2,n1) 382 to = nw(2,n2,n3) 383 a = TurnRestrictionBuilder.intersectionAngle(from, to) 384 o = TurnRestrictionBuilder.determineWayJoinOrientation(from,to) 385 assert Math.toDegrees(a) == -90 386 assert o == RelativeWayJoinOrientation.LEFT 387 388 /* 389 * if reversed to, the intersection angle is still -90� 390 */ 391 from = nw(1,n1,n2) 392 to = nw(2,n3,n2) 393 a = TurnRestrictionBuilder.intersectionAngle(from, to) 394 o = TurnRestrictionBuilder.determineWayJoinOrientation(from,to) 395 assert Math.toDegrees(a) == -90 396 assert o == RelativeWayJoinOrientation.LEFT 397 398 /* 399 * if reversed both, the intersection angle is still -90� 400 */ 401 from = nw(1,n2,n1) 402 to = nw(2,n3,n2) 403 a = TurnRestrictionBuilder.intersectionAngle(from, to) 404 o = TurnRestrictionBuilder.determineWayJoinOrientation(from,to) 405 assert Math.toDegrees(a) == -90 406 assert o == RelativeWayJoinOrientation.LEFT 407 } 408 409 /** 410 * n1 from 411 * (5,5) --------------> (5,10) n2 412 * | 413 * | to 414 * | 415 * v 416 * (2,10) 417 * n3 418 * 419 */ 420 @Test 421 public void intersectionAngle_2() { 422 Node n1 = nn(1,5,5) 423 Node n2 = nn(2,5,10) 424 Node n3 = nn(3,2,10) 425 Way from = nw(1,n1,n2) 426 Way to = nw(2,n2,n3) 427 428 double a = TurnRestrictionBuilder.intersectionAngle(from, to) 429 assert Math.toDegrees(a) == 90 430 431 /* 432 * if reversed from, the intersection angle is still 90� 433 */ 434 from = nw(1,n2,n1) 435 to = nw(2,n2,n3) 436 a = TurnRestrictionBuilder.intersectionAngle(from, to) 437 assert Math.toDegrees(a) == 90 438 439 /* 440 * if reversed to, the intersection angle is still 90� 441 */ 442 from = nw(1,n1,n2) 443 to = nw(2,n3,n2) 444 a = TurnRestrictionBuilder.intersectionAngle(from, to) 445 assert Math.toDegrees(a) == 90 446 447 /* 448 * if reversed both, the intersection angle is still 90� 449 */ 450 from = nw(1,n2,n1) 451 to = nw(2,n3,n2) 452 a = TurnRestrictionBuilder.intersectionAngle(from, to) 453 assert Math.toDegrees(a) == 90 454 } 455 456 457 /** 458 * 459 * 460 * (-1,-6) (n3) 461 * ^ 462 * / 463 * / to 464 * / 465 * (-5, -10) n2 470 466 * ^ 471 * |472 * | from473 * |474 * (-10,-10) n1475 */467 * | 468 * | from 469 * | 470 * (-10,-10) n1 471 */ 476 472 @Test 477 473 public void intersectionAngle_3() { 478 Node n1 = nn(1,-10,-10)479 Node n2 = nn(2,-5,-10)480 Node n3 = nn(3,-1,-6)481 Way from = nw(1,n1,n2)482 Way to = nw(2,n2,n3)483 484 double a = TurnRestrictionBuilder.intersectionAngle(from, to)485 assert Math.toDegrees(a) == 45486 487 /*488 * if reversed from, the intersection angle is still 45489 */490 from = nw(1,n2,n1)491 to = nw(2,n2,n3)492 a = TurnRestrictionBuilder.intersectionAngle(from, to)493 assert Math.toDegrees(a) == 45494 495 /*496 * if reversed to, the intersection angle is still 45497 */498 from = nw(1,n1,n2)499 to = nw(2,n3,n2)500 a = TurnRestrictionBuilder.intersectionAngle(from, to)501 assert Math.toDegrees(a) == 45502 503 /*504 * if reversed both, the intersection angle is still 45505 */506 from = nw(1,n2,n1)507 to = nw(2,n3,n2)508 a = TurnRestrictionBuilder.intersectionAngle(from, to)509 assert Math.toDegrees(a) == 45510 } 511 474 Node n1 = nn(1,-10,-10) 475 Node n2 = nn(2,-5,-10) 476 Node n3 = nn(3,-1,-6) 477 Way from = nw(1,n1,n2) 478 Way to = nw(2,n2,n3) 479 480 double a = TurnRestrictionBuilder.intersectionAngle(from, to) 481 assert Math.toDegrees(a) == 45 482 483 /* 484 * if reversed from, the intersection angle is still 45 485 */ 486 from = nw(1,n2,n1) 487 to = nw(2,n2,n3) 488 a = TurnRestrictionBuilder.intersectionAngle(from, to) 489 assert Math.toDegrees(a) == 45 490 491 /* 492 * if reversed to, the intersection angle is still 45 493 */ 494 from = nw(1,n1,n2) 495 to = nw(2,n3,n2) 496 a = TurnRestrictionBuilder.intersectionAngle(from, to) 497 assert Math.toDegrees(a) == 45 498 499 /* 500 * if reversed both, the intersection angle is still 45 501 */ 502 from = nw(1,n2,n1) 503 to = nw(2,n3,n2) 504 a = TurnRestrictionBuilder.intersectionAngle(from, to) 505 assert Math.toDegrees(a) == 45 506 } 507 512 508 /** 513 509 * … … 527 523 @Test 528 524 public void intersectionAngle_4() { 529 Node n1 = nn(1,-10,-10)530 Node n2 = nn(2,-5,-10)531 Node n3 = nn(3,-1,-14)532 Way from = nw(1,n1,n2)533 Way to = nw(2,n2,n3)534 535 double a = TurnRestrictionBuilder.intersectionAngle(from, to)536 assert Math.toDegrees(a) == -45537 538 /*539 * if reversed from, the intersection angle is still -45540 */541 from = nw(1,n2,n1)542 to = nw(2,n2,n3)543 a = TurnRestrictionBuilder.intersectionAngle(from, to)544 assert Math.toDegrees(a) == -45545 546 /*547 * if reversed to, the intersection angle is still -45548 */549 from = nw(1,n1,n2)550 to = nw(2,n3,n2)551 a = TurnRestrictionBuilder.intersectionAngle(from, to)552 assert Math.toDegrees(a) == -45553 554 /*555 * if reversed both, the intersection angle is still 45556 */557 from = nw(1,n2,n1)558 to = nw(2,n3,n2)559 a = TurnRestrictionBuilder.intersectionAngle(from, to)560 assert Math.toDegrees(a) == -45525 Node n1 = nn(1,-10,-10) 526 Node n2 = nn(2,-5,-10) 527 Node n3 = nn(3,-1,-14) 528 Way from = nw(1,n1,n2) 529 Way to = nw(2,n2,n3) 530 531 double a = TurnRestrictionBuilder.intersectionAngle(from, to) 532 assert Math.toDegrees(a) == -45 533 534 /* 535 * if reversed from, the intersection angle is still -45 536 */ 537 from = nw(1,n2,n1) 538 to = nw(2,n2,n3) 539 a = TurnRestrictionBuilder.intersectionAngle(from, to) 540 assert Math.toDegrees(a) == -45 541 542 /* 543 * if reversed to, the intersection angle is still -45 544 */ 545 from = nw(1,n1,n2) 546 to = nw(2,n3,n2) 547 a = TurnRestrictionBuilder.intersectionAngle(from, to) 548 assert Math.toDegrees(a) == -45 549 550 /* 551 * if reversed both, the intersection angle is still 45 552 */ 553 from = nw(1,n2,n1) 554 to = nw(2,n3,n2) 555 a = TurnRestrictionBuilder.intersectionAngle(from, to) 556 assert Math.toDegrees(a) == -45 561 557 } 562 563 564 /*565 *566 * n21 w21 n22 w22 n23567 * (10,10)-------------> (10,15) -------------- > (10,20)568 * ^569 * |570 * | w1571 * |572 * (5,15)573 * n11574 */575 @Test576 public void splitToWay() {577 Node n11 = new Node(11);578 n11.setCoor(new LatLon(5,15));579 580 Node n21 = new Node(21)581 n21.setCoor(new LatLon(10,10))582 Node n22 = new Node(22)583 n22.setCoor(new LatLon(10,15))584 Node n23 = new Node(23)585 n23.setCoor(new LatLon(10,20))586 587 Way w1 = new Way(1)588 w1.setNodes([n11,n22])589 Way w21 = new Way(21)590 w21.setNodes([n21,n22])591 Way w22 = new Way(22)592 w22.setNodes([n22,n23])593 594 Way adjustedTo = selectToWayAfterSplit(595 w1,596 w21,597 w22,598 TurnRestrictionType.NO_LEFT_TURN599 )600 601 assert adjustedTo != null602 assert adjustedTo == w21603 604 adjustedTo = selectToWayAfterSplit(605 w1,606 w21,607 w22,608 TurnRestrictionType.NO_RIGHT_TURN609 )610 611 assert adjustedTo != null612 assert adjustedTo == w22613 614 adjustedTo = selectToWayAfterSplit(615 w1,616 w21,617 w22,618 TurnRestrictionType.ONLY_LEFT_TURN619 )620 621 assert adjustedTo != null622 assert adjustedTo == w21623 624 adjustedTo = selectToWayAfterSplit(625 w1,626 w21,627 w22,628 TurnRestrictionType.ONLY_RIGHT_TURN629 )630 631 assert adjustedTo != null632 assert adjustedTo == w22633 634 adjustedTo = selectToWayAfterSplit(635 w1,636 w21,637 w22,638 TurnRestrictionType.NO_STRAIGHT_ON639 )640 641 assert adjustedTo == null642 } 558 559 560 /* 561 * 562 * n21 w21 n22 w22 n23 563 * (10,10)-------------> (10,15) -------------- > (10,20) 564 * ^ 565 * | 566 * | w1 567 * | 568 * (5,15) 569 * n11 570 */ 571 @Test 572 public void splitToWay() { 573 Node n11 = new Node(11); 574 n11.setCoor(new LatLon(5,15)); 575 576 Node n21 = new Node(21) 577 n21.setCoor(new LatLon(10,10)) 578 Node n22 = new Node(22) 579 n22.setCoor(new LatLon(10,15)) 580 Node n23 = new Node(23) 581 n23.setCoor(new LatLon(10,20)) 582 583 Way w1 = new Way(1) 584 w1.setNodes([n11,n22]) 585 Way w21 = new Way(21) 586 w21.setNodes([n21,n22]) 587 Way w22 = new Way(22) 588 w22.setNodes([n22,n23]) 589 590 Way adjustedTo = selectToWayAfterSplit( 591 w1, 592 w21, 593 w22, 594 TurnRestrictionType.NO_LEFT_TURN 595 ) 596 597 assert adjustedTo != null 598 assert adjustedTo == w21 599 600 adjustedTo = selectToWayAfterSplit( 601 w1, 602 w21, 603 w22, 604 TurnRestrictionType.NO_RIGHT_TURN 605 ) 606 607 assert adjustedTo != null 608 assert adjustedTo == w22 609 610 adjustedTo = selectToWayAfterSplit( 611 w1, 612 w21, 613 w22, 614 TurnRestrictionType.ONLY_LEFT_TURN 615 ) 616 617 assert adjustedTo != null 618 assert adjustedTo == w21 619 620 adjustedTo = selectToWayAfterSplit( 621 w1, 622 w21, 623 w22, 624 TurnRestrictionType.ONLY_RIGHT_TURN 625 ) 626 627 assert adjustedTo != null 628 assert adjustedTo == w22 629 630 adjustedTo = selectToWayAfterSplit( 631 w1, 632 w21, 633 w22, 634 TurnRestrictionType.NO_STRAIGHT_ON 635 ) 636 637 assert adjustedTo == null 638 } 643 639 } -
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/ExceptValueModelTest.groovy
r23571 r32409 1 1 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 2 3 import org.junit. *;4 import static org.junit.Assert.*; 5 import org. openstreetmap.josm.plugins.turnrestrictions.editor.ExceptValueModel;3 import static org.junit.Assert.* 4 5 import org.junit.* 6 6 7 7 class ExceptValueModelTest { 8 8 9 @Test 10 public void constructor() { 11 new ExceptValueModel() 12 13 def evm = new ExceptValueModel(null) 14 evm = new ExceptValueModel("") 15 evm = new ExceptValueModel(" ") 16 evm = new ExceptValueModel("hgv") 17 evm = new ExceptValueModel("hgv;psv") 18 evm = new ExceptValueModel("non_standard") 19 } 20 21 @Test 22 public void setValue() { 23 def evm 24 25 // null value allowed - means no vehicle exceptions 26 evm = new ExceptValueModel() 27 evm.setValue(null) 28 assert evm.getValue() == "" 29 assert evm.isStandard() 30 31 // empty string allowed - means no vehicle expections 32 evm = new ExceptValueModel() 33 evm.setValue("") 34 assert evm.getValue() == "" 35 assert evm.isStandard() 9 @Test 10 public void constructor() { 11 new ExceptValueModel() 36 12 37 // a single standard vehicle exeption 38 evm = new ExceptValueModel()39 evm.setValue("hgv")40 assert evm.getValue() == "hgv" 41 assert evm.isVehicleException("hgv")42 assert ! evm.isVehicleException("psv")43 assert evm.isStandard() 13 def evm = new ExceptValueModel(null) 14 evm = new ExceptValueModel("") 15 evm = new ExceptValueModel(" ") 16 evm = new ExceptValueModel("hgv") 17 evm = new ExceptValueModel("hgv;psv") 18 evm = new ExceptValueModel("non_standard") 19 } 44 20 45 // two standard vehicle exceptions 46 evm = new ExceptValueModel() 47 evm.setValue("hgv;psv") 48 assert evm.getValue() == "hgv;psv" 49 assert evm.isVehicleException("hgv") 50 assert evm.isVehicleException("psv") 51 assert evm.isStandard() 52 53 // white space and lowercase/uppercase mix allowed. Should be normalized 54 // by the except value model 55 evm = new ExceptValueModel() 56 evm.setValue(" hGv ; PsV ") 57 assert evm.getValue() == "hgv;psv" 58 assert evm.isVehicleException("hgv") 59 assert evm.isVehicleException("psv") 60 assert evm.isStandard() 61 62 // non standard value allowed 63 evm = new ExceptValueModel() 64 evm.setValue("Non Standard") 65 assert evm.getValue() == "Non Standard" 66 assert !evm.isVehicleException("hgv") 67 assert !evm.isVehicleException("psv") 68 assert !evm.isStandard() 69 } 21 @Test 22 public void setValue() { 23 def evm 24 25 // null value allowed - means no vehicle exceptions 26 evm = new ExceptValueModel() 27 evm.setValue(null) 28 assert evm.getValue() == "" 29 assert evm.isStandard() 30 31 // empty string allowed - means no vehicle expections 32 evm = new ExceptValueModel() 33 evm.setValue("") 34 assert evm.getValue() == "" 35 assert evm.isStandard() 36 37 // a single standard vehicle exeption 38 evm = new ExceptValueModel() 39 evm.setValue("hgv") 40 assert evm.getValue() == "hgv" 41 assert evm.isVehicleException("hgv") 42 assert ! evm.isVehicleException("psv") 43 assert evm.isStandard() 44 45 // two standard vehicle exceptions 46 evm = new ExceptValueModel() 47 evm.setValue("hgv;psv") 48 assert evm.getValue() == "hgv;psv" 49 assert evm.isVehicleException("hgv") 50 assert evm.isVehicleException("psv") 51 assert evm.isStandard() 52 53 // white space and lowercase/uppercase mix allowed. Should be normalized 54 // by the except value model 55 evm = new ExceptValueModel() 56 evm.setValue(" hGv ; PsV ") 57 assert evm.getValue() == "hgv;psv" 58 assert evm.isVehicleException("hgv") 59 assert evm.isVehicleException("psv") 60 assert evm.isStandard() 61 62 // non standard value allowed 63 evm = new ExceptValueModel() 64 evm.setValue("Non Standard") 65 assert evm.getValue() == "Non Standard" 66 assert !evm.isVehicleException("hgv") 67 assert !evm.isVehicleException("psv") 68 assert !evm.isStandard() 69 } 70 70 } -
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModelTest.groovy
r32377 r32409 1 1 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 2 3 import static groovy.test.GroovyAssert.shouldFail 3 4 import static org.junit.Assert.* 4 5 … … 15 16 * Unit test for {@see JosmSelctionListModel} 16 17 */ 17 class JosmSelectionListModelTest extends GroovyTestCase{18 class JosmSelectionListModelTest { 18 19 19 20 @Rule 20 21 public JOSMTestRules rules = new JOSMTestRules().preferences(); 21 22 22 final shouldFail = new GroovyTestCase().&shouldFail 23 @Test 24 public void test_Constructor(){ 25 DataSet ds = new DataSet() 26 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 27 JosmSelectionListModel model = new JosmSelectionListModel(layer); 23 28 24 @Test 25 public void test_Constructor(){ 26 DataSet ds = new DataSet() 27 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 28 JosmSelectionListModel model = new JosmSelectionListModel(layer); 29 shouldFail(IllegalArgumentException){ 30 model = new JosmSelectionListModel(null) 31 } 32 } 29 33 30 shouldFail(IllegalArgumentException){ 31 model = new JosmSelectionListModel(null) 32 } 33 } 34 @Test 35 public void test_setJOSMSelection() { 36 DataSet ds = new DataSet() 37 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 38 JosmSelectionListModel model = new JosmSelectionListModel(layer); 34 39 35 @Test 36 public void test_setJOSMSelection() { 37 DataSet ds = new DataSet() 38 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 39 JosmSelectionListModel model = new JosmSelectionListModel(layer); 40 // set a selection with three objects 41 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()] 42 model.setJOSMSelection objects 43 assert model.getSize() == 3 40 44 41 // set a selection with three objects 42 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()] 43 model.setJOSMSelection objects 44 assert model.getSize() == 345 // null is allowed 46 model.setJOSMSelection(null) 47 assert model.getSize() == 0 48 assert model.getSelected().isEmpty() 45 49 46 // null is allowed 47 model.setJOSMSelection(null) 48 assert model.getSize() == 0 49 assert model.getSelected().isEmpty() 50 // empty has the same effect 51 model.setJOSMSelection([]) 52 assert model.getSize() == 0 53 assert model.getSelected().isEmpty() 54 } 50 55 51 // empty has the same effect 52 model.setJOSMSelection([]) 53 assert model.getSize() == 0 54 assert model.getSelected().isEmpty() 55 } 56 57 @Test 58 public void test_setJOSMSelection_withSelected() { 59 DataSet ds = new DataSet() 60 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 61 JosmSelectionListModel model = new JosmSelectionListModel(layer); 62 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()] 63 model.setJOSMSelection(objects) 64 model.setSelected(objects[0..1]) 65 assert model.getSelected().asList() as Set == objects[0..1] as Set 56 @Test 57 public void test_setJOSMSelection_withSelected() { 58 DataSet ds = new DataSet() 59 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 60 JosmSelectionListModel model = new JosmSelectionListModel(layer); 61 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()] 62 model.setJOSMSelection(objects) 63 model.setSelected(objects[0..1]) 64 assert model.getSelected().asList() as Set == objects[0..1] as Set 66 65 67 66 // set new selection which includes one object which is currently 68 67 // selected in the model. Should still be selected after setting 69 68 // the new JOSM selection 70 objects = objects[1..2]71 model.setJOSMSelection(objects)72 assert model.getSelected().asList() == [objects[0]]73 }69 objects = objects[1..2] 70 model.setJOSMSelection(objects) 71 assert model.getSelected().asList() == [objects[0]] 72 } 74 73 75 @Test76 public void test_getSelected() {77 DataSet ds = new DataSet()78 OsmDataLayer layer = new OsmDataLayer(ds, "test", null)74 @Test 75 public void test_getSelected() { 76 DataSet ds = new DataSet() 77 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 79 78 80 JosmSelectionListModel model = new JosmSelectionListModel(layer);81 DefaultListSelectionModel selectionModel = model.getListSelectionModel()79 JosmSelectionListModel model = new JosmSelectionListModel(layer); 80 DefaultListSelectionModel selectionModel = model.getListSelectionModel() 82 81 83 assert model.getSelected() != null84 assert model.getSelected().isEmpty()82 assert model.getSelected() != null 83 assert model.getSelected().isEmpty() 85 84 86 // select one element87 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]88 model.setJOSMSelection(objects)89 selectionModel.setSelectionInterval(0, 0)90 assert model.getSelected().asList() == [model.getElementAt(0)];85 // select one element 86 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()] 87 model.setJOSMSelection(objects) 88 selectionModel.setSelectionInterval(0, 0) 89 assert model.getSelected().asList() == [model.getElementAt(0)]; 91 90 92 // select two elements93 selectionModel.setSelectionInterval(1,2)94 assert model.getSelected().asList() as Set == [model.getElementAt(1),model.getElementAt(2)] as Set;95 }91 // select two elements 92 selectionModel.setSelectionInterval(1,2) 93 assert model.getSelected().asList() as Set == [model.getElementAt(1),model.getElementAt(2)] as Set; 94 } 96 95 97 @Test98 public void test_setSelected() {99 DataSet ds = new DataSet()100 OsmDataLayer layer = new OsmDataLayer(ds, "test", null)96 @Test 97 public void test_setSelected() { 98 DataSet ds = new DataSet() 99 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 101 100 102 // set selected with null is OK - nothing selected thereafter103 JosmSelectionListModel model = new JosmSelectionListModel(layer);104 DefaultListSelectionModel selectionModel = model.getListSelectionModel()105 model.setSelected(null)106 assert model.getSelected().isEmpty()101 // set selected with null is OK - nothing selected thereafter 102 JosmSelectionListModel model = new JosmSelectionListModel(layer); 103 DefaultListSelectionModel selectionModel = model.getListSelectionModel() 104 model.setSelected(null) 105 assert model.getSelected().isEmpty() 107 106 108 // set selected with empty list is OK - nothing selected thereafter109 model.setSelected([])110 assert model.getSelected().isEmpty()107 // set selected with empty list is OK - nothing selected thereafter 108 model.setSelected([]) 109 assert model.getSelected().isEmpty() 111 110 112 // select an object existing in the list of displayed objects113 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]114 model.setJOSMSelection(objects)115 model.setSelected([objects[0]])116 assert model.getSelected().asList() == [objects[0]];111 // select an object existing in the list of displayed objects 112 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()] 113 model.setJOSMSelection(objects) 114 model.setSelected([objects[0]]) 115 assert model.getSelected().asList() == [objects[0]]; 117 116 118 // select an object not-existing in the list of displayed objects119 model.setJOSMSelection(objects)120 model.setSelected([new Way()])121 assert model.getSelected().isEmpty()122 }117 // select an object not-existing in the list of displayed objects 118 model.setJOSMSelection(objects) 119 model.setSelected([new Way()]) 120 assert model.getSelected().isEmpty() 121 } 123 122 124 @Test125 public void test_editLayerChanged() {126 DataSet ds = new DataSet()123 @Test 124 public void test_editLayerChanged() { 125 DataSet ds = new DataSet() 127 126 128 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]129 objects.each {ds.addPrimitive(it)}127 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()] 128 objects.each {ds.addPrimitive(it)} 130 129 131 OsmDataLayer layer1 = new OsmDataLayer(ds,"layer1", null)132 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(),"layer2", null)130 OsmDataLayer layer1 = new OsmDataLayer(ds,"layer1", null) 131 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(),"layer2", null) 133 132 134 133 Main.getLayerManager().addLayer(layer1) 135 134 Main.getLayerManager().addLayer(layer2) 136 135 137 JosmSelectionListModel model = new JosmSelectionListModel(layer1);138 DefaultListSelectionModel selectionModel = model.getListSelectionModel()139 // switch from edit layer1 to edit layer2. content of the JOSM selection140 // should be empty thereafter136 JosmSelectionListModel model = new JosmSelectionListModel(layer1); 137 DefaultListSelectionModel selectionModel = model.getListSelectionModel() 138 // switch from edit layer1 to edit layer2. content of the JOSM selection 139 // should be empty thereafter 141 140 Main.getLayerManager().setActiveLayer(layer1) 142 141 Main.getLayerManager().setActiveLayer(layer2) 143 assert model.getSize() == 0142 assert model.getSize() == 0 144 143 145 // switch from layer2 to layer1 which has one object selected. Object should146 // be displayed in the JOSM selection list147 ds.setSelected([objects[0]])144 // switch from layer2 to layer1 which has one object selected. Object should 145 // be displayed in the JOSM selection list 146 ds.setSelected([objects[0]]) 148 147 Main.getLayerManager().setActiveLayer(layer1) 149 assert model.getSize() == 1150 assert model.getElementAt(0) == objects[0];148 assert model.getSize() == 1 149 assert model.getElementAt(0) == objects[0]; 151 150 152 // switch to a "null" edit layer (i.e. no edit layer)- nothing should153 // be displayed in the selection list151 // switch to a "null" edit layer (i.e. no edit layer)- nothing should 152 // be displayed in the selection list 154 153 Main.getLayerManager().removeLayer(layer2) 155 154 Main.getLayerManager().removeLayer(layer1) 156 assert model.getSize() == 0157 }155 assert model.getSize() == 0 156 } 158 157 } -
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorModelUnitTest.groovy
r32363 r32409 1 1 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 import groovy.util.GroovyTestCase; 3 4 import static org.junit.Assert.*; 5 import org.junit.*; 2 import static groovy.test.GroovyAssert.shouldFail 3 import static org.junit.Assert.* 6 4 import static org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionLegRole.* 7 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 8 import org.openstreetmap.josm.data.osm.Relation 9 import org.openstreetmap.josm.data.osm.RelationMember 10 import org.openstreetmap.josm.data.osm.Node 11 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 12 import org.openstreetmap.josm.data.osm.Way 13 import org.openstreetmap.josm.data.osm.DataSet 5 6 import org.junit.* 14 7 import org.openstreetmap.josm.data.coor.* 15 import org.openstreetmap.josm. fixtures.JOSMFixture;8 import org.openstreetmap.josm.data.osm.* 16 9 import org.openstreetmap.josm.gui.layer.OsmDataLayer 17 import org.openstreetmap.josm.testutils.JOSMTestRules; 18 import org.openstreetmap.josm.JOSMFixture; 10 import org.openstreetmap.josm.testutils.JOSMTestRules 19 11 20 12 /** 21 13 * This is a unit test for {@link TurnRestrictionEditorModel} 22 *23 14 */ 24 class TurnRestrictionEditorModelUnitTest extends GroovyTestCase{ 25 26 final shouldFail = new GroovyTestCase().&shouldFail 15 class TurnRestrictionEditorModelUnitTest { 27 16 28 17 @Rule 29 18 public JOSMTestRules rules = new JOSMTestRules().preferences(); 30 19 31 def navigationControlerMock = [32 gotoBasicEditor:{}, 20 def navigationControlerMock = [ 21 gotoBasicEditor:{}, 33 22 gotoAdvancedEditor: {} 34 ] as NavigationControler35 36 private DataSet ds37 private OsmDataLayer layer38 private TurnRestrictionEditorModel model39 40 def createNode(id = null, coor = null) {41 Node n42 if (id == null){43 n = new Node()44 } else {45 n = new Node(id)46 }47 if (coor != null) n.setCoor(coor)48 ds.addPrimitive(n)49 return n50 }51 52 def createWay(id=null) {53 Way w54 if (id == null){55 w = new Way()56 } else {57 w = new Way(id)58 }59 ds.addPrimitive(w)60 return w61 }62 63 def node(id){64 return ds.getPrimitiveById(new SimplePrimitiveId(id, OsmPrimitiveType.NODE))65 }66 67 def way(id) {68 return ds.getPrimitiveById(new SimplePrimitiveId(id, OsmPrimitiveType.WAY))69 }70 71 def rel(id){72 return ds.getPrimitiveById(new SimplePrimitiveId(id, OsmPrimitiveType.RELATION))73 }74 75 def rm(role,object){76 return new RelationMember(role, object);77 }78 79 def buildDataSet1() {80 // prepare some nodes and ways81 createNode(21)82 createNode(22)83 createNode(31)84 createNode(32)85 createWay(2)86 createWay(3)87 88 way(2).setNodes([node(21), node(22)])89 way(3).setNodes([node(22), node(31)])90 91 // a standard turn restriction with a from, a to and a via92 Relation r = new Relation(1)93 r.setMembers([rm("from", way(2)), rm("to", way(3)), rm("via", node(22))])94 r.put "type", "restriction"95 r.put "restriction", "no_left_turn"96 ds.addPrimitive r97 }98 99 @Before100 public void setUp() {101 ds = new DataSet()102 layer = new OsmDataLayer(ds, "test", null)103 model = new TurnRestrictionEditorModel(layer, navigationControlerMock);104 }105 106 /**107 * Test the constructor108 */109 @Test110 public void test_Constructor() {111 shouldFail(IllegalArgumentException){112 model = new TurnRestrictionEditorModel(null, navigationControlerMock);113 }114 115 shouldFail(IllegalArgumentException){116 model = new TurnRestrictionEditorModel(layer, null);117 }118 }119 120 @Test121 public void test_populate_EmptyTurnRestriction() {122 // an "empty" turn restriction with a public id123 Relation r = new Relation(1)124 ds.addPrimitive r125 assert model.getTurnRestrictionLeg(FROM).isEmpty()126 assert model.getTurnRestrictionLeg(TO).isEmpty()127 assert model.getVias().isEmpty()128 assert model.getRestrictionTagValue() == ""129 assert model.getExcept().getValue() == ""130 }131 132 /**133 * Populating the model with a simple default turn restriction: one from member (a way),134 * one to member (a way), one via (the common node of these ways), minimal tag set with135 * type=restriction and restriction=no_left_turn136 * 137 */138 @Test139 public void test_populate_SimpleStandardTurnRestriction() {140 buildDataSet1()141 model.populate(rel(1))142 143 assert model.getTurnRestrictionLeg(FROM).asList() == [way(2)]144 assert model.getTurnRestrictionLeg(TO).asList() == [way(3)]145 assert model.getVias() == [node(22)]146 assert model.getRestrictionTagValue() == "no_left_turn"147 assert model.getExcept().getValue() == ""148 }149 150 @Test151 public void setFrom() {152 buildDataSet1()153 model.populate(rel(1))154 155 createNode(41)156 createNode(42)157 createWay(4).setNodes([node(41),node(42)]);158 159 // set another way as from160 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, way(4).getPrimitiveId())161 assert model.getTurnRestrictionLeg(TurnRestrictionLegRole.FROM).asList() == [way(4)];162 163 // delete the/all members with role 'from'164 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, null)165 assert model.getTurnRestrictionLeg(TurnRestrictionLegRole.FROM).isEmpty()166 167 168 shouldFail(IllegalArgumentException) {169 // can't add a node as 'from'170 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, node(21).getPrimitiveId())171 }172 173 shouldFail(IllegalStateException) {174 // can't set a way as 'from' if it isn't part of the dataset175 Way way = new Way()176 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, way.getPrimitiveId())177 }178 }179 180 @Test181 public void setTo() {182 buildDataSet1()183 model.populate(rel(1))184 185 createNode(41)186 createNode(42)187 createWay(4).setNodes([node(41),node(42)]);188 189 // set another way as from190 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, way(4).getPrimitiveId())191 assert model.getTurnRestrictionLeg(TurnRestrictionLegRole.TO).asList() == [way(4)];192 193 // delete the/all members with role 'from'194 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, null)195 assert model.getTurnRestrictionLeg(TurnRestrictionLegRole.TO).isEmpty()196 197 198 shouldFail(IllegalArgumentException) {199 // can't add a node as 'from'200 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, node(21).getPrimitiveId())201 }202 203 shouldFail(IllegalStateException) {204 // can't set a way as 'from' if it isn't part of the dataset205 Way way = new Way()206 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, way.getPrimitiveId())207 }208 }209 210 /**211 * Test setting or deleting the tag 'restriction'212 */213 @Test214 public void setRestrictionTagValue() {215 buildDataSet1()216 model.populate(rel(1))217 218 model.setRestrictionTagValue("no_left_turn")219 assert model.getRestrictionTagValue() == "no_left_turn";220 221 model.setRestrictionTagValue(null)222 assert model.getRestrictionTagValue() == "";223 224 model.setRestrictionTagValue(" ")225 assert model.getRestrictionTagValue() == "";226 227 model.setRestrictionTagValue(" no_right_Turn ")228 assert model.getRestrictionTagValue() == "no_right_turn";229 }230 231 /**232 * Test setting vias233 */234 @Test235 public void setVias() {236 buildDataSet1()237 model.populate(rel(1))238 239 // one node as via - OK240 model.setVias([node(22)])241 assert model.getVias() == [node(22)];242 243 // pass in null as vias -> remove all vias244 model.setVias(null)245 assert model.getVias().isEmpty()246 247 // pass in empty list -> remove all vias248 model.setVias([])249 assert model.getVias().isEmpty()250 251 // create a list of vias with a way and twice a node (which doesn't252 // make sense but is technically allowed)253 //254 createNode(41)255 createNode(42)256 createWay(4).setNodes([node(41), node(42)])257 model.setVias([way(4), node(22), node(22)])258 assert model.getVias() == [way(4), node(22), node(22)];259 260 // null values in the list of vias are skipped 23 ] as NavigationControler 24 25 private DataSet ds 26 private OsmDataLayer layer 27 private TurnRestrictionEditorModel model 28 29 def createNode(id = null, coor = null) { 30 Node n 31 if (id == null){ 32 n = new Node() 33 } else { 34 n = new Node(id) 35 } 36 if (coor != null) n.setCoor(coor) 37 ds.addPrimitive(n) 38 return n 39 } 40 41 def createWay(id=null) { 42 Way w 43 if (id == null){ 44 w = new Way() 45 } else { 46 w = new Way(id) 47 } 48 ds.addPrimitive(w) 49 return w 50 } 51 52 def node(id){ 53 return ds.getPrimitiveById(new SimplePrimitiveId(id, OsmPrimitiveType.NODE)) 54 } 55 56 def way(id) { 57 return ds.getPrimitiveById(new SimplePrimitiveId(id, OsmPrimitiveType.WAY)) 58 } 59 60 def rel(id){ 61 return ds.getPrimitiveById(new SimplePrimitiveId(id, OsmPrimitiveType.RELATION)) 62 } 63 64 def rm(role,object){ 65 return new RelationMember(role, object); 66 } 67 68 def buildDataSet1() { 69 // prepare some nodes and ways 70 createNode(21) 71 createNode(22) 72 createNode(31) 73 createNode(32) 74 createWay(2) 75 createWay(3) 76 77 way(2).setNodes([node(21), node(22)]) 78 way(3).setNodes([node(22), node(31)]) 79 80 // a standard turn restriction with a from, a to and a via 81 Relation r = new Relation(1) 82 r.setMembers([rm("from", way(2)), rm("to", way(3)), rm("via", node(22))]) 83 r.put "type", "restriction" 84 r.put "restriction", "no_left_turn" 85 ds.addPrimitive r 86 } 87 88 @Before 89 public void setUp() { 90 ds = new DataSet() 91 layer = new OsmDataLayer(ds, "test", null) 92 model = new TurnRestrictionEditorModel(layer, navigationControlerMock); 93 } 94 95 /** 96 * Test the constructor 97 */ 98 @Test 99 public void test_Constructor() { 100 shouldFail(IllegalArgumentException){ 101 model = new TurnRestrictionEditorModel(null, navigationControlerMock); 102 } 103 104 shouldFail(IllegalArgumentException){ 105 model = new TurnRestrictionEditorModel(layer, null); 106 } 107 } 108 109 @Test 110 public void test_populate_EmptyTurnRestriction() { 111 // an "empty" turn restriction with a public id 112 Relation r = new Relation(1) 113 ds.addPrimitive r 114 assert model.getTurnRestrictionLeg(FROM).isEmpty() 115 assert model.getTurnRestrictionLeg(TO).isEmpty() 116 assert model.getVias().isEmpty() 117 assert model.getRestrictionTagValue() == "" 118 assert model.getExcept().getValue() == "" 119 } 120 121 /** 122 * Populating the model with a simple default turn restriction: one from member (a way), 123 * one to member (a way), one via (the common node of these ways), minimal tag set with 124 * type=restriction and restriction=no_left_turn 125 * 126 */ 127 @Test 128 public void test_populate_SimpleStandardTurnRestriction() { 129 buildDataSet1() 130 model.populate(rel(1)) 131 132 assert model.getTurnRestrictionLeg(FROM).asList() == [way(2)] 133 assert model.getTurnRestrictionLeg(TO).asList() == [way(3)] 134 assert model.getVias() == [node(22)] 135 assert model.getRestrictionTagValue() == "no_left_turn" 136 assert model.getExcept().getValue() == "" 137 } 138 139 @Test 140 public void setFrom() { 141 buildDataSet1() 142 model.populate(rel(1)) 143 144 createNode(41) 145 createNode(42) 146 createWay(4).setNodes([node(41),node(42)]); 147 148 // set another way as from 149 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, way(4).getPrimitiveId()) 150 assert model.getTurnRestrictionLeg(TurnRestrictionLegRole.FROM).asList() == [way(4)]; 151 152 // delete the/all members with role 'from' 153 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, null) 154 assert model.getTurnRestrictionLeg(TurnRestrictionLegRole.FROM).isEmpty() 155 156 157 shouldFail(IllegalArgumentException) { 158 // can't add a node as 'from' 159 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, node(21).getPrimitiveId()) 160 } 161 162 shouldFail(IllegalStateException) { 163 // can't set a way as 'from' if it isn't part of the dataset 164 Way way = new Way() 165 model.setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, way.getPrimitiveId()) 166 } 167 } 168 169 @Test 170 public void setTo() { 171 buildDataSet1() 172 model.populate(rel(1)) 173 174 createNode(41) 175 createNode(42) 176 createWay(4).setNodes([node(41),node(42)]); 177 178 // set another way as from 179 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, way(4).getPrimitiveId()) 180 assert model.getTurnRestrictionLeg(TurnRestrictionLegRole.TO).asList() == [way(4)]; 181 182 // delete the/all members with role 'from' 183 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, null) 184 assert model.getTurnRestrictionLeg(TurnRestrictionLegRole.TO).isEmpty() 185 186 187 shouldFail(IllegalArgumentException) { 188 // can't add a node as 'from' 189 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, node(21).getPrimitiveId()) 190 } 191 192 shouldFail(IllegalStateException) { 193 // can't set a way as 'from' if it isn't part of the dataset 194 Way way = new Way() 195 model.setTurnRestrictionLeg(TurnRestrictionLegRole.TO, way.getPrimitiveId()) 196 } 197 } 198 199 /** 200 * Test setting or deleting the tag 'restriction' 201 */ 202 @Test 203 public void setRestrictionTagValue() { 204 buildDataSet1() 205 model.populate(rel(1)) 206 207 model.setRestrictionTagValue("no_left_turn") 208 assert model.getRestrictionTagValue() == "no_left_turn"; 209 210 model.setRestrictionTagValue(null) 211 assert model.getRestrictionTagValue() == ""; 212 213 model.setRestrictionTagValue(" ") 214 assert model.getRestrictionTagValue() == ""; 215 216 model.setRestrictionTagValue(" no_right_Turn ") 217 assert model.getRestrictionTagValue() == "no_right_turn"; 218 } 219 220 /** 221 * Test setting vias 222 */ 223 @Test 224 public void setVias() { 225 buildDataSet1() 226 model.populate(rel(1)) 227 228 // one node as via - OK 229 model.setVias([node(22)]) 230 assert model.getVias() == [node(22)]; 231 232 // pass in null as vias -> remove all vias 233 model.setVias(null) 234 assert model.getVias().isEmpty() 235 236 // pass in empty list -> remove all vias 237 model.setVias([]) 238 assert model.getVias().isEmpty() 239 240 // create a list of vias with a way and twice a node (which doesn't 241 // make sense but is technically allowed) 242 // 243 createNode(41) 244 createNode(42) 245 createWay(4).setNodes([node(41), node(42)]) 246 model.setVias([way(4), node(22), node(22)]) 247 assert model.getVias() == [way(4), node(22), node(22)]; 248 249 // null values in the list of vias are skipped 261 250 model.setVias([null, node(22)]) 262 251 assert model.getVias() == [node(22)] 263 252 264 253 shouldFail(IllegalArgumentException) { 265 // an object which doesn't belong to the same dataset can't266 // be a via267 Node n = new Node(new LatLon(0,0))268 model.setVias([n])269 }270 }271 272 /**273 * Tests whether the three sub models exist274 */275 @Test276 public void submodelsExist() {277 assert model.getIssuesModel() != null278 assert model.getRelationMemberEditorModel() != null279 assert model.getTagEditorModel() != null280 281 assert model.getLayer() == layer282 } 254 // an object which doesn't belong to the same dataset can't 255 // be a via 256 Node n = new Node(new LatLon(0,0)) 257 model.setVias([n]) 258 } 259 } 260 261 /** 262 * Tests whether the three sub models exist 263 */ 264 @Test 265 public void submodelsExist() { 266 assert model.getIssuesModel() != null 267 assert model.getRelationMemberEditorModel() != null 268 assert model.getTagEditorModel() != null 269 270 assert model.getLayer() == layer 271 } 283 272 } -
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditorUnitTest.groovy
r32363 r32409 1 1 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 2 3 import groovy.util.GroovyTestCase; 3 import static groovy.test.GroovyAssert.shouldFail 4 import static org.junit.Assert.* 4 5 5 import org.openstreetmap.josm.data.osm.DataSet; 6 import org.junit.* 7 import org.openstreetmap.josm.data.osm.DataSet 6 8 import org.openstreetmap.josm.gui.layer.OsmDataLayer 7 import org.openstreetmap.josm.testutils.JOSMTestRules; 8 import org.openstreetmap.josm.JOSMFixture; 9 import org.openstreetmap.josm.testutils.JOSMTestRules 9 10 10 import static org.junit.Assert.*;11 import org.junit.*;12 11 /** 13 12 * Unit test for the {@link TurnRestrictionLegEditor} 14 *15 13 */ 16 class TurnRestrictionLegEditorUnitTest extends GroovyTestCase { 17 final shouldFail = new GroovyTestCase().&shouldFail 14 class TurnRestrictionLegEditorUnitTest { 18 15 19 16 @Rule 20 17 public JOSMTestRules rules = new JOSMTestRules().preferences(); 21 18 22 def navigationControlerMock = [23 gotoBasicEditor:{}, 19 def navigationControlerMock = [ 20 gotoBasicEditor:{}, 24 21 gotoAdvancedEditor: {} 25 ] as NavigationControler 26 27 private DataSet ds 28 private OsmDataLayer layer 29 private TurnRestrictionEditorModel model 30 31 @Before 32 public void setUp() { 33 ds = new DataSet() 34 layer = new OsmDataLayer(ds, "test", null) 35 model = new TurnRestrictionEditorModel(layer, navigationControlerMock); 36 } 37 38 @Test 39 public void test_Constructor() { 40 41 TurnRestrictionLegEditor editor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.FROM) 42 43 assert editor.getModel() == model 44 assert editor.getRole() == TurnRestrictionLegRole.FROM 45 46 shouldFail(IllegalArgumentException) { 47 editor = new TurnRestrictionLegEditor(null, TurnRestrictionLegRole.FROM) 48 } 22 ] as NavigationControler 49 23 50 shouldFail(IllegalArgumentException) { 51 editor = new TurnRestrictionLegEditor(model, null) 52 } 53 } 24 private DataSet ds 25 private OsmDataLayer layer 26 private TurnRestrictionEditorModel model 27 28 @Before 29 public void setUp() { 30 ds = new DataSet() 31 layer = new OsmDataLayer(ds, "test", null) 32 model = new TurnRestrictionEditorModel(layer, navigationControlerMock); 33 } 34 35 @Test 36 public void test_Constructor() { 37 38 TurnRestrictionLegEditor editor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.FROM) 39 40 assert editor.getModel() == model 41 assert editor.getRole() == TurnRestrictionLegRole.FROM 42 43 shouldFail(IllegalArgumentException) { 44 editor = new TurnRestrictionLegEditor(null, TurnRestrictionLegRole.FROM) 45 } 46 47 shouldFail(IllegalArgumentException) { 48 editor = new TurnRestrictionLegEditor(model, null) 49 } 50 } 54 51 } -
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionTypeRendererTest.groovy
r32363 r32409 1 1 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 2 3 import static org.junit.Assert.*; 4 import org.junit.*; 3 import static org.junit.Assert.* 5 4 6 import groovy.util.GroovyTestCase; 5 import org.junit.* 6 import org.openstreetmap.josm.testutils.JOSMTestRules 7 7 8 import java.awt.Component 9 import org.openstreetmap.josm.JOSMFixture 10 import org.openstreetmap.josm.testutils.JOSMTestRules;; 11 12 class TurnRestrictionTypeRendererTest extends GroovyTestCase{ 8 class TurnRestrictionTypeRendererTest { 13 9 14 10 @Rule 15 11 public JOSMTestRules rules = new JOSMTestRules().preferences(); 16 12 17 @Test 18 public void test_Constructor() { 19 TurnRestrictionTypeRenderer renderer = new TurnRestrictionTypeRenderer(); 20 21 assert renderer.@icons != null 22 assert renderer.@icons.get(TurnRestrictionType.NO_LEFT_TURN) != null 23 } 24 25 @Test 26 public void test_getListCellRendererComponent_1() { 27 TurnRestrictionTypeRenderer renderer = new TurnRestrictionTypeRenderer(); 28 29 def c = renderer.getListCellRendererComponent(null, null, 0, false, false) 30 assert c.getIcon() == null 31 assert c.getText() != null 32 33 c = renderer.getListCellRendererComponent(null, "non-standard-value", 0, false, false) 34 assert c.getIcon() == null 35 assert c.getText() == "non-standard-value" 13 @Test 14 public void test_Constructor() { 15 TurnRestrictionTypeRenderer renderer = new TurnRestrictionTypeRenderer(); 36 16 37 c = renderer.getListCellRendererComponent(null, TurnRestrictionType.NO_LEFT_TURN, 0, false, false) 38 assert c.getIcon() == renderer.@icons.get(TurnRestrictionType.NO_LEFT_TURN) 39 assert c.getText() == TurnRestrictionType.NO_LEFT_TURN.getDisplayName() 40 } 17 assert renderer.@icons != null 18 assert renderer.@icons.get(TurnRestrictionType.NO_LEFT_TURN) != null 19 } 20 21 @Test 22 public void test_getListCellRendererComponent_1() { 23 TurnRestrictionTypeRenderer renderer = new TurnRestrictionTypeRenderer(); 24 25 def c = renderer.getListCellRendererComponent(null, null, 0, false, false) 26 assert c.getIcon() == null 27 assert c.getText() != null 28 29 c = renderer.getListCellRendererComponent(null, "non-standard-value", 0, false, false) 30 assert c.getIcon() == null 31 assert c.getText() == "non-standard-value" 32 33 c = renderer.getListCellRendererComponent(null, TurnRestrictionType.NO_LEFT_TURN, 0, false, false) 34 assert c.getIcon() == renderer.@icons.get(TurnRestrictionType.NO_LEFT_TURN) 35 assert c.getText() == TurnRestrictionType.NO_LEFT_TURN.getDisplayName() 36 } 41 37 } -
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionTypeTest.groovy
r23510 r32409 1 1 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 import groovy.util.GroovyTestCase;2 import static org.junit.Assert.* 3 3 4 import static org.junit.Assert.*;5 4 import org.junit.* 6 class TurnRestrictionTypeTest extends GroovyTestCase{ 7 8 @Test 9 public void test_fromTagValue() { 10 11 TurnRestrictionType type = TurnRestrictionType.fromTagValue("no_left_turn") 12 assert type == TurnRestrictionType.NO_LEFT_TURN 13 14 type = TurnRestrictionType.fromTagValue("doesnt_exist") 15 assert type == null 16 17 type = TurnRestrictionType.fromTagValue(null) 18 assert type == null 19 } 5 6 class TurnRestrictionTypeTest { 7 8 @Test 9 public void test_fromTagValue() { 10 11 TurnRestrictionType type = TurnRestrictionType.fromTagValue("no_left_turn") 12 assert type == TurnRestrictionType.NO_LEFT_TURN 13 14 type = TurnRestrictionType.fromTagValue("doesnt_exist") 15 assert type == null 16 17 type = TurnRestrictionType.fromTagValue(null) 18 assert type == null 19 } 20 20 }
Note:
See TracChangeset
for help on using the changeset viewer.
