-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#829 Turn AndInThreadsTest Stable #874
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,29 +25,34 @@ | |
|
||
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; | ||
import org.cactoos.Proc; | ||
import org.cactoos.Scalar; | ||
import org.cactoos.collection.CollectionOf; | ||
import org.cactoos.func.FuncOf; | ||
import org.cactoos.iterable.IterableOf; | ||
import org.cactoos.iterable.Mapped; | ||
import org.cactoos.list.ListOf; | ||
import org.hamcrest.Matcher; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.hamcrest.collection.IsIterableContainingInAnyOrder; | ||
import org.junit.Test; | ||
import org.llorllale.cactoos.matchers.MatcherOf; | ||
import org.llorllale.cactoos.matchers.ScalarHasValue; | ||
|
||
/** | ||
* Test case for {@link AndInThreads}. | ||
* @since 0.25 | ||
* @todo #829:30min Remove the use of the static method | ||
* `Collections.synchronizedList`. Replace by an object-oriented approach. | ||
* Create a class similar to `SyncCollection` but mutable. | ||
* @checkstyle JavadocMethodCheck (500 lines) | ||
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines) | ||
*/ | ||
@SuppressWarnings("PMD.TooManyMethods") | ||
@SuppressWarnings({"PMD.TooManyMethods", "PMD.AvoidDuplicateLiterals"}) | ||
public final class AndInThreadsTest { | ||
|
||
@Test | ||
|
@@ -57,8 +62,8 @@ public void allTrue() throws Exception { | |
new True(), | ||
new True(), | ||
new True() | ||
).value(), | ||
Matchers.equalTo(true) | ||
), | ||
new ScalarHasValue<>(true) | ||
); | ||
} | ||
|
||
|
@@ -69,8 +74,8 @@ public void oneFalse() throws Exception { | |
new True(), | ||
new False(), | ||
new True() | ||
).value(), | ||
Matchers.equalTo(false) | ||
), | ||
new ScalarHasValue<>(false) | ||
); | ||
} | ||
|
||
|
@@ -83,22 +88,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( | ||
|
@@ -107,11 +114,21 @@ public void iteratesList() { | |
new IterableOf<>("hello", "world") | ||
) | ||
), | ||
new ScalarHasValue<>( | ||
Matchers.allOf( | ||
Matchers.equalTo(true), | ||
new ScalarHasValue<>(true) | ||
); | ||
MatcherAssert.assertThat( | ||
list, | ||
new IsIterableContainingInAnyOrder<String>( | ||
new CollectionOf<Matcher<? super String>>( | ||
new MatcherOf<>( | ||
text -> { | ||
return "hello".equals(text); | ||
} | ||
), | ||
new MatcherOf<>( | ||
value -> list.size() == 2 | ||
text -> { | ||
return "world".equals(text); | ||
} | ||
) | ||
) | ||
) | ||
|
@@ -120,12 +137,14 @@ public void iteratesList() { | |
|
||
@Test | ||
public void iteratesEmptyList() { | ||
final List<String> list = new LinkedList<>(); | ||
final List<String> list = Collections.synchronizedList( | ||
new ArrayList<String>(2) | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pbenety What do you think about using cactoos There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @paulodamaso I thought about it but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pbenety Same as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @paulodamaso |
||
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<>( | ||
|
@@ -143,14 +162,29 @@ 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) | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pbenety What do you think about using cactoos There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @paulodamaso I thought about it but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pbenety Same as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @paulodamaso |
||
new AndInThreads( | ||
(Proc<Integer>) list::add, | ||
1, 1 | ||
).value(); | ||
MatcherAssert.assertThat( | ||
list.size(), | ||
Matchers.equalTo(2) | ||
list, | ||
new IsIterableContainingInAnyOrder<Integer>( | ||
new CollectionOf<Matcher<? super Integer>>( | ||
new MatcherOf<>( | ||
value -> { | ||
return value.equals(1); | ||
} | ||
), | ||
new MatcherOf<>( | ||
value -> { | ||
return value.equals(1); | ||
} | ||
) | ||
) | ||
) | ||
); | ||
} | ||
|
||
|
@@ -160,8 +194,8 @@ public void worksWithFunc() throws Exception { | |
new AndInThreads( | ||
input -> input > 0, | ||
1, -1, 0 | ||
).value(), | ||
Matchers.equalTo(false) | ||
), | ||
new ScalarHasValue<>(false) | ||
); | ||
} | ||
|
||
|
@@ -176,7 +210,20 @@ public void worksWithProcIterable() throws Exception { | |
).value(); | ||
MatcherAssert.assertThat( | ||
list, | ||
Matchers.containsInAnyOrder(1, 2) | ||
new IsIterableContainingInAnyOrder<Integer>( | ||
new CollectionOf<Matcher<? super Integer>>( | ||
new MatcherOf<>( | ||
value -> { | ||
return value.equals(1); | ||
} | ||
), | ||
new MatcherOf<>( | ||
value -> { | ||
return value.equals(2); | ||
} | ||
) | ||
) | ||
) | ||
); | ||
} | ||
|
||
|
@@ -206,7 +253,20 @@ public void worksWithExecServiceProcValues() throws Exception { | |
).value(); | ||
MatcherAssert.assertThat( | ||
list, | ||
Matchers.containsInAnyOrder(1, 2) | ||
new IsIterableContainingInAnyOrder<Integer>( | ||
new CollectionOf<Matcher<? super Integer>>( | ||
new MatcherOf<>( | ||
value -> { | ||
return value.equals(1); | ||
} | ||
), | ||
new MatcherOf<>( | ||
value -> { | ||
return value.equals(2); | ||
} | ||
) | ||
) | ||
) | ||
); | ||
} | ||
|
||
|
@@ -223,7 +283,20 @@ public void worksWithExecServiceProcIterable() throws Exception { | |
).value(); | ||
MatcherAssert.assertThat( | ||
list, | ||
Matchers.containsInAnyOrder(1, 2) | ||
new IsIterableContainingInAnyOrder<Integer>( | ||
new CollectionOf<Matcher<? super Integer>>( | ||
new MatcherOf<>( | ||
value -> { | ||
return value.equals(1); | ||
} | ||
), | ||
new MatcherOf<>( | ||
value -> { | ||
return value.equals(2); | ||
} | ||
) | ||
) | ||
) | ||
); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pbenety What do you think about using cactoos
SyncCollection
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paulodamaso I thought about it but
SyncCollection
does not implementadd
method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pbenety Right, it needs to be mutable for the test, so that's ok for now. Just open a
@todo
about removing these static methods access from here so we can think about it in the future.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paulodamaso
@todo
added.