### Question:
Function { public String splitDateAndPartialGet(final String dateExpression, final boolean first) { final StringBuilder builder = new StringBuilder(); boolean secondSectionStarted = false; boolean atLeastOneDigitHasBeenCollected = false; for (int i = 0; i < dateExpression.length(); i++) { final char ch = dateExpression.charAt(i); if (Character.isDigit(ch) ) { atLeastOneDigitHasBeenCollected = true; if (first || secondSectionStarted) { builder.append(ch); } } else if (atLeastOneDigitHasBeenCollected || ch == '-') { if (first) { return builder.length() > 0 ? builder.toString() : null; } if (!secondSectionStarted) { secondSectionStarted = true; builder.setLength(0); } } } return builder.length() > 0 ? builder.toString() : null; }  long getId(); List<String> asList(final String [] array); String normalize(final String value); String normalizeWithoutLowercase(final String value); String uuid(final String value); String normalizeStrong(final String value); String lidoClass(final Integer id, final String value); String splitDateAndPartialGet(final String dateExpression, final boolean first); String toAliadaEventTypeClass(final String from); boolean isNotNullAndNotEmpty(final String value); boolean isNullOrEmpty(final String value); String getOntologyTypeURI(final Integer id, final String term); Map<String, String> mner(final String tag, final String code, final Object record); Map<String, String> ner(final String text); String escape(final String textContent); String clean(final String value);  }### Answer:
@Test public void splitDates_bothDates() { final String [] test = {"1988-1999","1988 - 1999", "1988- 1999", "1988 1999"}; final String expectedBirth = "1988"; final String expectedDeath = "1999"; for (final String dateExpression : test) { assertEquals(dateExpression, expectedBirth, cut.splitDateAndPartialGet(dateExpression, true)); assertEquals(dateExpression, expectedDeath, cut.splitDateAndPartialGet(dateExpression, false)); } }
@Test public void splitDates_onlyBirthDates() { final String [] test = {"1988- ","1988 - ", "1988", "1988 ", "d. 1988 "}; final String expectedBirth = "1988"; for (final String dateExpression : test) { assertEquals(dateExpression, expectedBirth, cut.splitDateAndPartialGet(dateExpression, true)); assertNull(dateExpression, cut.splitDateAndPartialGet(dateExpression, false)); } }
@Test public void splitDates_onlyDeathDates() { final String [] test = {"-1999","- 1999"}; final String expectedDeath= "1999"; for (final String dateExpression : test) { assertEquals(dateExpression, expectedDeath, cut.splitDateAndPartialGet(dateExpression, false)); assertNull(dateExpression, cut.splitDateAndPartialGet(dateExpression, true)); } }