diff --git a/chat/src/test/java/net/md_5/bungee/api/chat/ComponentsTest.java b/chat/src/test/java/net/md_5/bungee/api/chat/ComponentsTest.java index 0c36662f0fc..8b41182ab46 100644 --- a/chat/src/test/java/net/md_5/bungee/api/chat/ComponentsTest.java +++ b/chat/src/test/java/net/md_5/bungee/api/chat/ComponentsTest.java @@ -20,14 +20,14 @@ public static void testDissembleReassemble(BaseComponent[] components) { String json = ComponentSerializer.toString( components ); BaseComponent[] parsed = ComponentSerializer.parse( json ); - assertEquals( TextComponent.toLegacyText( parsed ), TextComponent.toLegacyText( components ) ); + assertEquals( BaseComponent.toLegacyText( parsed ), BaseComponent.toLegacyText( components ) ); } public static void testDissembleReassemble(BaseComponent component) { String json = ComponentSerializer.toString( component ); BaseComponent[] parsed = ComponentSerializer.parse( json ); - assertEquals( TextComponent.toLegacyText( parsed ), TextComponent.toLegacyText( component ) ); + assertEquals( BaseComponent.toLegacyText( parsed ), BaseComponent.toLegacyText( component ) ); } public static void testAssembleDissemble(String json, boolean modern) @@ -177,7 +177,7 @@ public void testComponentParting() public void testToLegacyFromLegacy() { String text = "§a§lHello §f§kworld§7!"; - assertEquals( text, TextComponent.toLegacyText( TextComponent.fromLegacyText( text ) ) ); + assertEquals( text, BaseComponent.toLegacyText( TextComponent.fromLegacyText( text ) ) ); } @Test @@ -337,16 +337,16 @@ private void testHoverEventContents(HoverEvent hoverEvent, Function new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( "Test" ).create() ) ); + ComponentsTest.testFormatRetentionCopyFormatting( () -> new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( "Test" ).create() ) ); } @Test public void testFormatRetentionCopyFormattingBuild() { - this.testFormatRetentionCopyFormatting( () -> new HoverEvent( HoverEvent.Action.SHOW_TEXT, new Text( new ComponentBuilder( "Test" ).build() ) ) ); + testFormatRetentionCopyFormatting( () -> new HoverEvent( HoverEvent.Action.SHOW_TEXT, new Text( new ComponentBuilder( "Test" ).build() ) ) ); } - private void testFormatRetentionCopyFormatting(Supplier hoverEventSupplier) + private static void testFormatRetentionCopyFormatting(Supplier hoverEventSupplier) { TextComponent first = new TextComponent( "Hello" ); first.setBold( true ); @@ -365,16 +365,16 @@ private void testFormatRetentionCopyFormatting(Supplier hoverEventSu @Test public void testBuilderCloneCreate() { - this.testBuilderClone( (builder) -> TextComponent.toLegacyText( builder.create() ) ); + testBuilderClone( (builder) -> BaseComponent.toLegacyText( builder.create() ) ); } @Test public void testBuilderCloneBuild() { - this.testBuilderClone( (builder) -> TextComponent.toLegacyText( builder.build() ) ); + testBuilderClone( (builder) -> BaseComponent.toLegacyText( builder.build() ) ); } - private void testBuilderClone(Function legacyTextFunction) + private static void testBuilderClone(Function legacyTextFunction) { ComponentBuilder builder = new ComponentBuilder( "Hello " ).color( ChatColor.RED ).append( "world" ).color( ChatColor.DARK_RED ); ComponentBuilder cloned = new ComponentBuilder( builder ); @@ -385,7 +385,7 @@ private void testBuilderClone(Function legacyTextFunct @Test public void testBuilderAppendCreateMixedComponents() { - this.testBuilderAppendMixedComponents( + testBuilderAppendMixedComponents( ComponentBuilder::create, (components, index) -> components[index] ); @@ -394,13 +394,13 @@ public void testBuilderAppendCreateMixedComponents() @Test public void testBuilderAppendBuildMixedComponents() { - this.testBuilderAppendMixedComponents( + testBuilderAppendMixedComponents( ComponentBuilder::build, (component, index) -> component.getExtra().get( index ) ); } - private void testBuilderAppendMixedComponents(Function componentBuilder, BiFunction extraGetter) + private static void testBuilderAppendMixedComponents(Function componentBuilder, BiFunction extraGetter) { ComponentBuilder builder = new ComponentBuilder( "Hello " ); TextComponent textComponent = new TextComponent( "world " ); @@ -443,7 +443,7 @@ public void testStyle() @Test public void testBuilderAppendCreate() { - this.testBuilderAppend( + testBuilderAppend( () -> new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( "Hello world" ).create() ), ComponentBuilder::create, (components, index) -> components[index], @@ -456,7 +456,7 @@ public void testBuilderAppendCreate() @Test public void testBuilderAppendBuild() { - this.testBuilderAppend( + testBuilderAppend( () -> new HoverEvent( HoverEvent.Action.SHOW_TEXT, new Text( new ComponentBuilder( "Hello world" ).build() ) ), ComponentBuilder::build, (component, index) -> component.getExtra().get( index ), @@ -467,7 +467,7 @@ public void testBuilderAppendBuild() ); } - private void testBuilderAppend(Supplier hoverEventSupplier, Function componentBuilder, BiFunction extraGetter, Function toPlainTextFunction, String expectedLegacyText, Function toLegacyTextFunction) + private static void testBuilderAppend(Supplier hoverEventSupplier, Function componentBuilder, BiFunction extraGetter, Function toPlainTextFunction, String expectedLegacyText, Function toLegacyTextFunction) { ClickEvent clickEvent = new ClickEvent( ClickEvent.Action.RUN_COMMAND, "/help " ); HoverEvent hoverEvent = hoverEventSupplier.get(); @@ -486,7 +486,7 @@ private void testBuilderAppend(Supplier hoverEventSupplier, Func @Test public void testBuilderAppendLegacyCreate() { - this.testBuilderAppendLegacy( + testBuilderAppendLegacy( ComponentBuilder::create, BaseComponent::toPlainText, ChatColor.YELLOW + "Hello " + ChatColor.GREEN + "world!", @@ -497,7 +497,7 @@ public void testBuilderAppendLegacyCreate() @Test public void testBuilderAppendLegacyBuild() { - this.testBuilderAppendLegacy( + testBuilderAppendLegacy( ComponentBuilder::build, (component) -> BaseComponent.toPlainText( component ), // An extra format code is appended to the beginning because there is an empty TextComponent at the start of every component @@ -506,7 +506,7 @@ public void testBuilderAppendLegacyBuild() ); } - private void testBuilderAppendLegacy(Function componentBuilder, Function toPlainTextFunction, String expectedLegacyString, Function toLegacyTextFunction) + private static void testBuilderAppendLegacy(Function componentBuilder, Function toPlainTextFunction, String expectedLegacyString, Function toLegacyTextFunction) { ComponentBuilder builder = new ComponentBuilder( "Hello " ).color( ChatColor.YELLOW ); builder.appendLegacy( "§aworld!" ); @@ -579,7 +579,7 @@ public void testTranslateComponent() @Test public void testBuilderCreate() { - this.testBuilder( + testBuilder( ComponentBuilder::create, BaseComponent::toPlainText, ChatColor.RED + "Hello " + ChatColor.BLUE + ChatColor.BOLD + "World" + ChatColor.YELLOW + ChatColor.BOLD + "!", @@ -590,7 +590,7 @@ public void testBuilderCreate() @Test public void testBuilderBuild() { - this.testBuilder( + testBuilder( ComponentBuilder::build, (component) -> BaseComponent.toPlainText( component ), // An extra format code is appended to the beginning because there is an empty TextComponent at the start of every component @@ -599,7 +599,7 @@ public void testBuilderBuild() ); } - private void testBuilder(Function componentBuilder, Function toPlainTextFunction, String expectedLegacyString, Function toLegacyTextFunction) + private static void testBuilder(Function componentBuilder, Function toPlainTextFunction, String expectedLegacyString, Function toLegacyTextFunction) { T component = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( ChatColor.RED ). append( "World" ).bold( true ).color( ChatColor.BLUE ). @@ -612,7 +612,7 @@ private void testBuilder(Function componentBuilder, Fun @Test public void testBuilderCreateReset() { - this.testBuilderReset( + testBuilderReset( ComponentBuilder::create, (components, index) -> components[index] ); @@ -621,13 +621,13 @@ public void testBuilderCreateReset() @Test public void testBuilderBuildReset() { - this.testBuilderReset( + testBuilderReset( ComponentBuilder::build, (component, index) -> component.getExtra().get( index ) ); } - private void testBuilderReset(Function componentBuilder, BiFunction extraGetter) + private static void testBuilderReset(Function componentBuilder, BiFunction extraGetter) { T component = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( ChatColor.RED ) .append( "World" ).reset() ); @@ -639,7 +639,7 @@ private void testBuilderReset(Function componentBuilder @Test public void testBuilderCreateFormatRetention() { - this.testBuilderFormatRetention( + testBuilderFormatRetention( ComponentBuilder::create, (components, index) -> components[index] ); @@ -648,13 +648,13 @@ public void testBuilderCreateFormatRetention() @Test public void testBuilderBuildFormatRetention() { - this.testBuilderFormatRetention( + testBuilderFormatRetention( ComponentBuilder::build, (component, index) -> component.getExtra().get( index ) ); } - private void testBuilderFormatRetention(Function componentBuilder, BiFunction extraGetter) + private static void testBuilderFormatRetention(Function componentBuilder, BiFunction extraGetter) { T noneRetention = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( ChatColor.RED ) .append( "World", ComponentBuilder.FormatRetention.NONE ) ); @@ -800,7 +800,7 @@ public void testNotEquals() public void testLegacyHack() { BaseComponent[] hexColored = new ComponentBuilder().color( ChatColor.of( Color.GRAY ) ).append( "Test" ).create(); - String legacy = TextComponent.toLegacyText( hexColored ); + String legacy = BaseComponent.toLegacyText( hexColored ); BaseComponent[] reColored = TextComponent.fromLegacyText( legacy ); @@ -810,7 +810,7 @@ public void testLegacyHack() @Test public void testLegacyResetInBuilderCreate() { - this.testLegacyResetInBuilder( + testLegacyResetInBuilder( ComponentBuilder::create, ComponentSerializer::toString ); @@ -819,7 +819,7 @@ public void testLegacyResetInBuilderCreate() @Test public void testLegacyResetInBuilderBuild() { - this.testLegacyResetInBuilder( + testLegacyResetInBuilder( ComponentBuilder::build, ComponentSerializer::toString ); @@ -851,7 +851,7 @@ public void testStyleIsEmpty() * In legacy chat, colors and reset both reset all formatting. * Make sure it works in combination with ComponentBuilder. */ - private void testLegacyResetInBuilder(Function componentBuilder, Function componentSerializer) + private static void testLegacyResetInBuilder(Function componentBuilder, Function componentSerializer) { ComponentBuilder builder = new ComponentBuilder(); BaseComponent[] a = TextComponent.fromLegacyText( "§4§n44444§rdd§6§l6666" ); diff --git a/chat/src/test/java/net/md_5/bungee/api/chat/TranslatableComponentTest.java b/chat/src/test/java/net/md_5/bungee/api/chat/TranslatableComponentTest.java index 9ec5dcb1a73..47c06baafcf 100644 --- a/chat/src/test/java/net/md_5/bungee/api/chat/TranslatableComponentTest.java +++ b/chat/src/test/java/net/md_5/bungee/api/chat/TranslatableComponentTest.java @@ -22,7 +22,7 @@ public void testJsonSerialisation() String jsonString = ComponentSerializer.toString( testComponent ); BaseComponent[] baseComponents = ComponentSerializer.parse( jsonString ); - assertEquals( "Test string with a placeholder", TextComponent.toPlainText( baseComponents ) ); - assertEquals( "§fTest string with §fa§f placeholder", TextComponent.toLegacyText( baseComponents ) ); + assertEquals( "Test string with a placeholder", BaseComponent.toPlainText( baseComponents ) ); + assertEquals( "§fTest string with §fa§f placeholder", BaseComponent.toLegacyText( baseComponents ) ); } }