You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by pe...@apache.org on 2017/08/20 15:03:43 UTC
[43/53] [abbrv] beam git commit: ReshuffleTest: replace Iterable
equal tests with matchers.
ReshuffleTest: replace Iterable equal tests with matchers.
Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/e182cf75
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/e182cf75
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/e182cf75
Branch: refs/heads/jstorm-runner
Commit: e182cf75eb3d5a4701a98a2f5687cf0ea9d51774
Parents: 1178f9f
Author: Pei He <pe...@apache.org>
Authored: Wed Jul 19 20:38:49 2017 +0800
Committer: Pei He <pe...@apache.org>
Committed: Sat Aug 19 12:03:00 2017 +0800
----------------------------------------------------------------------
.../beam/sdk/transforms/ReshuffleTest.java | 22 ++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/beam/blob/e182cf75/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/ReshuffleTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/ReshuffleTest.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/ReshuffleTest.java
index 3cd7cf9..0eb8e2d 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/ReshuffleTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/ReshuffleTest.java
@@ -17,7 +17,10 @@
*/
package org.apache.beam.sdk.transforms;
+import static org.apache.beam.sdk.TestUtils.KvMatcher.isKv;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
+import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
@@ -70,9 +73,16 @@ public class ReshuffleTest implements Serializable {
KV.of("k1", 3),
KV.of("k2", 4));
- private static final List<KV<String, Iterable<Integer>>> GROUPED_TESTABLE_KVS = ImmutableList.of(
- KV.of("k1", (Iterable<Integer>) ImmutableList.of(3)),
- KV.of("k2", (Iterable<Integer>) ImmutableList.of(4)));
+ private static class AssertThatHasExpectedContents
+ implements SerializableFunction<Iterable<KV<String, Iterable<Integer>>>, Void> {
+ @Override
+ public Void apply(Iterable<KV<String, Iterable<Integer>>> actual) {
+ assertThat(actual, containsInAnyOrder(
+ isKv(is("k1"), containsInAnyOrder(3)),
+ isKv(is("k2"), containsInAnyOrder(4))));
+ return null;
+ }
+ }
@Rule
public final transient TestPipeline pipeline = TestPipeline.create();
@@ -167,7 +177,7 @@ public class ReshuffleTest implements Serializable {
PCollection<KV<String, Iterable<Integer>>> output = input
.apply(Reshuffle.<String, Iterable<Integer>>of());
- PAssert.that(output).containsInAnyOrder(GROUPED_TESTABLE_KVS);
+ PAssert.that(output).satisfies(new AssertThatHasExpectedContents());
assertEquals(
input.getWindowingStrategy(),
@@ -190,7 +200,7 @@ public class ReshuffleTest implements Serializable {
PCollection<KV<String, Iterable<Integer>>> output = input
.apply(Reshuffle.<String, Iterable<Integer>>of());
- PAssert.that(output).containsInAnyOrder(GROUPED_TESTABLE_KVS);
+ PAssert.that(output).satisfies(new AssertThatHasExpectedContents());
assertEquals(
input.getWindowingStrategy(),
@@ -213,7 +223,7 @@ public class ReshuffleTest implements Serializable {
PCollection<KV<String, Iterable<Integer>>> output = input
.apply(Reshuffle.<String, Iterable<Integer>>of());
- PAssert.that(output).containsInAnyOrder(GROUPED_TESTABLE_KVS);
+ PAssert.that(output).satisfies(new AssertThatHasExpectedContents());
assertEquals(
input.getWindowingStrategy(),