ValidateHandler implements OutputOperationHandler<Validate, Iterable<? extends Element>> { @Override public Iterable<? extends Element> doOperation(final Validate operation, final Context context, final Store store) throws OperationException { return doOperation(operation, store.getSchema()); }  @Override Iterable<? extends Element> doOperation(final Validate operation,
                                                   final Context context, final Store store); Iterable<? extends Element> doOperation(final Validate operation, final Schema schema);  }
@Test public void shouldReturnNullIfElementsAreNull() throws OperationException { final ValidateHandler handler = new ValidateHandler(); final Store store = mock(Store.class); final Validate validate = mock(Validate.class); given(validate.getInput()).willReturn(null); final Context context = new Context(); final Iterable<? extends Element> result = handler.doOperation(validate, context, store); assertNull(result); }
@Test public void shouldValidatedElements() throws OperationException { final ValidateHandler handler = new ValidateHandler(); final Store store = mock(Store.class); final Validate validate = mock(Validate.class); final Element elm1 = mock(Element.class); final Iterable elements = Collections.singletonList(elm1); final Schema schema = mock(Schema.class); final Context context = new Context(); given(validate.getInput()).willReturn(elements); given(validate.isSkipInvalidElements()).willReturn(false); given(store.getSchema()).willReturn(schema); final String group = "group"; given(elm1.getGroup()).willReturn(group); final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class); final ElementFilter validator = mock(ElementFilter.class); given(validator.test(elm1)).willReturn(true); given(elementDef.getValidator(true)).willReturn(validator); given(schema.getElement(group)).willReturn(elementDef); final Iterable<? extends Element> result = handler.doOperation(validate, context, store); final Iterator<? extends Element> itr = result.iterator(); final Element elm1Result = itr.next(); assertSame(elm1, elm1Result); assertFalse(itr.hasNext()); }