forked from BetonQuest/BetonQuest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Test for the LocalChatPaginator and refactored the code of it a…
…nd fixed a bug where leading spaces where deleted
- Loading branch information
Showing
2 changed files
with
103 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/test/java/org/betonquest/betonquest/utils/LocalChatPaginatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.betonquest.betonquest.utils; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* Tests for the {@link LocalChatPaginator} | ||
*/ | ||
@SuppressWarnings("PMD.UseVarargs") | ||
class LocalChatPaginatorTest { | ||
private static Stream<Arguments> stringsToWrap() { | ||
final String spaces = " "; | ||
return Stream.of( | ||
Arguments.of("Bist du bereit?", | ||
new String[]{"Bist du bereit?"}, | ||
25, ""), | ||
Arguments.of("\nBist du bereit?", | ||
new String[]{"", "Bist du bereit?"}, | ||
25, ""), | ||
Arguments.of("Ich stelle dir nun 15 Fragen, von denen du mindestens 13 richtig beantworten musst. \nBist du bereit?", | ||
new String[]{"Ich stelle dir nun 15 Fragen, ", | ||
"von denen du mindestens 13 ", | ||
"richtig beantworten musst. ", | ||
"Bist du bereit?"}, | ||
25, ""), | ||
|
||
Arguments.of("Bist du bereit?", | ||
new String[]{"Bist du bereit?"}, | ||
25, spaces), | ||
Arguments.of("\nBist du bereit?", | ||
new String[]{"", spaces + "Bist du bereit?"}, | ||
25, spaces), | ||
Arguments.of("Ich stelle dir nun 15 Fragen, von denen du mindestens 13 richtig beantworten musst. \nBist du bereit?", | ||
new String[]{"Ich stelle dir nun 15 Fragen, ", | ||
spaces + "von denen du mindestens ", | ||
spaces + "13 richtig beantworten ", | ||
spaces + "musst. ", | ||
spaces + "Bist du bereit?"}, | ||
25, spaces), | ||
Arguments.of(" §8[§3Ich denke ich lese mir die Regeln noch mal durch.§r§3§8]", | ||
new String[]{" §8[§3Ich denke ich lese mir die ", | ||
spaces + "§3Regeln noch mal durch.§r§3§8]"}, | ||
25, spaces), | ||
Arguments.of("This should really break.", | ||
new String[]{"This ", | ||
"verylongprefix!should ", | ||
"verylongprefix!really ", | ||
"verylongprefix!break."}, | ||
5, "verylongprefix!"), | ||
Arguments.of(String.valueOf(ChatColor.COLOR_CHAR), | ||
new String[]{"§"}, | ||
25, ""), | ||
Arguments.of("fun\nwith\nspaces", | ||
new String[]{"fun", "with", "spaces"}, | ||
25, "") | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("stringsToWrap") | ||
void line_wrap(final String input, final String[] expected, final int lineLength, final String wrapPrefix) { | ||
final String[] result = LocalChatPaginator.wordWrap(input, lineLength, wrapPrefix); | ||
assertArrayEquals(expected, result, "The arrays should equal each other"); | ||
} | ||
} |