@Test public void validateAfterDownload_resultXmlIsInvalid_ValidationException() throws Exception { final AbbyyInput abbyyInput = mock(AbbyyInput.class); final String xml = ""; when(abbyyInput.getResponseCharacterSet()).thenReturn(StandardCharsets.UTF_8.displayName()); SchemaFactory schemaFactoryMock = mock(SchemaFactory.class); PowerMockito.mockStatic(SchemaFactory.class); PowerMockito.when(SchemaFactory.newInstance(anyString())).thenReturn(schemaFactoryMock); StreamSource streamSourceMock = mock(StreamSource.class); PowerMockito.whenNew(StreamSource.class).withAnyArguments().thenReturn(streamSourceMock); Schema schemaMock = mock(Schema.class); when(schemaFactoryMock.newSchema(any(StreamSource.class))).thenReturn(schemaMock); Validator validatorMock = mock(Validator.class); when(schemaMock.newValidator()).thenReturn(validatorMock); doThrow(SAXException.class).when(validatorMock).validate(any(Source.class)); ValidationException ex = this.sut.validateAfterDownload(abbyyInput, xml); assertNotNull(ex); }
@Override public ValidationException validateAfterDownload(@NotNull AbbyyInput abbyyInput, @NotNull String result) throws Exception { try { validateSizeAfterDownload(abbyyInput, result); validateAgainstXsdSchema(abbyyInput, result); return null; } catch (ValidationException ex) { return ex; } }
XmlResultValidator implements AbbyyResultValidator { @Override public ValidationException validateAfterDownload(@NotNull AbbyyInput abbyyInput, @NotNull String result) throws Exception { try { validateSizeAfterDownload(abbyyInput, result); validateAgainstXsdSchema(abbyyInput, result); return null; } catch (ValidationException ex) { return ex; } } }
XmlResultValidator implements AbbyyResultValidator { @Override public ValidationException validateAfterDownload(@NotNull AbbyyInput abbyyInput, @NotNull String result) throws Exception { try { validateSizeAfterDownload(abbyyInput, result); validateAgainstXsdSchema(abbyyInput, result); return null; } catch (ValidationException ex) { return ex; } } XmlResultValidator(@NotNull AbbyyApi abbyyApi, @NotNull String xsdSchemaPath); }
XmlResultValidator implements AbbyyResultValidator { @Override public ValidationException validateAfterDownload(@NotNull AbbyyInput abbyyInput, @NotNull String result) throws Exception { try { validateSizeAfterDownload(abbyyInput, result); validateAgainstXsdSchema(abbyyInput, result); return null; } catch (ValidationException ex) { return ex; } } XmlResultValidator(@NotNull AbbyyApi abbyyApi, @NotNull String xsdSchemaPath); @Override ValidationException validateBeforeDownload(@NotNull AbbyyInput abbyyInput, @NotNull String downloadUrl); @Override ValidationException validateAfterDownload(@NotNull AbbyyInput abbyyInput, @NotNull String result); }
XmlResultValidator implements AbbyyResultValidator { @Override public ValidationException validateAfterDownload(@NotNull AbbyyInput abbyyInput, @NotNull String result) throws Exception { try { validateSizeAfterDownload(abbyyInput, result); validateAgainstXsdSchema(abbyyInput, result); return null; } catch (ValidationException ex) { return ex; } } XmlResultValidator(@NotNull AbbyyApi abbyyApi, @NotNull String xsdSchemaPath); @Override ValidationException validateBeforeDownload(@NotNull AbbyyInput abbyyInput, @NotNull String downloadUrl); @Override ValidationException validateAfterDownload(@NotNull AbbyyInput abbyyInput, @NotNull String result);  }