Skip to content

Commit

Permalink
(yegor256#829) Turn AndInThreadsTest Stable
Browse files Browse the repository at this point in the history
  • Loading branch information
pbenety committed May 22, 2018
1 parent 4cf47f1 commit 0284285
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions src/test/java/org/cactoos/scalar/AndInThreadsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand All @@ -47,7 +46,7 @@
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
@SuppressWarnings("PMD.TooManyMethods")
@SuppressWarnings({"PMD.TooManyMethods", "PMD.AvoidDuplicateLiterals"})
public final class AndInThreadsTest {

@Test
Expand All @@ -57,8 +56,8 @@ public void allTrue() throws Exception {
new True(),
new True(),
new True()
).value(),
Matchers.equalTo(true)
),
new ScalarHasValue<>(true)
);
}

Expand All @@ -69,8 +68,8 @@ public void oneFalse() throws Exception {
new True(),
new False(),
new True()
).value(),
Matchers.equalTo(false)
),
new ScalarHasValue<>(false)
);
}

Expand All @@ -83,22 +82,24 @@ public void allFalse() throws Exception {
new False(),
new False()
)
).value(),
Matchers.equalTo(false)
),
new ScalarHasValue<>(false)
);
}

@Test
public void emptyIterator() throws Exception {
MatcherAssert.assertThat(
new AndInThreads(Collections.emptyList()).value(),
Matchers.equalTo(true)
new AndInThreads(new IterableOf<Scalar<Boolean>>()),
new ScalarHasValue<>(true)
);
}

@Test
public void iteratesList() {
final List<String> list = new LinkedList<>();
final List<String> list = Collections.synchronizedList(
new ArrayList<String>(2)
);
MatcherAssert.assertThat(
"Can't iterate a list with a procedure",
new AndInThreads(
Expand All @@ -107,25 +108,24 @@ public void iteratesList() {
new IterableOf<>("hello", "world")
)
),
new ScalarHasValue<>(
Matchers.allOf(
Matchers.equalTo(true),
new MatcherOf<>(
value -> list.size() == 2
)
)
)
new ScalarHasValue<>(true)
);
MatcherAssert.assertThat(
list,
Matchers.containsInAnyOrder("hello", "world")
);
}

@Test
public void iteratesEmptyList() {
final List<String> list = new LinkedList<>();
final List<String> list = Collections.synchronizedList(
new ArrayList<String>(2)
);
MatcherAssert.assertThat(
"Can't iterate a list",
new AndInThreads(
new Mapped<String, Scalar<Boolean>>(
new FuncOf<>(list::add, () -> true), Collections.emptyList()
new FuncOf<>(list::add, () -> true), new IterableOf<>()
)
),
new ScalarHasValue<>(
Expand All @@ -143,14 +143,16 @@ public void iteratesEmptyList() {

@Test
public void worksWithProc() throws Exception {
final List<Integer> list = new LinkedList<>();
final List<Integer> list = Collections.synchronizedList(
new ArrayList<Integer>(2)
);
new AndInThreads(
(Proc<Integer>) list::add,
1, 1
).value();
MatcherAssert.assertThat(
list.size(),
Matchers.equalTo(2)
list,
Matchers.contains(1, 1)
);
}

Expand All @@ -160,8 +162,8 @@ public void worksWithFunc() throws Exception {
new AndInThreads(
input -> input > 0,
1, -1, 0
).value(),
Matchers.equalTo(false)
),
new ScalarHasValue<>(false)
);
}

Expand Down

0 comments on commit 0284285

Please sign in to comment.