diff --git a/src/main/java/com/qoomon/banking/swift/submessage/field/SwiftFieldReader.java b/src/main/java/com/qoomon/banking/swift/submessage/field/SwiftFieldReader.java index 3bfb1c7..762a81f 100644 --- a/src/main/java/com/qoomon/banking/swift/submessage/field/SwiftFieldReader.java +++ b/src/main/java/com/qoomon/banking/swift/submessage/field/SwiftFieldReader.java @@ -91,7 +91,7 @@ public GeneralField readField() throws FieldParseException { contentBuilder.toString() ); } catch (FieldParseException e) { - throw e; + throw e; } catch (Exception e) { throw new FieldParseException(e.getMessage(), getFieldLineNumber(), e); } @@ -111,7 +111,10 @@ private FieldLineType determineMessageLineType(String messageLine) { return FieldLineType.SEPARATOR; } if (messageLine.startsWith(":")) { - return FieldLineType.FIELD; + Matcher tagMatcher = FIELD_STRUCTURE_PATTERN.matcher(messageLine); + if (tagMatcher.matches() && tagMatcher.group("tag") != null) { + return FieldLineType.FIELD; + } } return FieldLineType.FIELD_CONTINUATION; diff --git a/src/test/java/com/qoomon/banking/swift/submessage/field/StatementLineTest.java b/src/test/java/com/qoomon/banking/swift/submessage/field/StatementLineTest.java index d8a89c4..6d1c8d4 100644 --- a/src/test/java/com/qoomon/banking/swift/submessage/field/StatementLineTest.java +++ b/src/test/java/com/qoomon/banking/swift/submessage/field/StatementLineTest.java @@ -28,9 +28,9 @@ public void of() throws Exception { assertThat(field.getTag()).isEqualTo(generalField.getTag()); assertThat(field.getContent()).isEqualTo(generalField.getContent()); assertThat(field.getDebitCreditType()).isEqualTo(DebitCreditType.REGULAR); + assertThat(field.getSignedAmount()).isEqualTo(new BigDecimal("123.456")); } - @Test public void getSignedAmount_WHEN_regular_debit_transaction_THEN_return_negative_amount() throws Exception { // Given diff --git a/src/test/java/com/qoomon/banking/swift/submessage/mt940/MT940PageReaderTest.java b/src/test/java/com/qoomon/banking/swift/submessage/mt940/MT940PageReaderTest.java index 5ab559c..0329554 100644 --- a/src/test/java/com/qoomon/banking/swift/submessage/mt940/MT940PageReaderTest.java +++ b/src/test/java/com/qoomon/banking/swift/submessage/mt940/MT940PageReaderTest.java @@ -35,6 +35,7 @@ public void parse_WHEN_parse_valid_file_RETURN_message() throws Exception { ":28C:00102\n" + ":60F:C000103USD672,\n" + ":61:0312091211D880,FTRFBPHP/081203/0003//59512112915002\n" + + "supplementary info\n" + ":86:multiline info\n" + "-info\n" + ":61:0312091211D880,FTRFBPHP/081203/0003//59512112915002\n" + @@ -58,6 +59,29 @@ public void parse_WHEN_parse_valid_file_RETURN_message() throws Exception { softly.assertThat(MT940Page.getTransactionGroupList()).hasSize(3); } + @Test + public void parse_WHEN_supplementary_details_start_with_colon_THEN_it_is_correctly_parsed() throws Exception { + + // Given + String mt940MessageText = ":20:02618\n" + + ":21:123456/DEV\n" + + ":25:6-9412771\n" + + ":28C:00102\n" + + ":60F:C000103USD672,\n" + + ":61:0312091211D880,FTRFBPHP/081203/0003//59512112915002\n" + + ":colon is valid x char set\n" + + ":62F:C000103USD987,\n" + + "-"; + + MT940PageReader classUnderTest = new MT940PageReader(new StringReader(mt940MessageText)); + + // When + List pageList = TestUtils.collectUntilNull(classUnderTest::read); + + // Then + assertThat(pageList).hasSize(1); + } + @Test public void getContent_SHOULD_return_input_text() throws Exception {