package org.xmlunit.assertj;

import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.Assertions;
import org.xmlunit.builder.Input;
import org.xmlunit.validation.JAXPValidator;
import org.xmlunit.validation.Languages;
import org.xmlunit.validation.ValidationResult;

import javax.xml.transform.Source;
import javax.xml.validation.Schema;

public class ValidationAssert extends AbstractAssert<ValidationAssert, Object> {

    private final Source[] schemaSource;
    private final Schema schema;
    private ValidationResult result;

    private ValidationAssert(Object actual, Source[] schemaSource, Schema schema) {
        super(actual, ValidationAssert.class);
        this.schemaSource = schemaSource;
        this.schema = schema;
    }

    static ValidationAssert create(Object xmlSource, Object... schemaSource) {

        Assertions.assertThat(schemaSource)
                .isNotNull()
                .isNotEmpty()
                .doesNotContainNull();

        Source[] sources = new Source[schemaSource.length];

        for (int i = 0; i < schemaSource.length; i++) {
            sources[i] = Input.from(schemaSource[i]).build();
        }

        return new ValidationAssert(xmlSource, sources, null);
    }

    static ValidationAssert create(Object xmlSource, Schema schema) {
        Assertions.assertThat(schema).isNotNull();

        return new ValidationAssert(xmlSource, null, schema);
    }

    private void validate() {
        if (result == null) {
            Source source = Input.from(actual).build();
            JAXPValidator validator = new JAXPValidator(Languages.W3C_XML_SCHEMA_NS_URI);
            if (schema != null) {
                validator.setSchema(schema);
            } else {
                validator.setSchemaSources(schemaSource);
            }
            this.result = validator.validateInstance(source);
        }
    }

    public ValidationAssert isValid() {
        validate();
        if (!result.isValid()) {
            failWithMessage("dupa");
        }
        return this;
    }

    public void isNotValid() {
        validate();
        if (result.isValid()) {
            failWithMessage("dupa");
        }
    }
}

@@ -507,45 +507,8 @@
 ema;
-%0A    private ValidationResult result;
 %0A%0A  
@@ -1405,60 +1405,39 @@
 ate 
-void validate() %7B%0A        if (result == null) %7B%0A    
+ValidationResult validate() %7B%0A%0A
     
@@ -1480,28 +1480,24 @@
 l).build();%0A
-    
         JAXP
@@ -1574,28 +1574,24 @@
 I);%0A        
-  
-  
 if (schema !
@@ -1596,28 +1596,24 @@
  != null) %7B%0A
-    
             
@@ -1649,20 +1649,16 @@
         
-   
- 
 %7D else %7B
@@ -1658,20 +1658,16 @@
  else %7B%0A
-    
         
@@ -1716,28 +1716,24 @@
 e);%0A        
-   
- 
 %7D%0A          
@@ -1734,25 +1734,14 @@
     
-    this.result =
+return
  val
@@ -1769,34 +1769,24 @@
 ce(source);%0A
-        %7D%0A
     %7D%0A%0A    p
@@ -1819,32 +1819,68 @@
 alid() %7B%0A       
+ ValidationResult validationResult =
  validate();%0A   
@@ -1889,17 +1889,27 @@
    if (!
-r
+validationR
 esult.is
@@ -1940,36 +1940,45 @@
 ailWithMessage(%22
-dupa
+error message
 %22);%0A        %7D%0A  
@@ -2037,24 +2037,59 @@
 () %7B%0A       
+  ValidationResult validateResult =
  validate();
@@ -2101,17 +2101,25 @@
     if (
-r
+validateR
 esult.is
@@ -2162,25 +2162,93 @@
 ge(%22
-dupa%22);%0A        %7D
+error message%22);%0A        %7D%0A    %7D%0A%0A    public void isInvalid() %7B%0A        isNotValid();
 %0A   

Remove validation result field