ElementTransformer extends TupleAdaptedFunctionComposite<String> { public Element apply(final Element element) { elementTuple.setElement(element); apply(elementTuple); return element; }  Element apply(final Element element); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString();  }
@Test public void shouldTransformElementUsingMockFunction() { final String selection = "reference1"; final String projection = "reference1"; final Integer valueResult = 3; final Function<String, Integer> function = mock(Function.class); given(function.apply("value1")).willReturn(valueResult); final ElementTransformer transformer = new ElementTransformer.Builder() .select(selection) .execute(function) .project(projection) .build(); final Edge edge = new Edge.Builder() .property(selection, "value1") .build(); final Element result = transformer.apply(edge); assertEquals(valueResult, result.getProperty(projection)); }
@Test public void shouldTransformElementUsingIdentityFunction() { final ElementTransformer transformer = new ElementTransformer.Builder() .select("prop1") .execute(new Identity()) .project("prop3") .build(); final Entity element = new Entity.Builder() .group("test") .property("prop1", "value") .property("prop2", 1) .build(); final Element result = transformer.apply(element); assertEquals(element.getProperty("prop1"), result.getProperty("prop3")); }
@Test public void shouldTransformElementUsingInlineFunction() { final Function<String, Integer> function = String::length; final ElementTransformer transformer = new ElementTransformer.Builder() .select("prop1") .execute(function) .project("prop3") .build(); final Entity element = new Entity.Builder() .group("test") .property("prop1", "value") .property("prop2", 1) .build(); final Element result = transformer.apply(element); assertEquals("prop1".length(), result.getProperty("prop3")); }