Skip to content

Commit

Permalink
Merge pull request #116 from nieldw/fix/description_line_can_start_wi…
Browse files Browse the repository at this point in the history
…th_colon

Fix/description line can start with colon
  • Loading branch information
qoomon authored Jan 8, 2022
2 parents 7e3f74b + 9506c99 commit f066de5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand All @@ -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<MT940Page> pageList = TestUtils.collectUntilNull(classUnderTest::read);

// Then
assertThat(pageList).hasSize(1);
}

@Test
public void getContent_SHOULD_return_input_text() throws Exception {

Expand Down

0 comments on commit f066de5

Please sign in to comment.