| 1 |
/* |
| 2 |
* Copyright (c) 2021 Goldman Sachs. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* and Eclipse Distribution License v. 1.0 which accompany this distribution. |
| 6 |
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* and the Eclipse Distribution License is available at |
| 8 |
* http://www.eclipse.org/org/documents/edl-v10.php. |
| 9 |
*/ |
| 10 |
|
| 11 |
package org.eclipse.collections.impl |
| 12 |
|
| 13 |
import java.lang.StringBuilder |
| 14 |
|
| 15 |
import org.eclipse.collections.api.RichIterable |
| 16 |
import org.eclipse.collections.api.collection.MutableCollection |
| 17 |
import org.eclipse.collections.api.list.MutableList |
| 18 |
import org.eclipse.collections.api.multimap.MutableMultimap |
| 19 |
import org.eclipse.collections.api.tuple.Pair |
| 20 |
import org.eclipse.collections.impl.Prelude._ |
| 21 |
import org.eclipse.collections.impl.list.mutable.FastList |
| 22 |
import org.eclipse.collections.impl.multimap.list.FastListMultimap |
| 23 |
import org.junit.Test |
| 24 |
|
| 25 |
trait SynchronizedRichIterableTestTrait extends SynchronizedMutableIterableTestTrait /* with RichIterableTestTrait */ |
| 26 |
{ |
| 27 |
val classUnderTest: RichIterable[String] |
| 28 |
|
| 29 |
@Test |
| 30 |
def size_synchronized |
| 31 |
{ |
| 32 |
this.assertSynchronized |
| 33 |
{ |
| 34 |
this.classUnderTest.size |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
@Test |
| 39 |
def isEmpty_synchronized |
| 40 |
{ |
| 41 |
this.assertSynchronized |
| 42 |
{ |
| 43 |
this.classUnderTest.isEmpty |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
@Test |
| 48 |
def notEmpty_synchronized |
| 49 |
{ |
| 50 |
this.assertSynchronized |
| 51 |
{ |
| 52 |
this.classUnderTest.notEmpty |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
@Test |
| 57 |
def getFirst_synchronized |
| 58 |
{ |
| 59 |
this.assertSynchronized |
| 60 |
{ |
| 61 |
this.classUnderTest.getFirst |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
@Test |
| 66 |
def contains_synchronized |
| 67 |
{ |
| 68 |
this.assertSynchronized |
| 69 |
{ |
| 70 |
this.classUnderTest.contains(null) |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
@Test |
| 75 |
def containsAllIterable_synchronized |
| 76 |
{ |
| 77 |
this.assertSynchronized |
| 78 |
{ |
| 79 |
val iterable: java.lang.Iterable[_] = FastList.newList[AnyRef] |
| 80 |
this.classUnderTest.containsAllIterable(iterable) |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
@Test |
| 85 |
def containsAllArguments_synchronized |
| 86 |
{ |
| 87 |
this.assertSynchronized |
| 88 |
{ |
| 89 |
this.classUnderTest.containsAllArguments("", "", "") |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
@Test |
| 94 |
def select_synchronized |
| 95 |
{ |
| 96 |
this.assertSynchronized |
| 97 |
{ |
| 98 |
this.classUnderTest.select({ |
| 99 |
_: String => false |
| 100 |
}) |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
@Test |
| 105 |
def select_with_target_synchronized |
| 106 |
{ |
| 107 |
this.assertSynchronized |
| 108 |
{ |
| 109 |
this.classUnderTest.select({ |
| 110 |
_: String => false |
| 111 |
}, FastList.newList[String]) |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
@Test |
| 116 |
def reject_synchronized |
| 117 |
{ |
| 118 |
this.assertSynchronized |
| 119 |
{ |
| 120 |
this.classUnderTest.reject({ |
| 121 |
_: String => true |
| 122 |
}) |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
@Test |
| 127 |
def reject_with_target_synchronized |
| 128 |
{ |
| 129 |
this.assertSynchronized |
| 130 |
{ |
| 131 |
this.classUnderTest.reject({ |
| 132 |
_: String => true |
| 133 |
}, null) |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
@Test |
| 138 |
def partition_synchronized |
| 139 |
{ |
| 140 |
this.assertSynchronized |
| 141 |
{ |
| 142 |
this.classUnderTest.partition({ |
| 143 |
_: String => true |
| 144 |
}) |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
@Test |
| 149 |
def partitionWith_synchronized |
| 150 |
{ |
| 151 |
this.assertSynchronized |
| 152 |
{ |
| 153 |
this.classUnderTest.partitionWith({ |
| 154 |
(_: String, _: AnyRef) => true |
| 155 |
}, null) |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
@Test |
| 160 |
def collect_synchronized |
| 161 |
{ |
| 162 |
this.assertSynchronized |
| 163 |
{ |
| 164 |
this.classUnderTest.collect({ |
| 165 |
_: String => null |
| 166 |
}) |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
@Test |
| 171 |
def collect_with_target_synchronized |
| 172 |
{ |
| 173 |
this.assertSynchronized |
| 174 |
{ |
| 175 |
this.classUnderTest.collect[String, MutableCollection[String]]( |
| 176 |
{ |
| 177 |
_: String => "" |
| 178 |
}, |
| 179 |
FastList.newList[String]) |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
@Test |
| 184 |
def collectIf_synchronized |
| 185 |
{ |
| 186 |
this.assertSynchronized |
| 187 |
{ |
| 188 |
this.classUnderTest.collectIf({ |
| 189 |
_: String => false |
| 190 |
}, |
| 191 |
{ |
| 192 |
_: String => "" |
| 193 |
}) |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
@Test |
| 198 |
def collectIf_with_target_synchronized |
| 199 |
{ |
| 200 |
this.assertSynchronized |
| 201 |
{ |
| 202 |
this.classUnderTest.collectIf[String, MutableCollection[String]]( |
| 203 |
{ |
| 204 |
_: String => false |
| 205 |
}, |
| 206 |
{ |
| 207 |
_: String => "" |
| 208 |
}, |
| 209 |
FastList.newList[String]) |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
@Test |
| 214 |
def flatCollect_synchronized |
| 215 |
{ |
| 216 |
this.assertSynchronized |
| 217 |
{ |
| 218 |
this.classUnderTest.flatCollect({ |
| 219 |
_: String => FastList.newList[String] |
| 220 |
}) |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
@Test |
| 225 |
def flatCollect_with_target_synchronized |
| 226 |
{ |
| 227 |
this.assertSynchronized |
| 228 |
{ |
| 229 |
this.classUnderTest.flatCollect[String, MutableList[String]]({ |
| 230 |
_: String => FastList.newList[String] |
| 231 |
}, FastList.newList[String]) |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
@Test |
| 236 |
def detect_synchronized |
| 237 |
{ |
| 238 |
this.assertSynchronized |
| 239 |
{ |
| 240 |
this.classUnderTest.detect({ |
| 241 |
_: String => false |
| 242 |
}) |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
@Test |
| 247 |
def detectIfNone_synchronized |
| 248 |
{ |
| 249 |
this.assertSynchronized |
| 250 |
{ |
| 251 |
this.classUnderTest.detectIfNone({ |
| 252 |
_: String => false |
| 253 |
}, |
| 254 |
{ |
| 255 |
() => "" |
| 256 |
}) |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
@Test |
| 261 |
def count_synchronized |
| 262 |
{ |
| 263 |
this.assertSynchronized |
| 264 |
{ |
| 265 |
this.classUnderTest.count({ |
| 266 |
_: String => false |
| 267 |
}) |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
@Test |
| 272 |
def anySatisfy_synchronized |
| 273 |
{ |
| 274 |
this.assertSynchronized |
| 275 |
{ |
| 276 |
this.classUnderTest.anySatisfy({ |
| 277 |
_: String => true |
| 278 |
}) |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
@Test |
| 283 |
def anySatisfyWith_synchronized |
| 284 |
{ |
| 285 |
this.assertSynchronized |
| 286 |
{ |
| 287 |
this.classUnderTest.anySatisfyWith({ |
| 288 |
(_: String, _: AnyRef) => true |
| 289 |
}, null) |
| 290 |
} |
| 291 |
} |
| 292 |
|
| 293 |
@Test |
| 294 |
def allSatisfy_synchronized |
| 295 |
{ |
| 296 |
this.assertSynchronized |
| 297 |
{ |
| 298 |
this.classUnderTest.allSatisfy({ |
| 299 |
_: String => false |
| 300 |
}) |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
@Test |
| 305 |
def allSatisfyWith_synchronized |
| 306 |
{ |
| 307 |
this.assertSynchronized |
| 308 |
{ |
| 309 |
this.classUnderTest.allSatisfyWith({ |
| 310 |
(_: String, _: AnyRef) => false |
| 311 |
}, null) |
| 312 |
} |
| 313 |
} |
| 314 |
|
| 315 |
@Test |
| 316 |
def noneSatisfy_synchronized |
| 317 |
{ |
| 318 |
this.assertSynchronized |
| 319 |
{ |
| 320 |
this.classUnderTest.noneSatisfy({ |
| 321 |
_: String => false |
| 322 |
}) |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
@Test |
| 327 |
def noneSatisfyWith_synchronized |
| 328 |
{ |
| 329 |
this.assertSynchronized |
| 330 |
{ |
| 331 |
this.classUnderTest.noneSatisfyWith({ |
| 332 |
(_: String, _: AnyRef) => false |
| 333 |
}, null) |
| 334 |
} |
| 335 |
} |
| 336 |
|
| 337 |
@Test |
| 338 |
def injectInto_synchronized |
| 339 |
{ |
| 340 |
this.assertSynchronized |
| 341 |
{ |
| 342 |
this.classUnderTest.injectInto[String]("", (_: String, _: String) => "") |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
@Test |
| 347 |
def toList_synchronized |
| 348 |
{ |
| 349 |
this.assertSynchronized |
| 350 |
{ |
| 351 |
this.classUnderTest.toList |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
@Test |
| 356 |
def toSortedList_synchronized |
| 357 |
{ |
| 358 |
this.assertSynchronized |
| 359 |
{ |
| 360 |
this.classUnderTest.toSortedList |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
@Test |
| 365 |
def toSortedList_with_comparator_synchronized |
| 366 |
{ |
| 367 |
this.assertSynchronized |
| 368 |
{ |
| 369 |
this.classUnderTest.toSortedList(null) |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
@Test |
| 374 |
def toSortedListBy_synchronized |
| 375 |
{ |
| 376 |
this.assertSynchronized |
| 377 |
{ |
| 378 |
this.classUnderTest.toSortedListBy[String]((string: String) => string) |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
@Test |
| 383 |
def toSet_synchronized |
| 384 |
{ |
| 385 |
this.assertSynchronized |
| 386 |
{ |
| 387 |
this.classUnderTest.toSet |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
@Test |
| 392 |
def toMap_synchronized |
| 393 |
{ |
| 394 |
this.assertSynchronized |
| 395 |
{ |
| 396 |
this.classUnderTest.toMap({ |
| 397 |
_: String => "" |
| 398 |
}, |
| 399 |
{ |
| 400 |
_: String => "" |
| 401 |
}) |
| 402 |
} |
| 403 |
} |
| 404 |
|
| 405 |
@Test |
| 406 |
def toArray_synchronized |
| 407 |
{ |
| 408 |
this.assertSynchronized |
| 409 |
{ |
| 410 |
this.classUnderTest.toArray |
| 411 |
} |
| 412 |
} |
| 413 |
|
| 414 |
@Test |
| 415 |
def toArray_with_target_synchronized |
| 416 |
{ |
| 417 |
this.assertSynchronized |
| 418 |
{ |
| 419 |
val array: Array[String] = new Array[String](this.classUnderTest.size()) |
| 420 |
this.classUnderTest.toArray(array) |
| 421 |
} |
| 422 |
} |
| 423 |
|
| 424 |
@Test |
| 425 |
def max_synchronized |
| 426 |
{ |
| 427 |
this.assertSynchronized |
| 428 |
{ |
| 429 |
this.classUnderTest.max({ |
| 430 |
(_: String, _: String) => 0 |
| 431 |
}) |
| 432 |
} |
| 433 |
} |
| 434 |
|
| 435 |
@Test |
| 436 |
def min_synchronized |
| 437 |
{ |
| 438 |
this.assertSynchronized |
| 439 |
{ |
| 440 |
this.classUnderTest.min({ |
| 441 |
(_: String, _: String) => 0 |
| 442 |
}) |
| 443 |
} |
| 444 |
} |
| 445 |
|
| 446 |
@Test |
| 447 |
def max_without_comparator_synchronized |
| 448 |
{ |
| 449 |
this.assertSynchronized |
| 450 |
{ |
| 451 |
this.classUnderTest.max() |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
@Test |
| 456 |
def min_without_comparator_synchronized |
| 457 |
{ |
| 458 |
this.assertSynchronized |
| 459 |
{ |
| 460 |
this.classUnderTest.min() |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
@Test |
| 465 |
def maxBy_synchronized |
| 466 |
{ |
| 467 |
this.assertSynchronized |
| 468 |
{ |
| 469 |
this.classUnderTest.maxBy[String]((string: String) => string) |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
@Test |
| 474 |
def minBy_synchronized |
| 475 |
{ |
| 476 |
this.assertSynchronized |
| 477 |
{ |
| 478 |
this.classUnderTest.minBy[String]((string: String) => string) |
| 479 |
} |
| 480 |
} |
| 481 |
|
| 482 |
@Test |
| 483 |
def makeString_synchronized |
| 484 |
{ |
| 485 |
this.assertSynchronized |
| 486 |
{ |
| 487 |
this.classUnderTest.makeString |
| 488 |
} |
| 489 |
} |
| 490 |
|
| 491 |
@Test |
| 492 |
def makeString_with_separator_synchronized |
| 493 |
{ |
| 494 |
this.assertSynchronized |
| 495 |
{ |
| 496 |
this.classUnderTest.makeString(", ") |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
@Test |
| 501 |
def makeString_with_start_separator_end_synchronized |
| 502 |
{ |
| 503 |
this.assertSynchronized |
| 504 |
{ |
| 505 |
this.classUnderTest.makeString("[", ", ", "]") |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
@Test |
| 510 |
def appendString_synchronized |
| 511 |
{ |
| 512 |
this.assertSynchronized |
| 513 |
{ |
| 514 |
this.classUnderTest.appendString(new StringBuilder) |
| 515 |
} |
| 516 |
} |
| 517 |
|
| 518 |
@Test |
| 519 |
def appendString_with_separator_synchronized |
| 520 |
{ |
| 521 |
this.assertSynchronized |
| 522 |
{ |
| 523 |
this.classUnderTest.appendString(new StringBuilder, ", ") |
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
@Test |
| 528 |
def appendString_with_start_separator_end_synchronized |
| 529 |
{ |
| 530 |
this.assertSynchronized |
| 531 |
{ |
| 532 |
this.classUnderTest.appendString(new StringBuilder, "[", ", ", "]") |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
@Test |
| 537 |
def groupBy_synchronized |
| 538 |
{ |
| 539 |
this.assertSynchronized |
| 540 |
{ |
| 541 |
this.classUnderTest.groupBy({ |
| 542 |
_: String => "" |
| 543 |
}) |
| 544 |
} |
| 545 |
} |
| 546 |
|
| 547 |
@Test |
| 548 |
def groupBy_with_target_synchronized |
| 549 |
{ |
| 550 |
this.assertSynchronized |
| 551 |
{ |
| 552 |
this.classUnderTest.groupBy[String, MutableMultimap[String, String]]( |
| 553 |
{ |
| 554 |
_: String => "" |
| 555 |
}, |
| 556 |
FastListMultimap.newMultimap[String, String]) |
| 557 |
} |
| 558 |
} |
| 559 |
|
| 560 |
@Test |
| 561 |
def toString_synchronized |
| 562 |
{ |
| 563 |
this.assertSynchronized |
| 564 |
{ |
| 565 |
this.classUnderTest.toString |
| 566 |
} |
| 567 |
} |
| 568 |
|
| 569 |
@Test |
| 570 |
def zip_synchronized |
| 571 |
{ |
| 572 |
this.assertSynchronized |
| 573 |
{ |
| 574 |
this.classUnderTest.zip[String](FastList.newList[String]) |
| 575 |
} |
| 576 |
} |
| 577 |
|
| 578 |
@Test |
| 579 |
def zip__with_target_synchronized |
| 580 |
{ |
| 581 |
this.assertSynchronized |
| 582 |
{ |
| 583 |
this.classUnderTest.zip[String, FastList[Pair[String, String]]](FastList.newList[String](), |
| 584 |
FastList.newList[Pair[String, String]]()) |
| 585 |
} |
| 586 |
} |
| 587 |
|
| 588 |
@Test |
| 589 |
def zipWithIndex_synchronized |
| 590 |
{ |
| 591 |
this.assertSynchronized |
| 592 |
{ |
| 593 |
this.classUnderTest.zipWithIndex() |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
@Test |
| 598 |
def zipWithIndex__with_target_synchronized |
| 599 |
{ |
| 600 |
this.assertSynchronized |
| 601 |
{ |
| 602 |
this.classUnderTest.zipWithIndex(FastList.newList[Pair[String, java.lang.Integer]]()) |
| 603 |
} |
| 604 |
} |
| 605 |
} |