Debian Codegraph @

scala-unit-tests/src/test/scala/org/eclipse/collections/impl/InternalIterableTestTrait.scala

raw
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.InternalIterable
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.eclipse.collections.impl.test.Verify
18 import org.junit.{Assert, Test}
19
20 trait InternalIterableTestTrait extends IterableTestTrait
21 {
22 val classUnderTest: InternalIterable[String]
23
24 @Test
25 def forEach
26 {
27 val result = FastList.newList[String]
28
29 this.classUnderTest.forEach(CollectionAddProcedure.on(result))
30
31 Verify.assertSize(3, result)
32 Verify.assertContainsAll(result, "1", "2", "3")
33 }
34
35 @Test
36 def forEachWithIndex
37 {
38 val result = FastList.newList[String]
39 val indices = FastList.newList[Integer]
40
41 var count = 0
42 this.classUnderTest.forEachWithIndex
43 {
44 (each: String, index: Int) =>
45 Assert.assertEquals(index, count)
46 count += 1
47 result.add(each)
48 indices.add(index)
49 ()
50 }
51
52 Verify.assertSize(3, result)
53 Verify.assertContainsAll(result, "1", "2", "3")
54
55 Verify.assertSize(3, indices)
56 Verify.assertContainsAll(indices, Integer.valueOf(0), Integer.valueOf(1), Integer.valueOf(2))
57 }
58
59 @Test
60 def forEachWith
61 {
62 val result = FastList.newList[String]
63
64 this.classUnderTest.forEachWith(
65 (each: String, parameter: String) =>
66 {
67 result.add(each + parameter)
68 ()
69 },
70 "!")
71
72 Verify.assertSize(3, result)
73 Verify.assertContainsAll(result, "1!", "2!", "3!")
74 }
75 }