Changeset 32409 in osm for applications/editors/josm/plugins/turnrestrictions
- Timestamp:
- 2016-06-26T15:53:08+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions
- Files:
-
- 7 edited
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 * 45 46 47 48 49 50 51 52 53 54 55 Relation r = builder.build(sel) 56 57 58 59 60 61 62 63 64 65 assert r.get("restriction") == "no_u_turn" 66 67 68 69 70 71 72 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 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 99 100 } 101 94 def tr = builder.build(null) 95 assertEmptyTurnRestriction(tr) 96 } 97 102 98 @Test 103 99 public void emptySelection() { 104 105 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 115 116 117 118 119 120 } 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 129 130 131 132 133 134 135 136 137 138 139 140 } 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 154 155 156 157 158 159 160 161 162 163 164 165 assert builder.phi(w1) == Math.toRadians(90) 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 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 200 201 * 202 203 204 205 206 * | 207 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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 assert memberWithRole(tr, "via") == n2 249 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 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 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 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 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 351 352 353 } 354 355 356 357 358 359 360 361 /**362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 * n1 from 415 416 417 418 419 420 421 422 * 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 * 463 * 464 465 466 467 468 469 346 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 * | from 473 474 * (-10,-10) n1 475 467 * | 468 * | from 469 * | 470 * (-10,-10) n1 471 */ 476 472 @Test 477 473 public void intersectionAngle_3() { 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 } 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 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 525 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 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 } 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() == 3 45 // 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 71 72 73 69 objects = objects[1..2] 70 model.setJOSMSelection(objects) 71 assert model.getSelected().asList() == [objects[0]] 72 } 74 73 75 76 77 78 74 @Test 75 public void test_getSelected() { 76 DataSet ds = new DataSet() 77 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 79 78 80 81 79 JosmSelectionListModel model = new JosmSelectionListModel(layer); 80 DefaultListSelectionModel selectionModel = model.getListSelectionModel() 82 81 83 84 82 assert model.getSelected() != null 83 assert model.getSelected().isEmpty() 85 84 86 87 88 89 90 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 93 94 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 98 99 100 96 @Test 97 public void test_setSelected() { 98 DataSet ds = new DataSet() 99 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 101 100 102 103 104 105 106 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 109 110 107 // set selected with empty list is OK - nothing selected thereafter 108 model.setSelected([]) 109 assert model.getSelected().isEmpty() 111 110 112 113 114 115 116 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 119 120 121 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 125 126 123 @Test 124 public void test_editLayerChanged() { 125 DataSet ds = new DataSet() 127 126 128 129 127 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()] 128 objects.each {ds.addPrimitive(it)} 130 129 131 132 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 138 139 140 136 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 142 assert model.getSize() == 0 144 143 145 146 147 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 150 148 assert model.getSize() == 1 149 assert model.getElementAt(0) == objects[0]; 151 150 152 153 151 // 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 157 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 32 gotoBasicEditor:{}, 20 def navigationControlerMock = [ 21 gotoBasicEditor:{}, 33 22 gotoAdvancedEditor: {} 34 35 36 37 38 private TurnRestrictionEditorModel model 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 def buildDataSet1() { 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 r.put "restriction", "no_left_turn" 96 97 98 99 100 101 102 layer = new OsmDataLayer(ds, "test", null) 103 104 105 106 107 * Test the constructor 108 109 110 public void test_Constructor() { 111 112 model = new TurnRestrictionEditorModel(null, navigationControlerMock); 113 114 115 116 model = new TurnRestrictionEditorModel(layer, null); 117 118 119 120 121 public void test_populate_EmptyTurnRestriction() { 122 // an "empty" turn restriction with a public id 123 124 125 126 127 128 129 130 131 132 133 134 135 136 * 137 138 139 public void test_populate_SimpleStandardTurnRestriction() { 140 buildDataSet1() 141 142 143 144 145 146 147 148 149 150 151 152 buildDataSet1() 153 154 155 156 157 158 159 // set another way as from 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 // can't set a way as 'from' if it isn't part of the dataset 175 Way way = new Way() 176 177 178 179 180 181 182 buildDataSet1() 183 184 185 186 187 188 189 // set another way as from 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 // can't set a way as 'from' if it isn't part of the dataset 205 Way way = new Way() 206 207 208 209 210 211 212 213 214 215 buildDataSet1() 216 217 218 219 220 221 222 223 224 225 226 227 228 assert model.getRestrictionTagValue() == "no_right_turn"; 229 230 231 232 233 234 235 236 buildDataSet1() 237 238 239 240 241 242 243 // pass in null as vias -> remove all vias 244 245 246 247 // pass in empty list -> remove all vias 248 249 250 251 252 253 254 255 256 257 258 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 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 assert model.getLayer() == layer 282 } 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 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.