Skip to content

Commit

Permalink
Updated edge case handling and fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
basiliskus committed Dec 23, 2024
1 parent b64eca5 commit fe296f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public static HL7Message parseMessage(String content) {
}

public static String parseMessageFieldValue(HL7Message message, HL7Path hl7Path)
throws HL7MessageException {
if (hl7Path == null || hl7Path.indices().length == 0) {
return "";
throws HL7ParserException, HL7MessageException {
if (hl7Path == null || hl7Path.indices().length == 0 || message == null) {
throw new HL7ParserException("Invalid HL7 path: message or path is null or empty");
}

int[] indices = hl7Path.indices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,26 @@ PID|||12345"""
"invalid index" | "TST-5" | ""
}

def "parseMessageFieldValue returns an empty string when inputs are null"() {
def "parseMessageFieldValue returns an exception when either or both inputs are null"() {
when:
def result = HL7Parser.parseMessageFieldValue(null, null)
HL7Parser.parseMessageFieldValue(null, null)

then:
result == ""
thrown(HL7ParserException)

when:
def hl7Path = HL7Parser.parsePath("MSH-3")
HL7Parser.parseMessageFieldValue(null, hl7Path)

then:
thrown(HL7ParserException)

when:
def message = HL7Parser.parseMessage("MSH|fakeValues")
HL7Parser.parseMessageFieldValue(message, null)

then:
thrown(HL7ParserException)
}

def "parseMessageFieldValue returns an empty string if an empty message is given"() {
Expand Down

0 comments on commit fe296f6

Please sign in to comment.