@Test @Category(NeedsRunner.class) public void testFindAllGroups() { PCollection<List<String>> output = p.apply(Create.of("aj", "xjx", "yjy", "zjz")).apply(Regex.findAll("([xyz])j([xyz])")); PAssert.that(output) .containsInAnyOrder( Arrays.asList("xjx", "x", "x"), Arrays.asList("yjy", "y", "y"), Arrays.asList("zjz", "z", "z")); p.run(); }
@Test @Category(NeedsRunner.class) public void testAllMatches() { PCollection<List<String>> output = p.apply(Create.of("a x", "x x", "y y", "z z")).apply(Regex.allMatches("([xyz]) ([xyz])")); PAssert.that(output) .containsInAnyOrder( Arrays.asList("x x", "x", "x"), Arrays.asList("y y", "y", "y"), Arrays.asList("z z", "z", "z")); p.run(); }
/** Tests that Pipeline supports a pass-through identity function. */ @Test @Category(ValidatesRunner.class) public void testIdentityTransform() { PCollection<Integer> output = pipeline.apply(Create.of(1, 2, 3, 4)).apply("IdentityTransform", new IdentityTransform<>()); PAssert.that(output).containsInAnyOrder(1, 2, 3, 4); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testToStringOf() { Integer[] ints = {1, 2, 3, 4, 5}; String[] strings = {"1", "2", "3", "4", "5"}; PCollection<Integer> input = p.apply(Create.of(Arrays.asList(ints))); PCollection<String> output = input.apply(ToString.elements()); PAssert.that(output).containsInAnyOrder(strings); p.run(); }
@Test @Category(NeedsRunner.class) public void testSplits() { PCollection<String> output = p.apply(Create.of("The quick brown fox jumps over the lazy dog")) .apply(Regex.split("\\W+")); PAssert.that(output) .containsInAnyOrder("The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"); p.run(); }
@Test @Category(NeedsRunner.class) public void testSplitsWithEmpty() { PCollection<String> output = p.apply(Create.of("The quick brown fox jumps over the lazy dog")) .apply(Regex.split("\\s", true)); PAssert.that(output) .containsInAnyOrder( "The", "", "quick", "brown", "", "", "fox", "jumps", "over", "", "", "", "the", "lazy", "dog"); p.run(); }