ToVerticesHandler implements OutputOperationHandler<ToVertices, Iterable<? extends Object>> { @Override public Iterable<Object> doOperation(final ToVertices operation, final Context context, final Store store) throws OperationException { if (null == operation.getInput()) { return null; } return new StreamFlatMapIterable<>(operation.getInput(), elementIdsToVertices(operation)); }  @Override Iterable<Object> doOperation(final ToVertices operation, final Context context, final Store store);  }
@Test public void shouldCorrectlyConvertEdgeSeedsWithEqualUseMatchedVertex() throws OperationException { final List elementIds = Arrays.asList( new EdgeSeed(vertex1, vertex2, false, null), new EdgeSeed(vertex3, vertex4, false, null), new EdgeSeed(vertex5, vertex6, false, null), new EdgeSeed(vertex7, vertex8, false, null)); final ToVerticesHandler handler = new ToVerticesHandler(); final ToVertices operation = mock(ToVertices.class); given(operation.getInput()).willReturn(elementIds); given(operation.getUseMatchedVertex()).willReturn(ToVertices.UseMatchedVertex.EQUAL); final Iterable<Object> results = handler.doOperation(operation, new Context(), null); assertThat(Sets.newHashSet(results), containsInAnyOrder(vertex1, vertex3, vertex5, vertex7)); }
@Test public void shouldCorrectlyConvertEdgeSeedsWithOppositeUseMatchedVertex() throws OperationException { final List elementIds = Arrays.asList( new EdgeSeed(vertex1, vertex2, false, null), new EdgeSeed(vertex3, vertex4, false, null), new EdgeSeed(vertex5, vertex6, false, null), new EdgeSeed(vertex7, vertex8, false, null)); final ToVerticesHandler handler = new ToVerticesHandler(); final ToVertices operation = mock(ToVertices.class); given(operation.getInput()).willReturn(elementIds); given(operation.getUseMatchedVertex()).willReturn(ToVertices.UseMatchedVertex.OPPOSITE); final Iterable<Object> results = handler.doOperation(operation, new Context(), null); assertThat(Sets.newHashSet(results), containsInAnyOrder(vertex2, vertex4, vertex6, vertex8)); }
@Test public void shouldCorrectlyConvertEdgeSeedsWithNoneUseMatchedVertex() throws OperationException { final List elementIds = Arrays.asList( new EdgeSeed(vertex1, vertex2, false, null), new EdgeSeed(vertex3, vertex4, false, null), new EdgeSeed(vertex5, vertex6, false, null), new EdgeSeed(vertex7, vertex8, false, null)); final ToVerticesHandler handler = new ToVerticesHandler(); final ToVertices operation = mock(ToVertices.class); given(operation.getInput()).willReturn(elementIds); given(operation.getUseMatchedVertex()).willReturn(ToVertices.UseMatchedVertex.IGNORE); final Iterable<Object> results = handler.doOperation(operation, new Context(), null); assertThat(Sets.newHashSet(results), is(empty())); }