Skip to content

Commit 74cc0bd

Browse files
committed
perf: use equal byte-by-byte comparison [Google Guava library]
Signed-off-by: Samir Romdhani <samir.romdhani_externe@rte-france.com>
1 parent 9b933b6 commit 74cc0bd

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

commons-test/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,9 @@
6464
<artifactId>slf4j-api</artifactId>
6565
<scope>compile</scope>
6666
</dependency>
67+
<dependency>
68+
<groupId>commons-io</groupId>
69+
<artifactId>commons-io</artifactId>
70+
</dependency>
6771
</dependencies>
6872
</project>

commons-test/src/main/java/com/powsybl/commons/test/ComparisonUtils.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
package com.powsybl.commons.test;
99

1010
import com.google.common.io.ByteStreams;
11+
import org.apache.commons.io.FileUtils;
1112
import org.slf4j.Logger;
1213
import org.slf4j.LoggerFactory;
13-
import org.xmlunit.builder.DiffBuilder;
14-
import org.xmlunit.diff.Diff;
1514

1615
import java.io.*;
1716
import java.nio.charset.StandardCharsets;
@@ -33,12 +32,24 @@ private ComparisonUtils() {
3332
}
3433

3534
public static void assertXmlEquals(InputStream expected, InputStream actual) {
35+
/*
3636
Diff myDiff = DiffBuilder.compare(expected).withTest(actual).ignoreWhitespace().ignoreComments().build();
3737
boolean hasDiff = myDiff.hasDifferences();
3838
if (hasDiff) {
3939
LOGGER.error("{}", myDiff);
4040
}
4141
assertFalse(hasDiff);
42+
*/
43+
try {
44+
File expectedFile = new File("expectedFile.xml");
45+
FileUtils.copyInputStreamToFile(expected, expectedFile);
46+
File actualFile = new File("actualFile.xml");
47+
FileUtils.copyInputStreamToFile(actual, actualFile);
48+
//Returns true if the files contains the same bytes.
49+
com.google.common.io.Files.equal(actualFile, expectedFile);
50+
} catch (IOException e) {
51+
throw new UncheckedIOException(e);
52+
}
4253
}
4354

4455
public static void assertTxtEquals(Path expected, Path actual) {

0 commit comments

Comments
 (0)