2017-05-28 03:00:02 +02:00
package org.bukkit ;
2019-04-23 06:54:36 +02:00
import static org.junit.Assert.* ;
2017-05-28 03:00:02 +02:00
import net.minecraft.server.EnumChatFormat ;
2018-07-18 00:42:30 +02:00
import net.minecraft.server.IChatBaseComponent ;
2017-05-28 03:00:02 +02:00
import org.bukkit.craftbukkit.util.CraftChatMessage ;
import org.junit.Assert ;
import org.junit.Test ;
public class ChatTest {
@Test
public void testColors ( ) {
for ( ChatColor color : ChatColor . values ( ) ) {
Assert . assertNotNull ( CraftChatMessage . getColor ( color ) ) ;
Assert . assertEquals ( color , CraftChatMessage . getColor ( CraftChatMessage . getColor ( color ) ) ) ;
}
for ( EnumChatFormat format : EnumChatFormat . values ( ) ) {
Assert . assertNotNull ( CraftChatMessage . getColor ( format ) ) ;
Assert . assertEquals ( format , CraftChatMessage . getColor ( CraftChatMessage . getColor ( format ) ) ) ;
}
}
2018-07-18 00:42:30 +02:00
@Test
public void testURLJsonConversion ( ) {
IChatBaseComponent [ ] components ;
components = CraftChatMessage . fromString ( " https://spigotmc.org/test Test Message " ) ;
2018-07-18 01:40:51 +02:00
assertEquals ( " { \" extra \" :[{ \" clickEvent \" :{ \" action \" : \" open_url \" , \" value \" : \" https://spigotmc.org/test \" }, \" text \" : \" https://spigotmc.org/test \" },{ \" text \" : \" Test Message \" }], \" text \" : \" \" } " ,
CraftChatMessage . toJSON ( components [ 0 ] ) ) ;
2018-07-18 00:42:30 +02:00
components = CraftChatMessage . fromString ( " 123 " + ChatColor . GOLD + " https://spigotmc.org " + ChatColor . BOLD + " test " ) ;
2018-07-18 01:40:51 +02:00
assertEquals ( " { \" extra \" :[{ \" text \" : \" 123 \" },{ \" color \" : \" gold \" , \" clickEvent \" :{ \" action \" : \" open_url \" , \" value \" : \" https://spigotmc.org \" }, \" text \" : \" https://spigotmc.org \" },{ \" color \" : \" gold \" , \" text \" : \" \" },{ \" bold \" :true, \" color \" : \" gold \" , \" text \" : \" test \" }], \" text \" : \" \" } " ,
CraftChatMessage . toJSON ( components [ 0 ] ) ) ;
2018-07-18 00:42:30 +02:00
components = CraftChatMessage . fromString ( " multiCase http://SpigotMC.ORg/SpOngeBobMeEMeGoESHeRE " ) ;
2018-07-18 01:40:51 +02:00
assertEquals ( " { \" extra \" :[{ \" text \" : \" multiCase \" },{ \" clickEvent \" :{ \" action \" : \" open_url \" , \" value \" : \" http://SpigotMC.ORg/SpOngeBobMeEMeGoESHeRE \" }, \" text \" : \" http://SpigotMC.ORg/SpOngeBobMeEMeGoESHeRE \" }], \" text \" : \" \" } " ,
CraftChatMessage . toJSON ( components [ 0 ] ) ) ;
2018-07-18 00:42:30 +02:00
}
2017-05-28 03:00:02 +02:00
}