use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.
the class NotTest method shouldAcceptTheValueWhenTheWrappedFunctionReturnsTrue.
@Test
public void shouldAcceptTheValueWhenTheWrappedFunctionReturnsTrue() {
// Given
final FilterFunction function = mock(FilterFunction.class);
final Not filter = new Not(function);
final Object[] input = new Object[] { "some value" };
given(function.isValid(input)).willReturn(true);
// When
boolean accepted = filter.isValid(input);
// Then
assertFalse(accepted);
verify(function).isValid(input);
}
use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.
the class NotTest method shouldClone.
@Test
public void shouldClone() {
// Given
final FilterFunction function = mock(FilterFunction.class);
final FilterFunction clonedFunction = mock(FilterFunction.class);
final Not filter = new Not(function);
given(function.statelessClone()).willReturn(clonedFunction);
// When
final Not clonedFilter = filter.statelessClone();
// Then
assertNotSame(filter, clonedFilter);
assertSame(clonedFunction, clonedFilter.getFunction());
}
use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.
the class OrTest method shouldAcceptWhenOneFunctionsAccepts.
@Test
public void shouldAcceptWhenOneFunctionsAccepts() {
// Given
final String test = "test";
final String test1a = "test1a";
final String test1b = "test1b";
final String test2a = "test2a";
final ConsumerFunctionContext<Integer, FilterFunction> funcContext1 = mock(ConsumerFunctionContext.class);
final ConsumerFunctionContext<Integer, FilterFunction> funcContext2 = mock(ConsumerFunctionContext.class);
final FilterFunction func1 = mock(FilterFunction.class);
final FilterFunction func2 = mock(FilterFunction.class);
final Or or = new Or(Arrays.asList(funcContext1, funcContext2));
given(funcContext1.getFunction()).willReturn(func1);
given(funcContext2.getFunction()).willReturn(func2);
given(funcContext1.select(Mockito.any(ArrayTuple.class))).willReturn(new Object[] { test, test1a, test1b });
given(funcContext2.select(Mockito.any(ArrayTuple.class))).willReturn(new Object[] { test, test2a });
given(func1.isValid(new String[] { test, test1a, test1b })).willReturn(true);
given(func2.isValid(new String[] { test, test2a })).willReturn(false);
// When
boolean accepted = or.isValid(new String[] { test, test1a, test2a, test1b });
// Then
assertTrue(accepted);
verify(func1).isValid(new String[] { test, test1a, test1b });
verify(func2, never()).isValid(new String[] { test, test2a });
}
use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.
the class OrTest method shouldClone.
@Test
public void shouldClone() {
// Given
final ConsumerFunctionContext<Integer, FilterFunction> funcContext1 = mock(ConsumerFunctionContext.class);
final ConsumerFunctionContext<Integer, FilterFunction> funcContext2 = mock(ConsumerFunctionContext.class);
final FilterFunction func1 = mock(FilterFunction.class);
final FilterFunction func2 = mock(FilterFunction.class);
final FilterFunction func1Cloned = mock(FilterFunction.class);
final FilterFunction func2Cloned = mock(FilterFunction.class);
final Or or = new Or(Arrays.asList(funcContext1, funcContext2));
given(funcContext1.getFunction()).willReturn(func1);
given(funcContext2.getFunction()).willReturn(func2);
given(funcContext1.getSelection()).willReturn(Arrays.asList(0, 1, 3));
given(funcContext2.getSelection()).willReturn(Arrays.asList(0, 2));
given(func1.statelessClone()).willReturn(func1Cloned);
given(func2.statelessClone()).willReturn(func2Cloned);
// When
final Or clonedOr = or.statelessClone();
// Then
assertNotSame(or, clonedOr);
assertNotNull(clonedOr);
assertEquals(2, clonedOr.getFunctions().size());
assertSame(func1Cloned, clonedOr.getFunctions().get(0).getFunction());
assertArrayEquals(new Integer[] { 0, 1, 3 }, clonedOr.getFunctions().get(0).getSelection().toArray());
assertSame(func2Cloned, clonedOr.getFunctions().get(1).getFunction());
assertArrayEquals(new Integer[] { 0, 2 }, clonedOr.getFunctions().get(1).getSelection().toArray());
}
use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.
the class OrTest method shouldRejectWhenAllFunctionsReject.
@Test
public void shouldRejectWhenAllFunctionsReject() {
// Given
final String test = "test";
final String test1a = "test1a";
final String test1b = "test1b";
final String test2a = "test2a";
final ConsumerFunctionContext<Integer, FilterFunction> funcContext1 = mock(ConsumerFunctionContext.class);
final ConsumerFunctionContext<Integer, FilterFunction> funcContext2 = mock(ConsumerFunctionContext.class);
final ConsumerFunctionContext<Integer, FilterFunction> funcContext3 = mock(ConsumerFunctionContext.class);
final FilterFunction func1 = mock(FilterFunction.class);
final FilterFunction func2 = mock(FilterFunction.class);
final FilterFunction func3 = mock(FilterFunction.class);
final Or or = new Or(Arrays.asList(funcContext1, funcContext2, funcContext3));
given(funcContext1.getFunction()).willReturn(func1);
given(funcContext2.getFunction()).willReturn(func2);
given(funcContext3.getFunction()).willReturn(func3);
given(funcContext1.select(Mockito.any(ArrayTuple.class))).willReturn(new Object[] { test, test1a, test1b });
given(funcContext2.select(Mockito.any(ArrayTuple.class))).willReturn(new Object[] { test, test2a });
given(funcContext3.select(Mockito.any(ArrayTuple.class))).willReturn(new Object[] { test });
given(func1.isValid(new String[] { test, test1a, test1b })).willReturn(false);
given(func2.isValid(new String[] { test, test2a })).willReturn(false);
given(func3.isValid(new String[] { test })).willReturn(false);
// When
boolean accepted = or.isValid(new String[] { test, test1a, test2a, test1b });
// Then
assertFalse(accepted);
verify(func1).isValid(new String[] { test, test1a, test1b });
verify(func2).isValid(new String[] { test, test2a });
verify(func3, never()).isValid(new String[] { test, test2a });
}
Aggregations