]> source.dussan.org Git - poi.git/commitdiff
use xmlunit for xml diffs in unit tests
authorPJ Fanning <fanningpj@apache.org>
Sun, 4 Mar 2018 12:24:44 +0000 (12:24 +0000)
committerPJ Fanning <fanningpj@apache.org>
Sun, 4 Mar 2018 12:24:44 +0000 (12:24 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1825810 13f79535-47bb-0310-9956-ffa450edef68

.classpath
build.gradle
build.xml
gradle/wrapper/gradle-wrapper.jar
sonar/pom.xml
src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestXDDFColor.java

index 7098e327662fb16d43ea9b9a8268d628ba3482a8..944cd2142bf82d04ba4253aea299cd2ca1de7c97 100644 (file)
@@ -35,6 +35,7 @@
        <classpathentry exported="true" kind="lib" path="lib/commons-logging-1.2.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/commons-collections4-4.1.jar"/>
        <classpathentry kind="lib" path="lib/commons-math3-3.6.1.jar"/>
+       <classpathentry kind="lib" path="lib/xmlunit-core-2.5.1.jar"/>
        <classpathentry kind="lib" path="lib/mockito-core-2.13.0.jar"/>
        <classpathentry kind="lib" path="lib/byte-buddy-1.7.9.jar"/>
        <classpathentry kind="lib" path="lib/byte-buddy-agent-1.7.9.jar"/>
index 5811fe43bcac247f90406ea828d49f138a677af9..1ec30a74413a7b959fa64e699abd022002edaebb 100644 (file)
@@ -206,6 +206,7 @@ project('ooxml') {
                
                testCompile 'junit:junit:4.12'
                testCompile 'org.mockito:mockito-core:2.13.0'
+               testCompile 'org.xmlunit:xmlunit-core:2.5.1'
                testCompile project(path: ':main', configuration: 'tests')
                testCompile 'org.openjdk.jmh:jmh-core:1.19'
                testCompile 'org.openjdk.jmh:jmh-generator-annprocess:1.19'
index 670585b736033f50c8ce8f89f1d86a8323fe151c..57d13c3ed9ff4114acc084719658485cce709fc1 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -164,6 +164,8 @@ under the License.
 
     <property name="main.hamcrest.jar" location="${main.lib}/hamcrest-core-1.3.jar"/>
     <property name="main.hamcrest.url" value="${repository.m2}/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"/>
+    <property name="main.xmlunit.jar" location="${main.lib}/xmlunit-core-2.5.1.jar"/>
+    <property name="main.xmlunit.url" value="${repository.m2}/maven2/org/xmlunit/xmlunit-core/2.5.1/xmlunit-core-2.5.1.jar"/>
     <property name="main.mockito.jar" location="${main.lib}/mockito-core-2.13.0.jar"/>
     <property name="main.mockito.url" value="${repository.m2}/maven2/org/mockito/mockito-core/2.13.0/mockito-core-2.13.0.jar"/>
     <property name="main.byte-buddy.jar" location="${main.lib}/byte-buddy-1.7.9.jar"/>
@@ -325,6 +327,7 @@ under the License.
         <pathelement location="${main.jmh.jar}"/>
         <pathelement location="${main.jmhAnnotation.jar}"/>
         <pathelement location="${main.hamcrest.jar}"/>
+        <pathelement location="${main.xmlunit.jar}"/>
         <pathelement location="${main.mockito.jar}"/>
         <pathelement location="${main.byte-buddy.jar}"/>
         <pathelement location="${main.byte-buddy-agent.jar}"/>
@@ -632,6 +635,7 @@ under the License.
                     <available file="${main.jmh.jar}"/>
                     <available file="${main.jmhAnnotation.jar}"/>
                     <available file="${main.hamcrest.jar}"/>
+                    <available file="${main.xmlunit.jar}"/>
                     <available file="${main.mockito.jar}"/>
                     <available file="${main.byte-buddy.jar}"/>
                     <available file="${main.byte-buddy-agent.jar}"/>
@@ -667,6 +671,7 @@ under the License.
         <downloadfile src="${main.jmh.url}" dest="${main.jmh.jar}"/>
         <downloadfile src="${main.jmhAnnotation.url}" dest="${main.jmhAnnotation.jar}"/>
         <downloadfile src="${main.hamcrest.url}" dest="${main.hamcrest.jar}"/>
+        <downloadfile src="${main.xmlunit.url}" dest="${main.xmlunit.jar}"/>
         <downloadfile src="${main.mockito.url}" dest="${main.mockito.jar}"/>
         <downloadfile src="${main.byte-buddy.url}" dest="${main.byte-buddy.jar}"/>
         <downloadfile src="${main.byte-buddy-agent.url}" dest="${main.byte-buddy-agent.jar}"/>
index 219c335356cc4a39e1c7cd3fa5261637d4893930..feef4e75785b9342f1ed3be2f04e798330bfe58a 100644 (file)
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
index 1022d2107be1a6a4f2b7e1d3a0a5ee3e6d0beb43..50a1b3fb057052b3c25545e0e0002f63e34470cb 100644 (file)
@@ -65,6 +65,7 @@
                <!-- define some of the third-party or plugin-versions globally to use the same in all modules -->
                <xmlbeans.version>2.6.0</xmlbeans.version>
                <junit.version>4.12</junit.version>
+               <xmlunit.version>2.5.1</xmlunit.version>
                <mockito.version>2.13.0</mockito.version>
                <maven.plugin.resources.version>3.0.1</maven.plugin.resources.version>
                <maven.plugin.jar.version>3.0.1</maven.plugin.jar.version>
                        <version>${junit.version}</version>
                        <scope>test</scope>
                </dependency>
+               <dependency>
+                       <groupId>org.xmlunit</groupId>
+                       <artifactId>xmlunit-core</artifactId>
+                       <version>${xmlunit.version}</version>
+                       <scope>test</scope>
+               </dependency>
                <dependency>
                        <groupId>org.mockito</groupId>
                        <artifactId>mockito-core</artifactId>
index 989313ae19d507e4e14fae86b6a0c9337bbbcfce..156133ad62913328ec4ef0efe7f5ea6486b41382 100644 (file)
@@ -18,6 +18,7 @@
 package org.apache.poi.xddf.usermodel;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 
 import java.io.IOException;
 
@@ -31,26 +32,34 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor;
 import org.openxmlformats.schemas.drawingml.x2006.main.STPresetColorVal;
 import org.openxmlformats.schemas.drawingml.x2006.main.STSchemeColorVal;
 import org.openxmlformats.schemas.drawingml.x2006.main.STSystemColorVal;
+import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.builder.Input;
+import org.xmlunit.diff.Diff;
 
 public class TestXDDFColor {
     private static final String XMLNS = "xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"/>";
 
     @Test
     public void testSchemeColor() throws IOException {
-        XMLSlideShow ppt = new XMLSlideShow();
-        XSLFTheme theme = ppt.createSlide().getTheme();
-
-        XDDFColor color = XDDFColor.forColorContainer(getThemeColor(theme, STSchemeColorVal.ACCENT_2));
-        // accent2 in theme1.xml is <a:srgbClr val="C0504D"/>
-        assertEquals("<a:srgbClr val=\"C0504D\" " + XMLNS, color.getColorContainer().toString());
-
-        color = XDDFColor.forColorContainer(getThemeColor(theme, STSchemeColorVal.LT_1));
-        assertEquals("<a:sysClr lastClr=\"FFFFFF\" val=\"window\" " + XMLNS, color.getColorContainer().toString());
-
-        color = XDDFColor.forColorContainer(getThemeColor(theme, STSchemeColorVal.DK_1));
-        assertEquals("<a:sysClr lastClr=\"000000\" val=\"windowText\" " + XMLNS, color.getColorContainer().toString());
-
-        ppt.close();
+        try (XMLSlideShow ppt = new XMLSlideShow()) {
+            XSLFTheme theme = ppt.createSlide().getTheme();
+
+            XDDFColor color = XDDFColor.forColorContainer(getThemeColor(theme, STSchemeColorVal.ACCENT_2));
+            // accent2 in theme1.xml is <a:srgbClr val="C0504D"/>
+            Diff d1 = DiffBuilder.compare(Input.fromString("<a:srgbClr val=\"C0504D\" " + XMLNS))
+                    .withTest(color.getColorContainer().toString()).build();
+            assertFalse(d1.toString(), d1.hasDifferences());
+
+            color = XDDFColor.forColorContainer(getThemeColor(theme, STSchemeColorVal.LT_1));
+            Diff d2 = DiffBuilder.compare(Input.fromString("<a:sysClr lastClr=\"FFFFFF\" val=\"window\" " + XMLNS))
+                    .withTest(color.getColorContainer().toString()).build();
+            assertFalse(d2.toString(), d2.hasDifferences());
+
+            color = XDDFColor.forColorContainer(getThemeColor(theme, STSchemeColorVal.DK_1));
+            Diff d3 = DiffBuilder.compare(Input.fromString("<a:sysClr lastClr=\"000000\" val=\"windowText\" " + XMLNS))
+                    .withTest(color.getColorContainer().toString()).build();
+            assertFalse(d3.toString(), d3.hasDifferences());
+        }
     }
 
     private CTColor getThemeColor(XSLFTheme theme, STSchemeColorVal.Enum value) {