diff --git a/proxy/src/test/java/net/md_5/bungee/chat/ComponentsTest.java b/proxy/src/test/java/net/md_5/bungee/chat/ComponentsTest.java index e6d7ec39..584310d1 100644 --- a/proxy/src/test/java/net/md_5/bungee/chat/ComponentsTest.java +++ b/proxy/src/test/java/net/md_5/bungee/chat/ComponentsTest.java @@ -11,50 +11,59 @@ import org.junit.Test; public class ComponentsTest { @Test - public void testBasicComponent() { + 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() ); + Assert.assertEquals( "Hello world", textComponent.toPlainText() ); + Assert.assertEquals( ChatColor.RED + "Hello world", textComponent.toLegacyText() ); } @Test - public void testLegacyConverter() { + 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 ) ); + 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 ) ); + 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 ) ); + + " " + 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() ); + 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() ); + Assert.assertEquals( "http://google.com/test", url2.getValue() ); } @Test - public void testTranslateComponent() { + public void testTranslateComponent() + { TranslatableComponent item = new TranslatableComponent( "item.swordGold.name" ); item.setColor( ChatColor.AQUA ); TranslatableComponent translatableComponent = new TranslatableComponent( "commands.give.success", 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 - + " * " + ChatColor.WHITE + "5" + ChatColor.WHITE + " to " + ChatColor.WHITE + "thinkofdeath" , + + " * " + ChatColor.WHITE + "5" + ChatColor.WHITE + " to " + ChatColor.WHITE + "thinkofdeath", 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() ); } + }