From 993d1f59e57af315c8495236fd9a37b5a93fe846 Mon Sep 17 00:00:00 2001 From: Pascal Christoph Date: Thu, 27 Jun 2019 10:43:55 +0200 Subject: [PATCH 1/3] Fix collecting lines by appending a line feed Fixes #296. --- .../main/java/org/metafacture/strings/LineRecorder.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/metafacture-strings/src/main/java/org/metafacture/strings/LineRecorder.java b/metafacture-strings/src/main/java/org/metafacture/strings/LineRecorder.java index aaa51c2e6..6e7b55305 100644 --- a/metafacture-strings/src/main/java/org/metafacture/strings/LineRecorder.java +++ b/metafacture-strings/src/main/java/org/metafacture/strings/LineRecorder.java @@ -23,12 +23,14 @@ import org.metafacture.framework.helpers.DefaultObjectPipe; /** - * Joins strings and emits them as records when a line matches the pattern. + * Collects trings and emits them as records when a line matches the pattern. + * Appends to every incoming line a line feed so that the original structure is + * preserved. * * @author Pascal Christoph (dr0i). * */ -@Description("Joins strings and emits them as records when a line matches the pattern.") +@Description("Collects strings and emits them as records when a line matches the pattern.") @In(String.class) @Out(String.class) @FluxCommand("lines-to-records") @@ -50,7 +52,7 @@ public void process(final String line) { getReceiver().process(record.toString()); record = new StringBuilder(SB_CAPACITY); } else - record.append(line); + record.append(line + "\n"); } } From 64e01c6e321f9dcc70db489059f9edb71e6118ac Mon Sep 17 00:00:00 2001 From: Pascal Christoph Date: Thu, 27 Jun 2019 14:38:03 +0200 Subject: [PATCH 2/3] Fix test by proper indication of line separator See #296. --- .../metafacture/strings/LineRecorderTest.java | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/metafacture-strings/src/test/java/org/metafacture/strings/LineRecorderTest.java b/metafacture-strings/src/test/java/org/metafacture/strings/LineRecorderTest.java index 24b997f5b..7573b58de 100644 --- a/metafacture-strings/src/test/java/org/metafacture/strings/LineRecorderTest.java +++ b/metafacture-strings/src/test/java/org/metafacture/strings/LineRecorderTest.java @@ -32,18 +32,20 @@ */ public final class LineRecorderTest { - private static final String RECORD1_PART1 = "a1\n"; - private static final String RECORD1_PART2 = "a2\n"; + private static final String RECORD1_PART1 = "a1"; + private static final String RECORD1_PART2 = "a2"; private static final String RECORD1_ENDMARKER = "\n"; - private static final String RECORD2_PART1 = "b1\n"; - private static final String RECORD2_PART2 = "b2\n"; + private static final String RECORD2_PART1 = "b1"; + private static final String RECORD2_PART2 = "b2"; private static final String RECORD2_ENDMARKER = "\n"; - private static final String RECORD3_PART1 = "c1\n"; - private static final String RECORD3_PART2 = "c2\n"; + private static final String RECORD3_PART1 = "c1"; + private static final String RECORD3_PART2 = "c2"; private static final String RECORD3_ENDMARKER = "EOR"; + private static final String LINE_SEPARATOR = "\n"; + private LineRecorder lineRecorder; @Mock @@ -63,13 +65,21 @@ public void shouldEmitRecords() { lineRecorder.process(RECORD1_ENDMARKER); final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).process(RECORD1_PART1 + RECORD1_PART2); + ordered.verify(receiver).process( + RECORD1_PART1 + + LINE_SEPARATOR + + RECORD1_PART2 + + LINE_SEPARATOR); lineRecorder.process(RECORD2_PART1); lineRecorder.process(RECORD2_PART2); lineRecorder.process(RECORD2_ENDMARKER); - ordered.verify(receiver).process(RECORD2_PART1 + RECORD2_PART2); + ordered.verify(receiver).process( + RECORD2_PART1 + + LINE_SEPARATOR + + RECORD2_PART2 + + LINE_SEPARATOR); ordered.verifyNoMoreInteractions(); } @@ -81,7 +91,11 @@ public void shouldEmitRecordWithNonDefaultRecordMarker() { lineRecorder.process(RECORD3_ENDMARKER); final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).process(RECORD3_PART1 + RECORD3_PART2); + ordered.verify(receiver).process( + RECORD3_PART1 + + LINE_SEPARATOR + + RECORD3_PART2 + + LINE_SEPARATOR); ordered.verifyNoMoreInteractions(); } From b1a603f5df5b0a863c87e9ea8b6c1a49d33443f2 Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Thu, 27 Jun 2019 16:12:09 +0200 Subject: [PATCH 3/3] Fix typo See https://github.com/metafacture/metafacture-core/issues/296 --- .../src/main/java/org/metafacture/strings/LineRecorder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metafacture-strings/src/main/java/org/metafacture/strings/LineRecorder.java b/metafacture-strings/src/main/java/org/metafacture/strings/LineRecorder.java index 6e7b55305..588353d61 100644 --- a/metafacture-strings/src/main/java/org/metafacture/strings/LineRecorder.java +++ b/metafacture-strings/src/main/java/org/metafacture/strings/LineRecorder.java @@ -23,7 +23,7 @@ import org.metafacture.framework.helpers.DefaultObjectPipe; /** - * Collects trings and emits them as records when a line matches the pattern. + * Collects strings and emits them as records when a line matches the pattern. * Appends to every incoming line a line feed so that the original structure is * preserved. *