Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher Thonfeld-Guckes <[email protected]>
  • Loading branch information
cguckes and cguckes authored Oct 19, 2022
1 parent 11c43c3 commit a3fbb82
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ public TitlecaseLambda(String delimiter) {
}

private String titleCase(final String input) {
return input.substring(0, 1).toUpperCase(Locale.ROOT) + input.substring(1);
if(input == null || "".equals(input)){
return "";
}

String firstLetter = input.substring(0, 1).toUpperCase(Locale.ROOT);
if (input.length() == 1) {
return firstLetter;
}
return firstLetter + input.substring(1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ public void titlecaseTest() {
test("Once Upon A Time", "{{#titlecase}}once upon a time{{/titlecase}}", ctx);
}

@Test
public void titlecaseSingleLetterTest() {
// Given
Map<String, Object> ctx = context("titlecase", new TitlecaseLambda());

// When & Then
test("O", "{{#titlecase}}o{{/titlecase}}", ctx);
}

@Test
public void titlecaseEmptyStringTest() {
// Given
Map<String, Object> ctx = context("titlecase", new TitlecaseLambda());

// When & Then
test("", "{{#titlecase}}{{/titlecase}}", ctx);
}

@Test
public void titlecaseWithDelimiterTest() {
// Given
Expand Down

0 comments on commit a3fbb82

Please sign in to comment.