ToMapHandler implements OutputOperationHandler<ToMap, Iterable<? extends Map<String, Object>>> { @Override public Iterable<? extends Map<String, Object>> doOperation(final ToMap operation, final Context context, final Store store) throws OperationException { if (null == operation.getInput()) { return null; } return operation.getElementGenerator().apply(operation.getInput()); }  @Override Iterable<? extends Map<String, Object>> doOperation(final ToMap operation, final Context context, final Store store);  }
@Test public void shouldConvertElementToMap() throws OperationException { final Entity entity = new Entity.Builder().group(TestGroups.ENTITY) .vertex(1) .build(); final Map<String, Object> originalMap = new HashMap<>(1); originalMap.put("group", TestGroups.ENTITY); originalMap.put("vertex", 1); final MapGenerator generator = new MapGenerator.Builder() .group("group") .vertex("vertex") .source("source") .destination("destination") .build(); final Iterable originalResults = new WrappedCloseableIterable<>(Collections.singleton(entity)); final ToMapHandler handler = new ToMapHandler(); final ToMap operation = mock(ToMap.class); given(operation.getInput()).willReturn(originalResults); given(operation.getElementGenerator()).willReturn(generator); final Iterable<? extends Map<String, Object>> results = handler.doOperation(operation, new Context(), null); assertThat(results, contains(originalMap)); }
@Test public void shouldHandleNullInput() throws OperationException { final ToMapHandler handler = new ToMapHandler(); final ToMap operation = mock(ToMap.class); given(operation.getInput()).willReturn(null); final Iterable<? extends Map<String, Object>> results = handler.doOperation(operation, new Context(), null); assertThat(results, is(nullValue())); }