@Udf(description = "Returns the string with the the first letter"
      + " of each word capitalized and the rest lowercased")
  public String initcap(
      @UdfParameter(
          description = "The source string."
              + " If null, then function returns null.") final String str) {
    if (str == null) {
      return null;
    }

    final Pattern pattern = Pattern.compile("[^\\s]+\\s*");
    final Matcher matcher = pattern.matcher(str.toLowerCase());
    String initCapped = "";
    while (matcher.find()) {
      final String part = matcher.group();
      initCapped = initCapped.concat(part.substring(0, 1).toUpperCase() + part.substring(1));
    }

    return initCapped;
  }
@Test
  public void shouldHandleNull() {
    assertThat(udf.initcap(null), isEmptyOrNullString());
  }