Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions greeting/src/main/java/Greeting.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@ public static String greet(String... names) {
List<String> lowercaseNames = new ArrayList<>();
List<String> uppercaseNames = new ArrayList<>();

for (String name : names) {
if (name == null) {
for (String nameOrCombined : names) {
if (nameOrCombined == null) {
continue;
} else if (name.chars().allMatch(Character::isUpperCase)) {
uppercaseNames.add(name);
} else {
lowercaseNames.add(name);
}
String[] splitNames = nameOrCombined.split(",");
for (String name : splitNames) {
name = name.strip();
if (name.chars().allMatch(Character::isUpperCase)) {
uppercaseNames.add(name);
} else {
lowercaseNames.add(name);
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions greeting/src/test/java/GreetingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,22 @@ public void GreetWithMixedMultipleNames() {
String expected = "Hello, Joel and Noel. AND HELLO JOHN, JANE, AND MIKEL!";
Assert.assertEquals(expected, actual);
}

@Test
public void GreetWithCombinedInput() {
String[] names = {"Joel,John"};
String actual = Greeting.greet(names);

String expected = "Hello, Joel and John.";
Assert.assertEquals(expected, actual);
}

@Test
public void GreetWithCombinedInputMultiple() {
String[] names = {"Joel,JOHN", "Noel", "JANE", "MIKEL"};
String actual = Greeting.greet(names);

String expected = "Hello, Joel and Noel. AND HELLO JOHN, JANE, AND MIKEL!";
Assert.assertEquals(expected, actual);
}
}