/
FlatCollectBooleanToObjectIterableTest.java
154 lines (136 loc) · 5.74 KB
/
FlatCollectBooleanToObjectIterableTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Copyright (c) 2017 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.collections.impl.lazy.primitive;
import org.eclipse.collections.api.InternalIterable;
import org.eclipse.collections.api.LazyIterable;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.impl.block.factory.Predicates;
import org.eclipse.collections.impl.block.factory.Predicates2;
import org.eclipse.collections.impl.block.factory.Predicates2Test;
import org.eclipse.collections.impl.block.factory.Procedures;
import org.eclipse.collections.impl.factory.Lists;
import org.eclipse.collections.impl.list.mutable.FastList;
import org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList;
import org.eclipse.collections.impl.test.Verify;
import org.junit.Assert;
import org.junit.Test;
public class FlatCollectBooleanToObjectIterableTest
{
private LazyIterable<Boolean> newPrimitiveWith(boolean... elements)
{
return new FlatCollectBooleanToObjectIterable<>(BooleanArrayList.newListWith(elements), Lists.mutable::with);
}
@Test
public void forEach()
{
InternalIterable<Boolean> select = this.newPrimitiveWith(true, false, true, false, true);
Appendable builder = new StringBuilder();
Procedure<Boolean> appendProcedure = Procedures.append(builder);
select.forEach(appendProcedure);
Assert.assertEquals("truefalsetruefalsetrue", builder.toString());
}
@Test
public void forEachWithIndex()
{
InternalIterable<Boolean> select = this.newPrimitiveWith(true, false, true, false, true);
StringBuilder builder = new StringBuilder("");
select.forEachWithIndex((object, index) -> {
builder.append(object);
builder.append(index);
});
Assert.assertEquals("true0false1true2false3true4", builder.toString());
}
@Test
public void iterator()
{
InternalIterable<Boolean> select = this.newPrimitiveWith(true, false, true, false, true);
StringBuilder builder = new StringBuilder("");
for (Boolean each : select)
{
builder.append(each);
}
Assert.assertEquals("truefalsetruefalsetrue", builder.toString());
}
@Test
public void forEachWith()
{
InternalIterable<Boolean> select = this.newPrimitiveWith(true, false, true, false, true);
StringBuilder builder = new StringBuilder("");
select.forEachWith((each, aBuilder) -> aBuilder.append(each), builder);
Assert.assertEquals("truefalsetruefalsetrue", builder.toString());
}
@Test
public void selectInstancesOf()
{
Assert.assertEquals(
FastList.newListWith(true, false, true, false, true),
this.newPrimitiveWith(true, false, true, false, true).selectInstancesOf(Boolean.class).toList());
}
@Test
public void sizeEmptyNotEmpty()
{
Verify.assertIterableSize(2, this.newPrimitiveWith(true, false));
Verify.assertIterableEmpty(this.newPrimitiveWith());
Assert.assertTrue(this.newPrimitiveWith(true, false).notEmpty());
}
@Test(expected = UnsupportedOperationException.class)
public void removeThrows()
{
this.newPrimitiveWith().iterator().remove();
}
@Test
public void detect()
{
Assert.assertEquals(Boolean.TRUE, this.newPrimitiveWith(true, false).detect(Predicates.equal(Boolean.TRUE)));
Assert.assertNull(this.newPrimitiveWith(true).detect(Predicates.equal(Boolean.FALSE)));
}
@Test
public void detectOptional()
{
Assert.assertEquals(Boolean.TRUE, this.newPrimitiveWith(true, false).detectOptional(Predicates.equal(Boolean.TRUE)).get());
Assert.assertFalse(this.newPrimitiveWith(true).detectOptional(Predicates.equal(Boolean.FALSE)).isPresent());
}
@Test
public void anySatisfy()
{
Assert.assertTrue(this.newPrimitiveWith(true).anySatisfy(Predicates.equal(Boolean.TRUE)));
Assert.assertFalse(this.newPrimitiveWith(true).anySatisfy(Predicates.equal(Boolean.FALSE)));
}
@Test
public void anySatisfyWith()
{
Assert.assertTrue(this.newPrimitiveWith(true).anySatisfyWith(Predicates2.equal(), Boolean.TRUE));
Assert.assertFalse(this.newPrimitiveWith(true).anySatisfyWith(Predicates2.equal(), Boolean.FALSE));
}
@Test
public void allSatisfy()
{
Assert.assertFalse(this.newPrimitiveWith(true, false).allSatisfy(Predicates.equal(Boolean.TRUE)));
Assert.assertTrue(this.newPrimitiveWith(true).allSatisfy(Predicates.equal(Boolean.TRUE)));
}
@Test
public void allSatisfyWith()
{
Assert.assertFalse(this.newPrimitiveWith(true, false).allSatisfyWith(Predicates2.equal(), Boolean.TRUE));
Assert.assertTrue(this.newPrimitiveWith(true).allSatisfyWith(Predicates2.equal(), Boolean.TRUE));
}
@Test
public void noneSatisfy()
{
Assert.assertFalse(this.newPrimitiveWith(true).noneSatisfy(Predicates.equal(Boolean.TRUE)));
Assert.assertTrue(this.newPrimitiveWith(false).noneSatisfy(Predicates.equal(Boolean.TRUE)));
}
@Test
public void noneSatisfyWith()
{
Assert.assertFalse(this.newPrimitiveWith(true).noneSatisfyWith(Predicates2.equal(), Boolean.TRUE));
Assert.assertTrue(this.newPrimitiveWith(false).noneSatisfyWith(Predicates2.equal(), Boolean.TRUE));
}
}