Skip to content

Commit

Permalink
Add more HL7Parser coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-pabon-tf committed Dec 17, 2024
1 parent 336a6f1 commit f4290aa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static HL7Message parse(String content) {
}

public static String parseAndGetValue(List<String> fields, char[] delimiters, int... indices) {
if (fields == null || indices[0] > fields.size()) {
if (fields == null || fields.isEmpty() || indices[0] > fields.size()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,43 @@ OBX|1|ST|57723-9^Unique bar code number of Current sample^LN||123456||||||F|||20
message.getValue("NK1", 33, 4, 1, 1) == "Medicaid"
message.getValue("NK1", 33, 4, 1, 1, 1) == null
}

def "parseAndGetValue returns null if a null list of fields is given"() {
given:
def nullList = null
def delimiters = ['|']

when:
def out = HL7Parser.parseAndGetValue(nullList, delimiters as char[])

then:
out == null
}

def "parseAndGetValue returns null if an empty list of fields is given"() {
given:
def emptyList = []
def delimiters = ['|']

when:
def out = HL7Parser.parseAndGetValue(emptyList, delimiters as char[])

then:
out == null
}

def "parseAndGetValue returns null if the indices are pointing outside the expected range"() {
given:
def emptyList = [
"MSH|fakeValues",
"OBR|fakeValues"
]
def delimiters = ['|']

when:
def out = HL7Parser.parseAndGetValue(emptyList, delimiters as char[], 10, 20)

then:
out == null
}
}

0 comments on commit f4290aa

Please sign in to comment.