11package me .confuser .banmanager .common .configs ;
22
33import me .confuser .banmanager .common .BasePluginTest ;
4+ import me .confuser .banmanager .common .TestLogger ;
5+ import me .confuser .banmanager .common .configuration .file .YamlConfiguration ;
46import me .confuser .banmanager .common .util .Message ;
57import org .junit .Test ;
68
9+ import java .io .StringReader ;
10+
711import static org .junit .Assert .assertEquals ;
12+ import static org .junit .Assert .assertFalse ;
813
914public class MessagesConfigTest extends BasePluginTest {
1015
@@ -15,4 +20,50 @@ public void isValid() {
1520 .get ("info.ban.temporary" ).set ("reason" , "abc" ).set ("actor" , "def" ).set ("created" ,
1621 "8th July" ).set ("expires" , "1d" ).toString ());
1722 }
23+
24+ @ Test
25+ public void doubleNewlineProducesNonEmptyLine () {
26+ String yaml = "messages:\n test:\n greeting: 'Hello\\ n\\ nWorld'" ;
27+ YamlConfiguration config = YamlConfiguration .loadConfiguration (new StringReader (yaml ));
28+ Message .load (config , new TestLogger ());
29+
30+ String result = Message .get ("test.greeting" ).toString ();
31+
32+ assertEquals ("Hello\n \n World" , result );
33+ }
34+
35+ @ Test
36+ public void tripleNewlineProducesNonEmptyLines () {
37+ String yaml = "messages:\n test:\n greeting: 'Hello\\ n\\ n\\ nWorld'" ;
38+ YamlConfiguration config = YamlConfiguration .loadConfiguration (new StringReader (yaml ));
39+ Message .load (config , new TestLogger ());
40+
41+ String result = Message .get ("test.greeting" ).toString ();
42+
43+ assertEquals ("Hello\n \n \n World" , result );
44+ }
45+
46+ @ Test
47+ public void singleNewlineIsUnchanged () {
48+ String yaml = "messages:\n test:\n greeting: 'Hello\\ nWorld'" ;
49+ YamlConfiguration config = YamlConfiguration .loadConfiguration (new StringReader (yaml ));
50+ Message .load (config , new TestLogger ());
51+
52+ String result = Message .get ("test.greeting" ).toString ();
53+
54+ assertEquals ("Hello\n World" , result );
55+ }
56+
57+ @ Test
58+ public void noConsecutiveEmptyLinesInLoadedMessages () {
59+ String yaml = "messages:\n test:\n msg: 'Line1\\ n\\ nLine2\\ n\\ n\\ nLine3'" ;
60+ YamlConfiguration config = YamlConfiguration .loadConfiguration (new StringReader (yaml ));
61+ Message .load (config , new TestLogger ());
62+
63+ String result = Message .get ("test.msg" ).toString ();
64+
65+ for (String line : result .split ("\n " , -1 )) {
66+ assertFalse ("Empty lines should contain a space for chat rendering" , line .isEmpty ());
67+ }
68+ }
1869}
0 commit comments