Added some unit tests
This commit is contained in:
parent
4ef15ae764
commit
70bb3ddcce
60
proxy/src/test/java/net/md_5/bungee/chat/ComponentsTest.java
Normal file
60
proxy/src/test/java/net/md_5/bungee/chat/ComponentsTest.java
Normal file
@ -0,0 +1,60 @@
|
||||
package net.md_5.bungee.chat;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ComponentsTest
|
||||
{
|
||||
@Test
|
||||
public void testBasicComponent() {
|
||||
TextComponent textComponent = new TextComponent( "Hello world" );
|
||||
textComponent.setColor( ChatColor.RED );
|
||||
|
||||
Assert.assertEquals( "Hello world" , textComponent.toPlainText() );
|
||||
Assert.assertEquals( ChatColor.RED + "Hello world" , textComponent.toLegacyText() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLegacyConverter() {
|
||||
BaseComponent[] test1 = TextComponent.fromLegacyText( ChatColor.AQUA + "Aqua " + ChatColor.RED + ChatColor.BOLD + "RedBold" );
|
||||
|
||||
Assert.assertEquals( "Aqua RedBold" , BaseComponent.toPlainText( test1 ) );
|
||||
Assert.assertEquals( ChatColor.AQUA + "Aqua " + ChatColor.RED + ChatColor.BOLD + "RedBold" , BaseComponent.toLegacyText( test1 ) );
|
||||
|
||||
BaseComponent[] test2 = TextComponent.fromLegacyText( "Text http://spigotmc.org " + ChatColor.GREEN + "google.com/test" );
|
||||
|
||||
Assert.assertEquals( "Text http://spigotmc.org google.com/test" , BaseComponent.toPlainText( test2 ) );
|
||||
//The extra ChatColor.WHITEs are sometimes inserted when not needed but it doesn't change the result
|
||||
Assert.assertEquals( ChatColor.WHITE + "Text " + ChatColor.WHITE + "http://spigotmc.org" + ChatColor.WHITE
|
||||
+ " " + ChatColor.GREEN + "google.com/test" , BaseComponent.toLegacyText( test2 ) );
|
||||
|
||||
ClickEvent url1 = test2[1].getClickEvent();
|
||||
Assert.assertNotNull( url1 );
|
||||
Assert.assertTrue( url1.getAction() == ClickEvent.Action.OPEN_URL );
|
||||
Assert.assertEquals( "http://spigotmc.org" , url1.getValue() );
|
||||
|
||||
ClickEvent url2 = test2[3].getClickEvent();
|
||||
Assert.assertNotNull( url2 );
|
||||
Assert.assertTrue( url2.getAction() == ClickEvent.Action.OPEN_URL );
|
||||
Assert.assertEquals( "http://google.com/test" , url2.getValue() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTranslateComponent() {
|
||||
TranslatableComponent item = new TranslatableComponent( "item.swordGold.name" );
|
||||
item.setColor( ChatColor.AQUA );
|
||||
TranslatableComponent translatableComponent = new TranslatableComponent( "commands.give.success",
|
||||
item, "5",
|
||||
"thinkofdeath");
|
||||
|
||||
Assert.assertEquals( "Given Golden Sword * 5 to thinkofdeath" , translatableComponent.toPlainText() );
|
||||
Assert.assertEquals( ChatColor.WHITE + "Given " + ChatColor.AQUA + "Golden Sword" + ChatColor.WHITE
|
||||
+ " * " + ChatColor.WHITE + "5" + ChatColor.WHITE + " to " + ChatColor.WHITE + "thinkofdeath" ,
|
||||
translatableComponent.toLegacyText() );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user