ToEntitySeedsHandler implements OutputOperationHandler<ToEntitySeeds, Iterable<? extends EntitySeed>> { @Override public Iterable<EntitySeed> doOperation(final ToEntitySeeds operation, final Context context, final Store store) throws OperationException { if (null == operation.getInput()) { return null; } return new StreamMapIterable<>( operation.getInput(), seed -> seed instanceof EntitySeed ? ((EntitySeed) seed) : new EntitySeed(seed) ); }  @Override Iterable<EntitySeed> doOperation(final ToEntitySeeds operation, final Context context, final Store store);  }
@Test public void shouldConvertVerticesToEntitySeeds() throws OperationException { final Object vertex1 = "vertex1"; final Object vertex2 = "vertex2"; final Iterable originalResults = new WrappedCloseableIterable<>(Arrays.asList(vertex1, vertex2)); final ToEntitySeedsHandler handler = new ToEntitySeedsHandler(); final ToEntitySeeds operation = mock(ToEntitySeeds.class); given(operation.getInput()).willReturn(originalResults); final Iterable<EntitySeed> results = handler.doOperation(operation, new Context(), null); assertThat(results, containsInAnyOrder(new EntitySeed(vertex1), new EntitySeed(vertex2))); }
@Test public void shouldBeAbleToIterableOverTheResultsMultipleTimes() throws OperationException { final Object vertex1 = "vertex1"; final Object vertex2 = "vertex2"; final Iterable originalResults = new WrappedCloseableIterable<>(Arrays.asList(vertex1, vertex2)); final ToEntitySeedsHandler handler = new ToEntitySeedsHandler(); final ToEntitySeeds operation = mock(ToEntitySeeds.class); given(operation.getInput()).willReturn(originalResults); final Iterable<EntitySeed> results = handler.doOperation(operation, new Context(), null); final Set<Object> set1 = Sets.newHashSet(results); final Set<Object> set2 = Sets.newHashSet(results); assertEquals(Sets.newHashSet(new EntitySeed(vertex1), new EntitySeed(vertex2)), set1); assertEquals(set1, set2); }
@Test public void shouldHandleNullInput() throws OperationException { final ToEntitySeedsHandler handler = new ToEntitySeedsHandler(); final ToEntitySeeds operation = mock(ToEntitySeeds.class); given(operation.getInput()).willReturn(null); final Iterable<EntitySeed> results = handler.doOperation(operation, new Context(), null); assertThat(results, is(nullValue())); }