use of uk.gov.gchq.gaffer.data.element.ElementTuple in project Gaffer by gchq.
the class ElementFilterTest method shouldWrapElementInElementTupleAndCallSuper.
@Test
public void shouldWrapElementInElementTupleAndCallSuper() {
// Given
final String reference = "reference1";
final String value = "value";
final ElementFilter filter = new ElementFilter();
final ConsumerFunctionContext<String, FilterFunction> functionContext1 = mock(ConsumerFunctionContext.class);
final FilterFunction function = mock(FilterFunction.class);
given(functionContext1.getFunction()).willReturn(function);
filter.addFunction(functionContext1);
final Element element = mock(Element.class);
given(element.getProperty(reference)).willReturn(value);
final ArgumentCaptor<ElementTuple> elementTupleCaptor = ArgumentCaptor.forClass(ElementTuple.class);
given(functionContext1.select(elementTupleCaptor.capture())).willReturn(new Object[] { value });
// When
filter.filter(element);
// Then
assertSame(element, elementTupleCaptor.getValue().getElement());
verify(functionContext1).getFunction();
final ArgumentCaptor<Object[]> argumentCaptor = ArgumentCaptor.forClass(Object[].class);
verify(function).isValid(argumentCaptor.capture());
assertEquals(value, argumentCaptor.getValue()[0]);
}
use of uk.gov.gchq.gaffer.data.element.ElementTuple in project Gaffer by gchq.
the class ElementTransformerTest method shouldWrapElementInElementTupleAndCallSuper.
@Test
public void shouldWrapElementInElementTupleAndCallSuper() {
// Given
final String reference = "reference1";
final String value = "value";
final ElementTransformer transformer = new ElementTransformer();
final ConsumerProducerFunctionContext<String, TransformFunction> functionContext1 = mock(ConsumerProducerFunctionContext.class);
final TransformFunction function = mock(TransformFunction.class);
given(functionContext1.getFunction()).willReturn(function);
transformer.addFunction(functionContext1);
final Element element = mock(Element.class);
given(element.getProperty(reference)).willReturn(value);
final ArgumentCaptor<ElementTuple> elementTupleCaptor = ArgumentCaptor.forClass(ElementTuple.class);
given(functionContext1.select(elementTupleCaptor.capture())).willReturn(new Object[] { value });
// When
transformer.transform(element);
// Then
assertSame(element, elementTupleCaptor.getValue().getElement());
verify(functionContext1).getFunction();
final ArgumentCaptor<Object[]> argumentCaptor = ArgumentCaptor.forClass(Object[].class);
verify(function).transform(argumentCaptor.capture());
assertEquals(value, argumentCaptor.getValue()[0]);
}
Aggregations