| 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 org.eclipse.collections.api.list.ListIterable |
| 14 |
import org.eclipse.collections.impl.Prelude._ |
| 15 |
import org.eclipse.collections.impl.block.procedure.CollectionAddProcedure |
| 16 |
import org.eclipse.collections.impl.list.mutable.FastList |
| 17 |
import org.junit.{Assert, Test} |
| 18 |
|
| 19 |
trait ListIterableTestTrait extends InternalIterableTestTrait |
| 20 |
{ |
| 21 |
val classUnderTest: ListIterable[String] |
| 22 |
|
| 23 |
@Test |
| 24 |
abstract override def forEach |
| 25 |
{ |
| 26 |
super.forEach |
| 27 |
|
| 28 |
val result = FastList.newList[String] |
| 29 |
classUnderTest.forEach(CollectionAddProcedure.on(result)) |
| 30 |
Assert.assertEquals(FastList.newListWith("1", "2", "3"), result) |
| 31 |
} |
| 32 |
|
| 33 |
@Test |
| 34 |
abstract override def forEachWithIndex |
| 35 |
{ |
| 36 |
super.forEachWithIndex |
| 37 |
|
| 38 |
var count = 0 |
| 39 |
classUnderTest.forEachWithIndex |
| 40 |
{ |
| 41 |
(each: String, index: Int) => |
| 42 |
Assert.assertEquals(index, count) |
| 43 |
count += 1 |
| 44 |
Assert.assertEquals(String.valueOf(count), each) |
| 45 |
} |
| 46 |
|
| 47 |
Assert.assertEquals(3, count) |
| 48 |
} |
| 49 |
|
| 50 |
@Test |
| 51 |
abstract override def forEachWith |
| 52 |
{ |
| 53 |
super.forEachWith |
| 54 |
|
| 55 |
val unique = new AnyRef |
| 56 |
var count = 0 |
| 57 |
|
| 58 |
classUnderTest.forEachWith( |
| 59 |
(each: String, parameter: AnyRef) => |
| 60 |
{ |
| 61 |
count += 1 |
| 62 |
Assert.assertEquals(String.valueOf(count), each) |
| 63 |
Assert.assertSame(unique, parameter) |
| 64 |
() |
| 65 |
}, |
| 66 |
unique) |
| 67 |
|
| 68 |
Assert.assertEquals(3, count) |
| 69 |
} |
| 70 |
} |