You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2022/07/13 06:57:35 UTC

[uima-uimaj] 01/01: [#222] Support comparing test files irrespective of line endings

This is an automated email from the ASF dual-hosted git repository.

rec pushed a commit to branch feature/222-Support-comparing-test-files-irrespective-of-line-endings
in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git

commit 6db34ef232e81746a013c39c356c14f709324a84
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Wed Jul 13 08:57:29 2022 +0200

    [#222] Support comparing test files irrespective of line endings
    
    - Added `SerDesCasIOTestUtils.roundTripDesSerScenariosComparingFileContentsNormalizingNewlines`
---
 .../uima/cas/serdes/SerDesCasIOTestUtils.java      | 25 ++++++++++++++++++++++
 .../cas/serdes/scenario/DesSerTestScenario.java    |  6 ++++++
 2 files changed, 31 insertions(+)

diff --git a/uimaj-core/src/test/java/org/apache/uima/cas/serdes/SerDesCasIOTestUtils.java b/uimaj-core/src/test/java/org/apache/uima/cas/serdes/SerDesCasIOTestUtils.java
index 2c4b9cc5e..717f4500a 100644
--- a/uimaj-core/src/test/java/org/apache/uima/cas/serdes/SerDesCasIOTestUtils.java
+++ b/uimaj-core/src/test/java/org/apache/uima/cas/serdes/SerDesCasIOTestUtils.java
@@ -127,6 +127,31 @@ public class SerDesCasIOTestUtils {
     return confs;
   }
 
+  /**
+   * DESERIALIZE -> SERIALIZE scenarios using the reference data from the
+   * serialize/compare-to-reference data.
+   */
+  public static List<DesSerTestScenario> roundTripDesSerScenariosComparingFileContentsNormalizingNewlines(
+          Collection<CasDesSerCycleConfiguration> aDesSerCycles, String aCasFileName)
+          throws Exception {
+    Class<?> caller = getCallerClass();
+
+    List<DesSerTestScenario> confs = new ArrayList<>();
+
+    for (CasDesSerCycleConfiguration cycle : aDesSerCycles) {
+      try (Stream<DesSerTestScenario.Builder> builders = DesSerTestScenario.builderCases(caller,
+              cycle, ROUND_TRIP, aCasFileName)) {
+
+        builders.map(builder -> builder.withCycle(cycle::performCycle)
+                .withAssertion(DesSerTestScenario::assertFileContentsAreEqualNormalizingNewlines)
+                .build()) //
+                .forEach(confs::add);
+      }
+    }
+
+    return confs;
+  }
+
   /**
    * DESERIALIZE -> SERIALIZE scenarios using the reference data from the
    * serialize/compare-to-reference data.
diff --git a/uimaj-core/src/test/java/org/apache/uima/cas/serdes/scenario/DesSerTestScenario.java b/uimaj-core/src/test/java/org/apache/uima/cas/serdes/scenario/DesSerTestScenario.java
index 8c896cc3d..bf8c7f54e 100644
--- a/uimaj-core/src/test/java/org/apache/uima/cas/serdes/scenario/DesSerTestScenario.java
+++ b/uimaj-core/src/test/java/org/apache/uima/cas/serdes/scenario/DesSerTestScenario.java
@@ -121,6 +121,12 @@ public class DesSerTestScenario implements Runnable {
     assertThat(contentOf(aTargetCasFile.toFile())).isEqualTo(contentOf(aReferenceCasFile.toFile()));
   }
 
+  public static void assertFileContentsAreEqualNormalizingNewlines(Path aTargetCasFile,
+          Path aReferenceCasFile) {
+    assertThat(contentOf(aTargetCasFile.toFile()))
+            .isEqualToNormalizingNewlines(contentOf(aReferenceCasFile.toFile()));
+  }
+
   /**
    * Builder to build {@link DesSerTestScenario}.
    */