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:
parent
158167187d
commit
5b2e95933a
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user