mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-28 05:05:21 +01:00
Added another unit test + formatted code
This commit is contained in:
parent
70bb3ddcce
commit
bc746a546f
@ -11,50 +11,59 @@ import org.junit.Test;
|
|||||||
public class ComponentsTest
|
public class ComponentsTest
|
||||||
{
|
{
|
||||||
@Test
|
@Test
|
||||||
public void testBasicComponent() {
|
public void testBasicComponent()
|
||||||
|
{
|
||||||
TextComponent textComponent = new TextComponent( "Hello world" );
|
TextComponent textComponent = new TextComponent( "Hello world" );
|
||||||
textComponent.setColor( ChatColor.RED );
|
textComponent.setColor( ChatColor.RED );
|
||||||
|
|
||||||
Assert.assertEquals( "Hello world" , textComponent.toPlainText() );
|
Assert.assertEquals( "Hello world", textComponent.toPlainText() );
|
||||||
Assert.assertEquals( ChatColor.RED + "Hello world" , textComponent.toLegacyText() );
|
Assert.assertEquals( ChatColor.RED + "Hello world", textComponent.toLegacyText() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLegacyConverter() {
|
public void testLegacyConverter()
|
||||||
|
{
|
||||||
BaseComponent[] test1 = TextComponent.fromLegacyText( ChatColor.AQUA + "Aqua " + ChatColor.RED + ChatColor.BOLD + "RedBold" );
|
BaseComponent[] test1 = TextComponent.fromLegacyText( ChatColor.AQUA + "Aqua " + ChatColor.RED + ChatColor.BOLD + "RedBold" );
|
||||||
|
|
||||||
Assert.assertEquals( "Aqua RedBold" , BaseComponent.toPlainText( test1 ) );
|
Assert.assertEquals( "Aqua RedBold", BaseComponent.toPlainText( test1 ) );
|
||||||
Assert.assertEquals( ChatColor.AQUA + "Aqua " + ChatColor.RED + ChatColor.BOLD + "RedBold" , BaseComponent.toLegacyText( 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" );
|
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 ) );
|
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
|
//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
|
Assert.assertEquals( ChatColor.WHITE + "Text " + ChatColor.WHITE + "http://spigotmc.org" + ChatColor.WHITE
|
||||||
+ " " + ChatColor.GREEN + "google.com/test" , BaseComponent.toLegacyText( test2 ) );
|
+ " " + ChatColor.GREEN + "google.com/test", BaseComponent.toLegacyText( test2 ) );
|
||||||
|
|
||||||
ClickEvent url1 = test2[1].getClickEvent();
|
ClickEvent url1 = test2[1].getClickEvent();
|
||||||
Assert.assertNotNull( url1 );
|
Assert.assertNotNull( url1 );
|
||||||
Assert.assertTrue( url1.getAction() == ClickEvent.Action.OPEN_URL );
|
Assert.assertTrue( url1.getAction() == ClickEvent.Action.OPEN_URL );
|
||||||
Assert.assertEquals( "http://spigotmc.org" , url1.getValue() );
|
Assert.assertEquals( "http://spigotmc.org", url1.getValue() );
|
||||||
|
|
||||||
ClickEvent url2 = test2[3].getClickEvent();
|
ClickEvent url2 = test2[3].getClickEvent();
|
||||||
Assert.assertNotNull( url2 );
|
Assert.assertNotNull( url2 );
|
||||||
Assert.assertTrue( url2.getAction() == ClickEvent.Action.OPEN_URL );
|
Assert.assertTrue( url2.getAction() == ClickEvent.Action.OPEN_URL );
|
||||||
Assert.assertEquals( "http://google.com/test" , url2.getValue() );
|
Assert.assertEquals( "http://google.com/test", url2.getValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTranslateComponent() {
|
public void testTranslateComponent()
|
||||||
|
{
|
||||||
TranslatableComponent item = new TranslatableComponent( "item.swordGold.name" );
|
TranslatableComponent item = new TranslatableComponent( "item.swordGold.name" );
|
||||||
item.setColor( ChatColor.AQUA );
|
item.setColor( ChatColor.AQUA );
|
||||||
TranslatableComponent translatableComponent = new TranslatableComponent( "commands.give.success",
|
TranslatableComponent translatableComponent = new TranslatableComponent( "commands.give.success",
|
||||||
item, "5",
|
item, "5",
|
||||||
"thinkofdeath");
|
"thinkofdeath" );
|
||||||
|
|
||||||
Assert.assertEquals( "Given Golden Sword * 5 to thinkofdeath" , translatableComponent.toPlainText() );
|
Assert.assertEquals( "Given Golden Sword * 5 to thinkofdeath", translatableComponent.toPlainText() );
|
||||||
Assert.assertEquals( ChatColor.WHITE + "Given " + ChatColor.AQUA + "Golden Sword" + ChatColor.WHITE
|
Assert.assertEquals( ChatColor.WHITE + "Given " + ChatColor.AQUA + "Golden Sword" + ChatColor.WHITE
|
||||||
+ " * " + ChatColor.WHITE + "5" + ChatColor.WHITE + " to " + ChatColor.WHITE + "thinkofdeath" ,
|
+ " * " + ChatColor.WHITE + "5" + ChatColor.WHITE + " to " + ChatColor.WHITE + "thinkofdeath",
|
||||||
translatableComponent.toLegacyText() );
|
translatableComponent.toLegacyText() );
|
||||||
|
|
||||||
|
TranslatableComponent positional = new TranslatableComponent( "book.pageIndicator", "5", "50" );
|
||||||
|
|
||||||
|
Assert.assertEquals( "Page 5 of 50", positional.toPlainText() );
|
||||||
|
Assert.assertEquals( ChatColor.WHITE + "Page " + ChatColor.WHITE + "5" + ChatColor.WHITE + " of " + ChatColor.WHITE + "50", positional.toLegacyText() );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user