diff --git a/rs-e2e/src/main/java/gov/hhs/cdc/trustedintermediary/rse2e/hl7/HL7Parser.java b/rs-e2e/src/main/java/gov/hhs/cdc/trustedintermediary/rse2e/hl7/HL7Parser.java index cb4f18c30..e37be8098 100644 --- a/rs-e2e/src/main/java/gov/hhs/cdc/trustedintermediary/rse2e/hl7/HL7Parser.java +++ b/rs-e2e/src/main/java/gov/hhs/cdc/trustedintermediary/rse2e/hl7/HL7Parser.java @@ -53,7 +53,7 @@ public static HL7Message parse(String content) { } public static String parseAndGetValue(List fields, char[] delimiters, int... indices) { - if (fields == null || indices[0] > fields.size()) { + if (fields == null || fields.isEmpty() || indices[0] > fields.size()) { return null; } diff --git a/rs-e2e/src/test/groovy/gov/hhs/cdc/trustedintermediary/rse2e/hl7/HL7ParserTest.groovy b/rs-e2e/src/test/groovy/gov/hhs/cdc/trustedintermediary/rse2e/hl7/HL7ParserTest.groovy index 6f6977aac..55f8bd0a2 100644 --- a/rs-e2e/src/test/groovy/gov/hhs/cdc/trustedintermediary/rse2e/hl7/HL7ParserTest.groovy +++ b/rs-e2e/src/test/groovy/gov/hhs/cdc/trustedintermediary/rse2e/hl7/HL7ParserTest.groovy @@ -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 + } }