1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

added unit test for checkPlurality and IAE for negative values

This commit is contained in:
iTwins 2023-08-30 23:52:17 +02:00
parent 158167187d
commit 5b2e95933a
2 changed files with 15 additions and 0 deletions

View File

@ -89,8 +89,13 @@ public final class ChatUtils {
* 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;
}

View File

@ -33,4 +33,14 @@ class TestChatUtils {
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));
}
}