### Question:
SuppressionFileUtils { protected static Optional<ConsentEntity> entityFromLine(String line, String filename, int lineNum) throws InvalidSuppressionRecordException { final int hicnStart = 0, hicnEnd = 11, effectiveDateStart = 354, effectiveDateEnd = 362, sourceCodeStart = 362, sourceCodeEnd = 367, prefIndicatorStart = 368, prefIndicatorEnd = 369; if (line.startsWith("HDR_BENEDATASHR") || line.startsWith("TRL_BENEDATASHR")) { return Optional.empty(); } String sourceCode = line.substring(sourceCodeStart, sourceCodeEnd); if (!sourceCode.trim().matches("1-?800")) { if (StringUtils.isBlank(sourceCode)) { return Optional.empty(); } throw new InvalidSuppressionRecordException("Unexpected beneficiary data sharing source code", filename, lineNum); } ConsentEntity consent = new ConsentEntity(); String effectiveDateStr = line.substring(effectiveDateStart, effectiveDateEnd); LocalDate effectiveDate = LocalDate.parse(effectiveDateStr, DateTimeFormatter.ofPattern("yyyyMMdd")); try { consent.setEffectiveDate(effectiveDate); } catch (DateTimeParseException e) { throw new InvalidSuppressionRecordException("Cannot parse date from suppression record", filename, lineNum, e); } String hicn = line.substring(hicnStart, hicnEnd).trim(); if (!HICN_PATTERN.matcher(hicn).matches()) { throw new InvalidSuppressionRecordException("HICN does not match expected format", filename, lineNum); } consent.setHicn(hicn); String prefIndicator = line.substring(prefIndicatorStart, prefIndicatorEnd); switch (prefIndicator) { case "Y": consent.setPolicyCode("OPTIN"); break; case "N": consent.setPolicyCode("OPTOUT"); break; default: throw new InvalidSuppressionRecordException("Beneficiary data sharing preference does not match expected value of 'Y' or 'N'", filename, lineNum); } consent.setPurposeCode("TREAT"); consent.setLoincCode("64292-6"); consent.setScopeCode("patient-privacy"); return Optional.ofNullable(consent); } private  SuppressionFileUtils();   }### Answer:
@Test public void testEntityFromLine() { Optional<ConsentEntity> result = SuppressionFileUtils.entityFromLine("1000087481 1847800005John Mitchell Doe 198203218702 E Fake St. Apt. 63L Region Las Vegas NV423139954M20190618201907011-800TY201907011-800TNT9992WeCare Medical ", "", 0); assertTrue(result.isPresent()); ConsentEntity consent = result.get(); assertEquals("1000087481", consent.getHicn()); assertEquals("OPTIN", consent.getPolicyCode()); assertEquals(LocalDate.parse("2019-07-01"), consent.getEffectiveDate()); }
@Test public void testEntityFromLine_InvalidSource() { assertThrows(InvalidSuppressionRecordException.class, () -> { SuppressionFileUtils.entityFromLine("1000050218 1120500001Janice Marie J 19700227288 Waterpool Dr. AddressLine2 City FakeCity NY110390889U2019030120190719aaaaaTN T9992 ", "", 0); }); }
@Test public void testEntityFromLine_Header() { Optional<ConsentEntity> result = SuppressionFileUtils.entityFromLine("HDR_BENEDATASHR20191011", "", 0); assertTrue(result.isEmpty()); }
@Test public void testEntityFromLine_Trailer() { Optional<ConsentEntity> result = SuppressionFileUtils.entityFromLine("TRL_BENEDATASHR20191011 10", "", 0); assertTrue(result.isEmpty()); }