Skip to content

Commit

Permalink
added unit test for checkPlurality and IAE for negative values
Browse files Browse the repository at this point in the history
  • Loading branch information
iTwins committed Aug 30, 2023
1 parent 1581671 commit 5b2e959
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ public static void awaitInput(@Nonnull Player p, @Nonnull Consumer<String> callb
* The amount of things
* @return
* {@code string} if {@code count} is 1 else {@code string + "s"}
* @throws IllegalArgumentException
* if count is less than 0
*/
public static @Nonnull String checkPlurality(@Nonnull String string, int count) {
if (count < 0) {
throw new IllegalArgumentException("Argument count cannot be negative.");
}
if (count == 1) {
return string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ void testColorCodeRemoval() {
Assertions.assertEquals(expected, ChatUtils.removeColorCodes(ChatColor.GREEN + "Hello " + ChatColor.RED + "world"));
}

@Test
@DisplayName("Test ChatUtils.checkPlurality(...)")
void testPluralization() {
String input = "Banana";
Assertions.assertThrows(IllegalArgumentException.class, () -> ChatUtils.checkPlurality(input, -1));
Assertions.assertEquals("Bananas", ChatUtils.checkPlurality(input, 0));
Assertions.assertEquals("Banana", ChatUtils.checkPlurality(input, 1));
Assertions.assertEquals("Bananas", ChatUtils.checkPlurality(input, 2));
}

}

0 comments on commit 5b2e959

Please sign in to comment.