diff --git a/api/src/test/java/net/md_5/bungee/api/ServerConnectRequestTest.java b/api/src/test/java/net/md_5/bungee/api/ServerConnectRequestTest.java index aefe026e..9c48782c 100644 --- a/api/src/test/java/net/md_5/bungee/api/ServerConnectRequestTest.java +++ b/api/src/test/java/net/md_5/bungee/api/ServerConnectRequestTest.java @@ -1,12 +1,13 @@ package net.md_5.bungee.api; +import static org.junit.jupiter.api.Assertions.*; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.Collection; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.ServerConnectEvent; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ServerConnectRequestTest { @@ -78,15 +79,15 @@ public class ServerConnectRequestTest } }; - @Test(expected = NullPointerException.class) + @Test public void testNullTarget() { - ServerConnectRequest.builder().target( null ).reason( ServerConnectEvent.Reason.JOIN_PROXY ).build(); + assertThrows( NullPointerException.class, () -> ServerConnectRequest.builder().target( null ).reason( ServerConnectEvent.Reason.JOIN_PROXY ).build() ); } - @Test(expected = NullPointerException.class) + @Test public void testNullReason() { - ServerConnectRequest.builder().target( DUMMY_INFO ).reason( null ).build(); + assertThrows( NullPointerException.class, () -> ServerConnectRequest.builder().target( DUMMY_INFO ).reason( null ).build() ); } } diff --git a/api/src/test/java/net/md_5/bungee/util/AddressParseTest.java b/api/src/test/java/net/md_5/bungee/util/AddressParseTest.java index a0752255..4c7efca6 100644 --- a/api/src/test/java/net/md_5/bungee/util/AddressParseTest.java +++ b/api/src/test/java/net/md_5/bungee/util/AddressParseTest.java @@ -1,63 +1,38 @@ package net.md_5.bungee.util; +import static org.junit.jupiter.api.Assertions.*; import io.netty.channel.unix.DomainSocketAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; -import java.util.Arrays; -import java.util.Collection; +import java.util.stream.Stream; import lombok.RequiredArgsConstructor; import net.md_5.bungee.Util; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; @RequiredArgsConstructor -@RunWith(Parameterized.class) public class AddressParseTest { - @Parameters - public static Collection data() + public static Stream data() { - return Arrays.asList( new Object[][] - { - { - "127.0.0.1", "127.0.0.1", Util.DEFAULT_PORT - }, - { - "127.0.0.1:1337", "127.0.0.1", 1337 - }, - { - "[::1]", "0:0:0:0:0:0:0:1", Util.DEFAULT_PORT - }, - { - "[0:0:0:0::1]", "0:0:0:0:0:0:0:1", Util.DEFAULT_PORT - }, - { - "[0:0:0:0:0:0:0:1]", "0:0:0:0:0:0:0:1", Util.DEFAULT_PORT - }, - { - "[::1]:1337", "0:0:0:0:0:0:0:1", 1337 - }, - { - "[0:0:0:0::1]:1337", "0:0:0:0:0:0:0:1", 1337 - }, - { - "[0:0:0:0:0:0:0:1]:1337", "0:0:0:0:0:0:0:1", 1337 - }, - { - "unix:///var/run/bungee.sock", "/var/run/bungee.sock", -1 - } - } ); + return Stream.of( + Arguments.of( "127.0.0.1", "127.0.0.1", Util.DEFAULT_PORT ), + Arguments.of( "127.0.0.1:1337", "127.0.0.1", 1337 ), + Arguments.of( "[::1]", "0:0:0:0:0:0:0:1", Util.DEFAULT_PORT ), + Arguments.of( "[0:0:0:0::1]", "0:0:0:0:0:0:0:1", Util.DEFAULT_PORT ), + Arguments.of( "[0:0:0:0:0:0:0:1]", "0:0:0:0:0:0:0:1", Util.DEFAULT_PORT ), + Arguments.of( "[::1]:1337", "0:0:0:0:0:0:0:1", 1337 ), + Arguments.of( "[0:0:0:0::1]:1337", "0:0:0:0:0:0:0:1", 1337 ), + Arguments.of( "[0:0:0:0:0:0:0:1]:1337", "0:0:0:0:0:0:0:1", 1337 ), + Arguments.of( "unix:///var/run/bungee.sock", "/var/run/bungee.sock", -1 ) + ); } - private final String line; - private final String host; - private final int port; - @Test - public void test() + @ParameterizedTest + @MethodSource("data") + public void test(String line, String host, int port) { SocketAddress parsed = Util.getAddr( line ); @@ -65,14 +40,14 @@ public class AddressParseTest { InetSocketAddress tcp = (InetSocketAddress) parsed; - Assert.assertEquals( host, tcp.getHostString() ); - Assert.assertEquals( port, tcp.getPort() ); + assertEquals( host, tcp.getHostString() ); + assertEquals( port, tcp.getPort() ); } else if ( parsed instanceof DomainSocketAddress ) { DomainSocketAddress unix = (DomainSocketAddress) parsed; - Assert.assertEquals( host, unix.path() ); - Assert.assertEquals( -1, port ); + assertEquals( host, unix.path() ); + assertEquals( -1, port ); } else { throw new AssertionError( "Unknown socket " + parsed ); diff --git a/api/src/test/java/net/md_5/bungee/util/CaseInsensitiveTest.java b/api/src/test/java/net/md_5/bungee/util/CaseInsensitiveTest.java index c25912af..7c6ec2f0 100644 --- a/api/src/test/java/net/md_5/bungee/util/CaseInsensitiveTest.java +++ b/api/src/test/java/net/md_5/bungee/util/CaseInsensitiveTest.java @@ -1,7 +1,7 @@ package net.md_5.bungee.util; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class CaseInsensitiveTest { @@ -13,12 +13,12 @@ public class CaseInsensitiveTest CaseInsensitiveMap map = new CaseInsensitiveMap<>(); map.put( "FOO", obj ); - Assert.assertTrue( map.contains( "foo" ) ); // Assert that contains is case insensitive - Assert.assertTrue( map.entrySet().iterator().next().getKey().equals( "FOO" ) ); // Assert that case is preserved + assertTrue( map.contains( "foo" ) ); // Assert that contains is case insensitive + assertTrue( map.entrySet().iterator().next().getKey().equals( "FOO" ) ); // Assert that case is preserved // Assert that remove is case insensitive map.remove( "FoO" ); - Assert.assertFalse( map.contains( "foo" ) ); + assertFalse( map.contains( "foo" ) ); } @Test @@ -27,8 +27,8 @@ public class CaseInsensitiveTest CaseInsensitiveSet set = new CaseInsensitiveSet(); set.add( "FOO" ); - Assert.assertTrue( set.contains( "foo" ) ); // Assert that contains is case insensitive + assertTrue( set.contains( "foo" ) ); // Assert that contains is case insensitive set.remove( "FoO" ); - Assert.assertFalse( set.contains( "foo" ) ); // Assert that remove is case insensitive + assertFalse( set.contains( "foo" ) ); // Assert that remove is case insensitive } } diff --git a/api/src/test/java/net/md_5/bungee/util/UUIDTest.java b/api/src/test/java/net/md_5/bungee/util/UUIDTest.java index 9f2d58ed..aef50f06 100644 --- a/api/src/test/java/net/md_5/bungee/util/UUIDTest.java +++ b/api/src/test/java/net/md_5/bungee/util/UUIDTest.java @@ -1,9 +1,9 @@ package net.md_5.bungee.util; +import static org.junit.jupiter.api.Assertions.*; import java.util.UUID; import net.md_5.bungee.Util; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class UUIDTest { @@ -13,7 +13,7 @@ public class UUIDTest { UUID uuid = UUID.fromString( "af74a02d-19cb-445b-b07f-6866a861f783" ); UUID uuid1 = Util.getUUID( "af74a02d19cb445bb07f6866a861f783" ); - Assert.assertEquals( uuid, uuid1 ); + assertEquals( uuid, uuid1 ); } @Test @@ -23,7 +23,7 @@ public class UUIDTest { UUID expected = UUID.randomUUID(); UUID actual = Util.getUUID( expected.toString().replace( "-", "" ) ); - Assert.assertEquals( "Could not parse UUID " + expected, expected, actual ); + assertEquals( expected, actual, "Could not parse UUID " + expected ); } } } 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 95dd1620..1273e098 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 @@ -1,5 +1,6 @@ package net.md_5.bungee.api.chat; +import static org.junit.jupiter.api.Assertions.*; import java.awt.Color; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -10,8 +11,7 @@ import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.hover.content.Item; import net.md_5.bungee.api.chat.hover.content.Text; import net.md_5.bungee.chat.ComponentSerializer; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ComponentsTest { @@ -20,14 +20,14 @@ public class ComponentsTest { String json = ComponentSerializer.toString( components ); BaseComponent[] parsed = ComponentSerializer.parse( json ); - Assert.assertEquals( TextComponent.toLegacyText( parsed ), TextComponent.toLegacyText( components ) ); + assertEquals( TextComponent.toLegacyText( parsed ), TextComponent.toLegacyText( components ) ); } public static void testDissembleReassemble(BaseComponent component) { String json = ComponentSerializer.toString( component ); BaseComponent[] parsed = ComponentSerializer.parse( json ); - Assert.assertEquals( TextComponent.toLegacyText( parsed ), TextComponent.toLegacyText( component ) ); + assertEquals( TextComponent.toLegacyText( parsed ), TextComponent.toLegacyText( component ) ); } public static void testAssembleDissemble(String json, boolean modern) @@ -35,11 +35,11 @@ public class ComponentsTest if ( modern ) { BaseComponent deserialized = ComponentSerializer.deserialize( json ); - Assert.assertEquals( json, ComponentSerializer.toString( deserialized ) ); + assertEquals( json, ComponentSerializer.toString( deserialized ) ); } else { BaseComponent[] parsed = ComponentSerializer.parse( json ); - Assert.assertEquals( json, ComponentSerializer.toString( parsed ) ); + assertEquals( json, ComponentSerializer.toString( parsed ) ); } } @@ -69,7 +69,7 @@ public class ComponentsTest json = "{\"extra\":[{\"text\":\"[\"},{\"extra\":[{\"translate\":\"block.minecraft.dirt\"}],\"text\":\"\"},{\"text\":\"]\"}],\"hoverEvent\":{\"action\":\"show_item\",\"value\":[" + hoverVal + "]},\"text\":\"\"}"; components = ComponentSerializer.parse( json ); Text contentText = ( (Text) components[0].getHoverEvent().getContents().get( 0 ) ); - Assert.assertEquals( hoverVal, ComponentSerializer.toString( (BaseComponent[]) contentText.getValue() ) ); + assertEquals( hoverVal, ComponentSerializer.toString( (BaseComponent[]) contentText.getValue() ) ); testDissembleReassemble( components ); ////////// TextComponent component1 = new TextComponent( "HoverableText" ); @@ -80,10 +80,10 @@ public class ComponentsTest json = ComponentSerializer.toString( component1 ); components = ComponentSerializer.parse( json ); Item parsedContentItem = ( (Item) components[0].getHoverEvent().getContents().get( 0 ) ); - Assert.assertEquals( contentItem, parsedContentItem ); - Assert.assertEquals( contentItem.getCount(), parsedContentItem.getCount() ); - Assert.assertEquals( contentItem.getId(), parsedContentItem.getId() ); - Assert.assertEquals( nbt, parsedContentItem.getTag().getNbt() ); + assertEquals( contentItem, parsedContentItem ); + assertEquals( contentItem.getCount(), parsedContentItem.getCount() ); + assertEquals( contentItem.getId(), parsedContentItem.getId() ); + assertEquals( nbt, parsedContentItem.getTag().getNbt() ); } @Test @@ -91,8 +91,8 @@ public class ComponentsTest { this.testEmptyComponentBuilder( ComponentBuilder::create, - (components) -> Assert.assertEquals( components.length, 0 ), - (components, size) -> Assert.assertEquals( size, components.length ) + (components) -> assertEquals( components.length, 0 ), + (components, size) -> assertEquals( size, components.length ) ); } @@ -101,8 +101,8 @@ public class ComponentsTest { this.testEmptyComponentBuilder( ComponentBuilder::build, - (component) -> Assert.assertNull( component.getExtra() ), - (component, size) -> Assert.assertEquals( component.getExtra().size(), size ) + (component) -> assertNull( component.getExtra() ), + (component, size) -> assertEquals( component.getExtra().size(), size ) ); } @@ -125,23 +125,23 @@ public class ComponentsTest public void testDummyRetaining() { ComponentBuilder builder = new ComponentBuilder(); - Assert.assertNotNull( builder.getCurrentComponent() ); + assertNotNull( builder.getCurrentComponent() ); builder.color( ChatColor.GREEN ); builder.append( "test ", ComponentBuilder.FormatRetention.ALL ); - Assert.assertEquals( builder.getCurrentComponent().getColor(), ChatColor.GREEN ); + assertEquals( builder.getCurrentComponent().getColor(), ChatColor.GREEN ); } - @Test(expected = IndexOutOfBoundsException.class) + @Test public void testComponentGettingExceptions() { ComponentBuilder builder = new ComponentBuilder(); - builder.getComponent( -1 ); - builder.getComponent( 0 ); - builder.getComponent( 1 ); + assertThrows( IndexOutOfBoundsException.class, () -> builder.getComponent( -1 ) ); + assertThrows( IndexOutOfBoundsException.class, () -> builder.getComponent( 0 ) ); + assertThrows( IndexOutOfBoundsException.class, () -> builder.getComponent( 1 ) ); BaseComponent component = new TextComponent( "Hello" ); builder.append( component ); - Assert.assertEquals( builder.getComponent( 0 ), component ); - builder.getComponent( 1 ); + assertEquals( builder.getComponent( 0 ), component ); + assertThrows( IndexOutOfBoundsException.class, () -> builder.getComponent( 1 ) ); } @Test @@ -150,33 +150,33 @@ public class ComponentsTest ComponentBuilder builder = new ComponentBuilder(); TextComponent apple = new TextComponent( "apple" ); builder.append( apple ); - Assert.assertEquals( builder.getCurrentComponent(), apple ); - Assert.assertEquals( builder.getComponent( 0 ), apple ); + assertEquals( builder.getCurrentComponent(), apple ); + assertEquals( builder.getComponent( 0 ), apple ); TextComponent mango = new TextComponent( "mango" ); TextComponent orange = new TextComponent( "orange" ); builder.append( mango ); builder.append( orange ); builder.removeComponent( 1 ); // Removing mango - Assert.assertEquals( builder.getComponent( 0 ), apple ); - Assert.assertEquals( builder.getComponent( 1 ), orange ); + assertEquals( builder.getComponent( 0 ), apple ); + assertEquals( builder.getComponent( 1 ), orange ); } @Test public void testToLegacyFromLegacy() { String text = "§a§lHello §f§kworld§7!"; - Assert.assertEquals( text, TextComponent.toLegacyText( TextComponent.fromLegacyText( text ) ) ); + assertEquals( text, TextComponent.toLegacyText( TextComponent.fromLegacyText( text ) ) ); } - @Test(expected = IndexOutOfBoundsException.class) + @Test public void testComponentBuilderCursorInvalidPos() { ComponentBuilder builder = new ComponentBuilder(); builder.append( new TextComponent( "Apple, " ) ); builder.append( new TextComponent( "Orange, " ) ); - builder.setCursor( -1 ); - builder.setCursor( 2 ); + assertThrows( IndexOutOfBoundsException.class, () -> builder.setCursor( -1 ) ); + assertThrows( IndexOutOfBoundsException.class, () -> builder.setCursor( 2 ) ); } @Test @@ -184,24 +184,24 @@ public class ComponentsTest { TextComponent t1, t2, t3; ComponentBuilder builder = new ComponentBuilder(); - Assert.assertEquals( builder.getCursor(), -1 ); + assertEquals( builder.getCursor(), -1 ); builder.append( t1 = new TextComponent( "Apple, " ) ); - Assert.assertEquals( builder.getCursor(), 0 ); + assertEquals( builder.getCursor(), 0 ); builder.append( t2 = new TextComponent( "Orange, " ) ); builder.append( t3 = new TextComponent( "Mango, " ) ); - Assert.assertEquals( builder.getCursor(), 2 ); + assertEquals( builder.getCursor(), 2 ); builder.setCursor( 0 ); - Assert.assertEquals( builder.getCurrentComponent(), t1 ); + assertEquals( builder.getCurrentComponent(), t1 ); // Test that appending new components updates the position to the new list size // after having previously set it to 0 (first component) builder.append( new TextComponent( "and Grapefruit" ) ); - Assert.assertEquals( builder.getCursor(), 3 ); + assertEquals( builder.getCursor(), 3 ); builder.setCursor( 0 ); builder.resetCursor(); - Assert.assertEquals( builder.getCursor(), 3 ); + assertEquals( builder.getCursor(), 3 ); } @Test @@ -210,7 +210,7 @@ public class ComponentsTest String text = "§a§lHello §r§kworld§7!"; BaseComponent[] components = TextComponent.fromLegacyText( text ); BaseComponent[] builderComponents = new ComponentBuilder().append( components ).create(); - Assert.assertArrayEquals( components, builderComponents ); + assertArrayEquals( components, builderComponents ); } /* @@ -232,7 +232,7 @@ public class ComponentsTest component.setHoverEvent( event ); String serialised = ComponentSerializer.toString( component ); BaseComponent[] deserialised = ComponentSerializer.parse( serialised ); - Assert.assertEquals( TextComponent.toLegacyText( deserialised ), TextComponent.toLegacyText( component ) ); + assertEquals( TextComponent.toLegacyText( deserialised ), TextComponent.toLegacyText( component ) ); } */ @@ -247,9 +247,9 @@ public class ComponentsTest ); TextComponent component = new TextComponent( "test" ); component.setHoverEvent( hoverEvent ); - Assert.assertEquals( component.getHoverEvent().getContents().size(), 1 ); - Assert.assertTrue( component.getHoverEvent().getContents().get( 0 ) instanceof Text ); - Assert.assertEquals( ( (Text) component.getHoverEvent().getContents().get( 0 ) ).getValue(), advancement ); + assertEquals( component.getHoverEvent().getContents().size(), 1 ); + assertTrue( component.getHoverEvent().getContents().get( 0 ) instanceof Text ); + assertEquals( ( (Text) component.getHoverEvent().getContents().get( 0 ) ).getValue(), advancement ); } @Test @@ -274,11 +274,11 @@ public class ComponentsTest TextComponent component = new TextComponent( "Sample text" ); component.setHoverEvent( hoverEvent ); - Assert.assertEquals( hoverEvent.getContents().size(), 1 ); - Assert.assertTrue( hoverEvent.isLegacy() ); + assertEquals( hoverEvent.getContents().size(), 1 ); + assertTrue( hoverEvent.isLegacy() ); String serialized = ComponentSerializer.toString( component ); BaseComponent[] deserialized = ComponentSerializer.parse( serialized ); - Assert.assertEquals( component.getHoverEvent(), deserialized[0].getHoverEvent() ); + assertEquals( component.getHoverEvent(), deserialized[0].getHoverEvent() ); } @Test @@ -303,12 +303,12 @@ public class ComponentsTest { TextComponent component = new TextComponent( "Sample text" ); component.setHoverEvent( hoverEvent ); - Assert.assertEquals( hoverEvent.getContents().size(), 2 ); - Assert.assertFalse( hoverEvent.isLegacy() ); + assertEquals( hoverEvent.getContents().size(), 2 ); + assertFalse( hoverEvent.isLegacy() ); String serialized = ComponentSerializer.toString( component ); T deserialized = deserializer.apply( serialized ); - Assert.assertEquals( component.getHoverEvent(), hoverEventGetter.apply( deserialized ) ); + assertEquals( component.getHoverEvent(), hoverEventGetter.apply( deserialized ) ); // Test single content: String json = "{\"italic\":true,\"color\":\"gray\",\"translate\":\"chat.type.admin\",\"with\":[{\"text\":\"@\"}" @@ -345,10 +345,10 @@ public class ComponentsTest TextComponent second = new TextComponent( " world" ); second.copyFormatting( first, ComponentBuilder.FormatRetention.ALL, true ); - Assert.assertEquals( first.isBold(), second.isBold() ); - Assert.assertEquals( first.getColor(), second.getColor() ); - Assert.assertEquals( first.getClickEvent(), second.getClickEvent() ); - Assert.assertEquals( first.getHoverEvent(), second.getHoverEvent() ); + assertEquals( first.isBold(), second.isBold() ); + assertEquals( first.getColor(), second.getColor() ); + assertEquals( first.getClickEvent(), second.getClickEvent() ); + assertEquals( first.getHoverEvent(), second.getHoverEvent() ); } @Test @@ -368,7 +368,7 @@ public class ComponentsTest ComponentBuilder builder = new ComponentBuilder( "Hello " ).color( ChatColor.RED ).append( "world" ).color( ChatColor.DARK_RED ); ComponentBuilder cloned = new ComponentBuilder( builder ); - Assert.assertEquals( legacyTextFunction.apply( builder ), legacyTextFunction.apply( cloned ) ); + assertEquals( legacyTextFunction.apply( builder ), legacyTextFunction.apply( cloned ) ); } @Test @@ -403,10 +403,10 @@ public class ComponentsTest ScoreComponent scoreComponent = new ScoreComponent( "myscore", "myobjective" ); builder.append( scoreComponent ); // non array based BaseComponent append T component = componentBuilder.apply( builder ); - Assert.assertEquals( "Hello ", extraGetter.apply( component, 0 ).toPlainText() ); - Assert.assertEquals( textComponent.toPlainText(), extraGetter.apply( component, 1 ).toPlainText() ); - Assert.assertEquals( translatableComponent.toPlainText(), extraGetter.apply( component, 2 ).toPlainText() ); - Assert.assertEquals( scoreComponent.toPlainText(), extraGetter.apply( component, 3 ).toPlainText() ); + assertEquals( "Hello ", extraGetter.apply( component, 0 ).toPlainText() ); + assertEquals( textComponent.toPlainText(), extraGetter.apply( component, 1 ).toPlainText() ); + assertEquals( translatableComponent.toPlainText(), extraGetter.apply( component, 2 ).toPlainText() ); + assertEquals( scoreComponent.toPlainText(), extraGetter.apply( component, 3 ).toPlainText() ); } @Test @@ -416,7 +416,7 @@ public class ComponentsTest String text = ComponentSerializer.toString( component ); BaseComponent[] reparsed = ComponentSerializer.parse( text ); - Assert.assertArrayEquals( component, reparsed ); + assertArrayEquals( component, reparsed ); } @Test @@ -456,10 +456,10 @@ public class ComponentsTest T component = componentBuilder.apply( builder ); - Assert.assertEquals( extraGetter.apply( component, 1 ).getHoverEvent(), hoverEvent ); - Assert.assertEquals( extraGetter.apply( component, 1 ).getClickEvent(), clickEvent ); - Assert.assertEquals( "Hello world!", toPlainTextFunction.apply( component ) ); - Assert.assertEquals( expectedLegacyText, toLegacyTextFunction.apply( component ) ); + assertEquals( extraGetter.apply( component, 1 ).getHoverEvent(), hoverEvent ); + assertEquals( extraGetter.apply( component, 1 ).getClickEvent(), clickEvent ); + assertEquals( "Hello world!", toPlainTextFunction.apply( component ) ); + assertEquals( expectedLegacyText, toLegacyTextFunction.apply( component ) ); } @Test @@ -492,8 +492,8 @@ public class ComponentsTest T component = componentBuilder.apply( builder ); - Assert.assertEquals( "Hello world!", toPlainTextFunction.apply( component ) ); - Assert.assertEquals( expectedLegacyString, toLegacyTextFunction.apply( component ) ); + assertEquals( "Hello world!", toPlainTextFunction.apply( component ) ); + assertEquals( expectedLegacyString, toLegacyTextFunction.apply( component ) ); } @Test @@ -502,8 +502,8 @@ public class ComponentsTest TextComponent textComponent = new TextComponent( "Hello world" ); textComponent.setColor( ChatColor.RED ); - Assert.assertEquals( "Hello world", textComponent.toPlainText() ); - Assert.assertEquals( ChatColor.RED + "Hello world", textComponent.toLegacyText() ); + assertEquals( "Hello world", textComponent.toPlainText() ); + assertEquals( ChatColor.RED + "Hello world", textComponent.toLegacyText() ); } @Test @@ -511,25 +511,25 @@ public class ComponentsTest { 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 ) ); + assertEquals( "Aqua RedBold", BaseComponent.toPlainText( test1 ) ); + 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 ) ); + assertEquals( "Text http://spigotmc.org google.com/test", BaseComponent.toPlainText( test2 ) ); //The extra ChatColor instances 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 + assertEquals( ChatColor.WHITE + "Text " + ChatColor.WHITE + "http://spigotmc.org" + ChatColor.WHITE + " " + ChatColor.GREEN + "google.com/test" + ChatColor.GREEN, 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() ); + assertNotNull( url1 ); + assertTrue( url1.getAction() == ClickEvent.Action.OPEN_URL ); + 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() ); + assertNotNull( url2 ); + assertTrue( url2.getAction() == ClickEvent.Action.OPEN_URL ); + assertEquals( "http://google.com/test", url2.getValue() ); } @Test @@ -541,18 +541,18 @@ public class ComponentsTest item, "5", "thinkofdeath" ); - Assert.assertEquals( "Given Golden Sword * 5 to thinkofdeath", translatableComponent.toPlainText() ); - Assert.assertEquals( ChatColor.WHITE + "Given " + ChatColor.AQUA + "Golden Sword" + ChatColor.WHITE + assertEquals( "Given Golden Sword * 5 to thinkofdeath", translatableComponent.toPlainText() ); + assertEquals( ChatColor.WHITE + "Given " + ChatColor.AQUA + "Golden Sword" + ChatColor.WHITE + " * " + 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() ); + assertEquals( "Page 5 of 50", positional.toPlainText() ); + assertEquals( ChatColor.WHITE + "Page " + ChatColor.WHITE + "5" + ChatColor.WHITE + " of " + ChatColor.WHITE + "50", positional.toLegacyText() ); TranslatableComponent one_four_two = new TranslatableComponent( "filled_map.buried_treasure" ); - Assert.assertEquals( "Buried Treasure Map", one_four_two.toPlainText() ); + assertEquals( "Buried Treasure Map", one_four_two.toPlainText() ); } @Test @@ -586,8 +586,8 @@ public class ComponentsTest append( "World" ).bold( true ).color( ChatColor.BLUE ). append( "!" ).color( ChatColor.YELLOW ) ); - Assert.assertEquals( "Hello World!", toPlainTextFunction.apply( component ) ); - Assert.assertEquals( expectedLegacyString, toLegacyTextFunction.apply( component ) ); + assertEquals( "Hello World!", toPlainTextFunction.apply( component ) ); + assertEquals( expectedLegacyString, toLegacyTextFunction.apply( component ) ); } @Test @@ -613,8 +613,8 @@ public class ComponentsTest T component = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( ChatColor.RED ) .append( "World" ).reset() ); - Assert.assertEquals( ChatColor.RED, extraGetter.apply( component, 0 ).getColor() ); - Assert.assertEquals( ChatColor.WHITE, extraGetter.apply( component, 1 ).getColor() ); + assertEquals( ChatColor.RED, extraGetter.apply( component, 0 ).getColor() ); + assertEquals( ChatColor.WHITE, extraGetter.apply( component, 1 ).getColor() ); } @Test @@ -640,41 +640,41 @@ public class ComponentsTest T noneRetention = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( ChatColor.RED ) .append( "World", ComponentBuilder.FormatRetention.NONE ) ); - Assert.assertEquals( ChatColor.RED, extraGetter.apply( noneRetention, 0 ).getColor() ); - Assert.assertEquals( ChatColor.WHITE, extraGetter.apply( noneRetention, 1 ).getColor() ); + assertEquals( ChatColor.RED, extraGetter.apply( noneRetention, 0 ).getColor() ); + assertEquals( ChatColor.WHITE, extraGetter.apply( noneRetention, 1 ).getColor() ); HoverEvent testEvent = new HoverEvent( HoverEvent.Action.SHOW_TEXT, new Text( new ComponentBuilder( "test" ).build() ) ); T formattingRetention = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( ChatColor.RED ) .event( testEvent ).append( "World", ComponentBuilder.FormatRetention.FORMATTING ) ); - Assert.assertEquals( ChatColor.RED, extraGetter.apply( formattingRetention, 0 ).getColor() ); - Assert.assertEquals( testEvent, extraGetter.apply( formattingRetention, 0 ).getHoverEvent() ); - Assert.assertEquals( ChatColor.RED, extraGetter.apply( formattingRetention, 1 ).getColor() ); - Assert.assertNull( extraGetter.apply( formattingRetention, 1 ).getHoverEvent() ); + assertEquals( ChatColor.RED, extraGetter.apply( formattingRetention, 0 ).getColor() ); + assertEquals( testEvent, extraGetter.apply( formattingRetention, 0 ).getHoverEvent() ); + assertEquals( ChatColor.RED, extraGetter.apply( formattingRetention, 1 ).getColor() ); + assertNull( extraGetter.apply( formattingRetention, 1 ).getHoverEvent() ); ClickEvent testClickEvent = new ClickEvent( ClickEvent.Action.OPEN_URL, "http://www.example.com" ); T eventRetention = componentBuilder.apply( new ComponentBuilder( "Hello " ).color( ChatColor.RED ) .event( testEvent ).event( testClickEvent ).append( "World", ComponentBuilder.FormatRetention.EVENTS ) ); - Assert.assertEquals( ChatColor.RED, extraGetter.apply( eventRetention, 0 ).getColor() ); - Assert.assertEquals( testEvent, extraGetter.apply( eventRetention, 0 ).getHoverEvent() ); - Assert.assertEquals( testClickEvent, extraGetter.apply( eventRetention, 0 ).getClickEvent() ); - Assert.assertEquals( ChatColor.WHITE, extraGetter.apply( eventRetention, 1 ).getColor() ); - Assert.assertEquals( testEvent, extraGetter.apply( eventRetention, 1 ).getHoverEvent() ); - Assert.assertEquals( testClickEvent, extraGetter.apply( eventRetention, 1 ).getClickEvent() ); + assertEquals( ChatColor.RED, extraGetter.apply( eventRetention, 0 ).getColor() ); + assertEquals( testEvent, extraGetter.apply( eventRetention, 0 ).getHoverEvent() ); + assertEquals( testClickEvent, extraGetter.apply( eventRetention, 0 ).getClickEvent() ); + assertEquals( ChatColor.WHITE, extraGetter.apply( eventRetention, 1 ).getColor() ); + assertEquals( testEvent, extraGetter.apply( eventRetention, 1 ).getHoverEvent() ); + assertEquals( testClickEvent, extraGetter.apply( eventRetention, 1 ).getClickEvent() ); } - @Test(expected = IllegalArgumentException.class) + @Test public void testLoopSimple() { TextComponent component = new TextComponent( "Testing" ); component.addExtra( component ); - ComponentSerializer.toString( component ); + assertThrows( IllegalArgumentException.class, () -> ComponentSerializer.toString( component ) ); } - @Test(expected = IllegalArgumentException.class) + @Test public void testLoopComplex() { TextComponent a = new TextComponent( "A" ); @@ -685,7 +685,7 @@ public class ComponentsTest a.addExtra( b ); b.addExtra( c ); c.addExtra( a ); - ComponentSerializer.toString( a ); + assertThrows( IllegalArgumentException.class, () -> ComponentSerializer.toString( a ) ); } @Test @@ -699,7 +699,7 @@ public class ComponentsTest ComponentSerializer.toString( a ); } - @Test(expected = IllegalArgumentException.class) + @Test public void testRepeatedError() { TextComponent a = new TextComponent( "A" ); @@ -711,7 +711,7 @@ public class ComponentsTest a.addExtra( c ); c.addExtra( a ); a.addExtra( b ); - ComponentSerializer.toString( a ); + assertThrows( IllegalArgumentException.class, () -> ComponentSerializer.toString( a ) ); } @Test @@ -736,7 +736,7 @@ public class ComponentsTest String emptyLegacyText = fromAndToLegacyText( "" ); // all invalid color codes and the trailing '§' should be ignored - Assert.assertEquals( emptyLegacyText, invalidColorCodesLegacyText ); + assertEquals( emptyLegacyText, invalidColorCodesLegacyText ); } @Test @@ -745,12 +745,12 @@ public class ComponentsTest String text = "§a"; BaseComponent[] converted = TextComponent.fromLegacyText( text ); - Assert.assertEquals( ChatColor.GREEN, converted[0].getColor() ); + assertEquals( ChatColor.GREEN, converted[0].getColor() ); String roundtripLegacyText = BaseComponent.toLegacyText( converted ); // color code should not be lost during conversion - Assert.assertEquals( text, roundtripLegacyText ); + assertEquals( text, roundtripLegacyText ); } @Test @@ -762,7 +762,7 @@ public class ComponentsTest TextComponent second = new TextComponent( "Hello, " ); second.addExtra( new TextComponent( "World!" ) ); - Assert.assertEquals( first, second ); + assertEquals( first, second ); } @Test @@ -774,7 +774,7 @@ public class ComponentsTest TextComponent second = new TextComponent( "Hello, " ); second.addExtra( new TextComponent( "World!" ) ); - Assert.assertNotEquals( first, second ); + assertNotEquals( first, second ); } @Test @@ -785,7 +785,7 @@ public class ComponentsTest BaseComponent[] reColored = TextComponent.fromLegacyText( legacy ); - Assert.assertArrayEquals( hexColored, reColored ); + assertArrayEquals( hexColored, reColored ); } @Test @@ -817,18 +817,18 @@ public class ComponentsTest String expected = "{\"extra\":[{\"underlined\":true,\"color\":\"dark_red\",\"text\":\"44444\"},{\"color\":" + "\"white\",\"text\":\"dd\"},{\"bold\":true,\"color\":\"gold\",\"text\":\"6666\"}],\"text\":\"\"}"; - Assert.assertEquals( expected, ComponentSerializer.toString( a ) ); + assertEquals( expected, ComponentSerializer.toString( a ) ); builder.append( a ); String test1 = componentSerializer.apply( componentBuilder.apply( builder ) ); - Assert.assertEquals( expected, test1 ); + assertEquals( expected, test1 ); BaseComponent[] b = TextComponent.fromLegacyText( "§rrrrr" ); builder.append( b ); String test2 = componentSerializer.apply( componentBuilder.apply( builder ) ); - Assert.assertEquals( + assertEquals( "{\"extra\":[{\"underlined\":true,\"color\":\"dark_red\",\"text\":\"44444\"}," + "{\"color\":\"white\",\"text\":\"dd\"},{\"bold\":true,\"color\":\"gold\",\"text\":\"6666\"}," + "{\"color\":\"white\",\"text\":\"rrrr\"}],\"text\":\"\"}", 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 9e37eed0..9ec5dcb1 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 @@ -1,8 +1,8 @@ package net.md_5.bungee.api.chat; +import static org.junit.jupiter.api.Assertions.*; import net.md_5.bungee.chat.ComponentSerializer; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TranslatableComponentTest { @@ -11,8 +11,8 @@ public class TranslatableComponentTest public void testMissingPlaceholdersAdded() { TranslatableComponent testComponent = new TranslatableComponent( "Test string with %s placeholders: %s", 2, "aoeu" ); - Assert.assertEquals( "Test string with 2 placeholders: aoeu", testComponent.toPlainText() ); - Assert.assertEquals( "§fTest string with §f2§f placeholders: §faoeu", testComponent.toLegacyText() ); + assertEquals( "Test string with 2 placeholders: aoeu", testComponent.toPlainText() ); + assertEquals( "§fTest string with §f2§f placeholders: §faoeu", testComponent.toLegacyText() ); } @Test @@ -22,7 +22,7 @@ public class TranslatableComponentTest String jsonString = ComponentSerializer.toString( testComponent ); BaseComponent[] baseComponents = ComponentSerializer.parse( jsonString ); - Assert.assertEquals( "Test string with a placeholder", TextComponent.toPlainText( baseComponents ) ); - Assert.assertEquals( "§fTest string with §fa§f placeholder", TextComponent.toLegacyText( baseComponents ) ); + assertEquals( "Test string with a placeholder", TextComponent.toPlainText( baseComponents ) ); + assertEquals( "§fTest string with §fa§f placeholder", TextComponent.toLegacyText( baseComponents ) ); } } diff --git a/checkstyle.xml b/checkstyle.xml index 3acb90f5..44a84d72 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -36,7 +36,6 @@ - diff --git a/config/src/test/java/net/md_5/bungee/config/CompoundConfigurationTest.java b/config/src/test/java/net/md_5/bungee/config/CompoundConfigurationTest.java index f5573331..8f3383a3 100644 --- a/config/src/test/java/net/md_5/bungee/config/CompoundConfigurationTest.java +++ b/config/src/test/java/net/md_5/bungee/config/CompoundConfigurationTest.java @@ -1,148 +1,138 @@ package net.md_5.bungee.config; +import static org.junit.jupiter.api.Assertions.*; import java.io.StringReader; import java.io.StringWriter; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import lombok.RequiredArgsConstructor; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; @RequiredArgsConstructor -@RunWith(Parameterized.class) public class CompoundConfigurationTest { - @Parameters(name = "{0}") - public static Iterable data() + public static Stream data() { - // CHECKSTYLE:OFF - return Arrays.asList( new Object[][] - { - { - // provider - YamlConfiguration.class, - // testDocument - "" - + "receipt: Oz-Ware Purchase Invoice\n" - + "date: 2012-08-06\n" - + "customer:\n" - + " given: Dorothy\n" - + " family: Gale\n" - + "\n" - + "items:\n" - + " - part_no: A4786\n" - + " descrip: Water Bucket (Filled)\n" - + " price: 1.47\n" - + " quantity: 4\n" - + "\n" - + " - part_no: E1628\n" - + " descrip: High Heeled \"Ruby\" Slippers\n" - + " size: 8\n" - + " price: 100.27\n" - + " quantity: 1\n" - + "\n" - + "bill-to: &id001\n" - + " street: |\n" - + " 123 Tornado Alley\n" - + " Suite 16\n" - + " city: East Centerville\n" - + " state: KS\n" - + "\n" - + "ship-to: *id001\n" - + "\n" - + "specialDelivery: >\n" - + " Follow the Yellow Brick\n" - + " Road to the Emerald City.\n" - + " Pay no attention to the\n" - + " man behind the curtain.", - // numberTest - "" - + "someKey:\n" - + " 1: 1\n" - + " 2: 2\n" - + " 3: 3\n" - + " 4: 4", - // nullTest - "" - + "null:\n" - + " null: object\n" - + " object: null\n" - }, - { - // provider - JsonConfiguration.class, - // testDocument - "" - + "{\n" - + " \"customer\": {\n" - + " \"given\": \"Dorothy\", \n" - + " \"family\": \"Gale\"\n" - + " }, \n" - + " \"ship-to\": {\n" - + " \"city\": \"East Centerville\", \n" - + " \"state\": \"KS\", \n" - + " \"street\": \"123 Tornado Alley\\nSuite 16\\n\"\n" - + " }, \n" - + " \"bill-to\": {\n" - + " \"city\": \"East Centerville\", \n" - + " \"state\": \"KS\", \n" - + " \"street\": \"123 Tornado Alley\\nSuite 16\\n\"\n" - + " }, \n" - + " \"date\": \"2012-08-06\", \n" - + " \"items\": [\n" - + " {\n" - + " \"part_no\": \"A4786\", \n" - + " \"price\": 1.47, \n" - + " \"descrip\": \"Water Bucket (Filled)\", \n" - + " \"quantity\": 4\n" - + " }, \n" - + " {\n" - + " \"part_no\": \"E1628\", \n" - + " \"descrip\": \"High Heeled \\\"Ruby\\\" Slippers\", \n" - + " \"price\": 100.27, \n" - + " \"quantity\": 1, \n" - + " \"size\": 8\n" - + " }\n" - + " ], \n" - + " \"receipt\": \"Oz-Ware Purchase Invoice\", \n" - + " \"specialDelivery\": \"Follow the Yellow Brick Road to the Emerald City. Pay no attention to the man behind the curtain.\"\n" - + "}", - // numberTest - "" - + "{\n" - + " \"someKey\": {\n" - + " \"1\": 1, \n" - + " \"2\": 2, \n" - + " \"3\": 3, \n" - + " \"4\": 4\n" - + " }\n" - + "}", - // nullTest - "" - + "{\n" - + " \"null\": {\n" - + " \"null\": \"object\", \n" - + " \"object\": null\n" - + " }\n" - + "}" - } - } ); - // CHECKSTYLE:ON + return Stream.of( + Arguments.of( + // provider + YamlConfiguration.class, + // testDocument + "" + + "receipt: Oz-Ware Purchase Invoice\n" + + "date: 2012-08-06\n" + + "customer:\n" + + " given: Dorothy\n" + + " family: Gale\n" + + "\n" + + "items:\n" + + " - part_no: A4786\n" + + " descrip: Water Bucket (Filled)\n" + + " price: 1.47\n" + + " quantity: 4\n" + + "\n" + + " - part_no: E1628\n" + + " descrip: High Heeled \"Ruby\" Slippers\n" + + " size: 8\n" + + " price: 100.27\n" + + " quantity: 1\n" + + "\n" + + "bill-to: &id001\n" + + " street: |\n" + + " 123 Tornado Alley\n" + + " Suite 16\n" + + " city: East Centerville\n" + + " state: KS\n" + + "\n" + + "ship-to: *id001\n" + + "\n" + + "specialDelivery: >\n" + + " Follow the Yellow Brick\n" + + " Road to the Emerald City.\n" + + " Pay no attention to the\n" + + " man behind the curtain.", + // numberTest + "" + + "someKey:\n" + + " 1: 1\n" + + " 2: 2\n" + + " 3: 3\n" + + " 4: 4", + // nullTest + "" + + "null:\n" + + " null: object\n" + + " object: null\n" + ), + Arguments.of( + // provider + JsonConfiguration.class, + // testDocument + "" + + "{\n" + + " \"customer\": {\n" + + " \"given\": \"Dorothy\", \n" + + " \"family\": \"Gale\"\n" + + " }, \n" + + " \"ship-to\": {\n" + + " \"city\": \"East Centerville\", \n" + + " \"state\": \"KS\", \n" + + " \"street\": \"123 Tornado Alley\\nSuite 16\\n\"\n" + + " }, \n" + + " \"bill-to\": {\n" + + " \"city\": \"East Centerville\", \n" + + " \"state\": \"KS\", \n" + + " \"street\": \"123 Tornado Alley\\nSuite 16\\n\"\n" + + " }, \n" + + " \"date\": \"2012-08-06\", \n" + + " \"items\": [\n" + + " {\n" + + " \"part_no\": \"A4786\", \n" + + " \"price\": 1.47, \n" + + " \"descrip\": \"Water Bucket (Filled)\", \n" + + " \"quantity\": 4\n" + + " }, \n" + + " {\n" + + " \"part_no\": \"E1628\", \n" + + " \"descrip\": \"High Heeled \\\"Ruby\\\" Slippers\", \n" + + " \"price\": 100.27, \n" + + " \"quantity\": 1, \n" + + " \"size\": 8\n" + + " }\n" + + " ], \n" + + " \"receipt\": \"Oz-Ware Purchase Invoice\", \n" + + " \"specialDelivery\": \"Follow the Yellow Brick Road to the Emerald City. Pay no attention to the man behind the curtain.\"\n" + + "}", + // numberTest + "" + + "{\n" + + " \"someKey\": {\n" + + " \"1\": 1, \n" + + " \"2\": 2, \n" + + " \"3\": 3, \n" + + " \"4\": 4\n" + + " }\n" + + "}", + // nullTest + "" + + "{\n" + + " \"null\": {\n" + + " \"null\": \"object\", \n" + + " \"object\": null\n" + + " }\n" + + "}" + ) + ); } - // - private final Class provider; - private final String testDocument; - private final String numberTest; - private final String nullTest; - @Test - public void testConfig() throws Exception + @ParameterizedTest + @MethodSource("data") + public void testConfig(Class provider, String testDocument, String numberTest, String nullTest) throws Exception { Configuration conf = ConfigurationProvider.getProvider( provider ).load( testDocument ); testSection( conf ); @@ -151,7 +141,7 @@ public class CompoundConfigurationTest ConfigurationProvider.getProvider( provider ).save( conf, sw ); // Check nulls were saved, see #1094 - Assert.assertFalse( "Config contains null", sw.toString().contains( "null" ) ); + assertFalse( sw.toString().contains( "null" ), "Config contains null" ); conf = ConfigurationProvider.getProvider( provider ).load( new StringReader( sw.toString() ) ); conf.set( "receipt", "Oz-Ware Purchase Invoice" ); // Add it back @@ -160,37 +150,38 @@ public class CompoundConfigurationTest private void testSection(Configuration conf) { - Assert.assertEquals( "receipt", "Oz-Ware Purchase Invoice", conf.getString( "receipt" ) ); - // Assert.assertEquals( "date", "2012-08-06", conf.get( "date" ).toString() ); + assertEquals( "Oz-Ware Purchase Invoice", conf.getString( "receipt" ), "receipt" ); + // assertEquals( "2012-08-06", conf.get( "date" ).toString(), "date" ); Configuration customer = conf.getSection( "customer" ); - Assert.assertEquals( "customer.given", "Dorothy", customer.getString( "given" ) ); - Assert.assertEquals( "customer.given", "Dorothy", conf.getString( "customer.given" ) ); + assertEquals( "Dorothy", customer.getString( "given" ), "customer.given" ); + assertEquals( "Dorothy", conf.getString( "customer.given" ), "customer.given" ); List items = conf.getList( "items" ); Map item = (Map) items.get( 0 ); - Assert.assertEquals( "items[0].part_no", "A4786", item.get( "part_no" ) ); + assertEquals( "A4786", item.get( "part_no" ), "items[0].part_no" ); conf.set( "receipt", null ); - Assert.assertEquals( null, conf.get( "receipt" ) ); - Assert.assertEquals( "foo", conf.get( "receipt", "foo" ) ); + assertEquals( null, conf.get( "receipt" ) ); + assertEquals( "foo", conf.get( "receipt", "foo" ) ); Configuration newSection = conf.getSection( "new.section" ); newSection.set( "value", "foo" ); - Assert.assertEquals( "foo", conf.get( "new.section.value" ) ); + assertEquals( "foo", conf.get( "new.section.value" ) ); conf.set( "other.new.section", "bar" ); - Assert.assertEquals( "bar", conf.get( "other.new.section" ) ); + assertEquals( "bar", conf.get( "other.new.section" ) ); - Assert.assertTrue( conf.contains( "customer.given" ) ); - Assert.assertTrue( customer.contains( "given" ) ); + assertTrue( conf.contains( "customer.given" ) ); + assertTrue( customer.contains( "given" ) ); - Assert.assertFalse( conf.contains( "customer.foo" ) ); - Assert.assertFalse( customer.contains( "foo" ) ); + assertFalse( conf.contains( "customer.foo" ) ); + assertFalse( customer.contains( "foo" ) ); } - @Test - public void testNumberedKeys() + @ParameterizedTest + @MethodSource("data") + public void testNumberedKeys(Class provider, String testDocument, String numberTest, String nullTest) { Configuration conf = ConfigurationProvider.getProvider( provider ).load( numberTest ); @@ -201,29 +192,31 @@ public class CompoundConfigurationTest } } - @Test - public void testNull() + @ParameterizedTest + @MethodSource("data") + public void testNull(Class provider, String testDocument, String numberTest, String nullTest) { Configuration conf = ConfigurationProvider.getProvider( provider ).load( nullTest ); - Assert.assertEquals( "object", conf.get( "null.null" ) ); - Assert.assertEquals( "object", conf.getSection( "null" ).get( "null" ) ); + assertEquals( "object", conf.get( "null.null" ) ); + assertEquals( "object", conf.getSection( "null" ).get( "null" ) ); - Assert.assertEquals( null, conf.get( "null.object" ) ); - Assert.assertEquals( "", conf.getString( "null.object" ) ); + assertEquals( null, conf.get( "null.object" ) ); + assertEquals( "", conf.getString( "null.object" ) ); } - @Test - public void testMapAddition() + @ParameterizedTest + @MethodSource("data") + public void testMapAddition(Class provider, String testDocument, String numberTest, String nullTest) { Configuration conf = ConfigurationProvider.getProvider( provider ).load( testDocument ); conf.set( "addition", Collections.singletonMap( "foo", "bar" ) ); // Order matters - Assert.assertEquals( "bar", conf.getSection( "addition" ).getString( "foo" ) ); - Assert.assertEquals( "bar", conf.getString( "addition.foo" ) ); + assertEquals( "bar", conf.getSection( "addition" ).getString( "foo" ) ); + assertEquals( "bar", conf.getString( "addition.foo" ) ); - Assert.assertTrue( conf.get( "addition" ) instanceof Configuration ); + assertTrue( conf.get( "addition" ) instanceof Configuration ); } } diff --git a/config/src/test/java/net/md_5/bungee/config/DefaultConfigurationTest.java b/config/src/test/java/net/md_5/bungee/config/DefaultConfigurationTest.java index 3ea12bb1..4dbd962d 100644 --- a/config/src/test/java/net/md_5/bungee/config/DefaultConfigurationTest.java +++ b/config/src/test/java/net/md_5/bungee/config/DefaultConfigurationTest.java @@ -1,7 +1,7 @@ package net.md_5.bungee.config; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class DefaultConfigurationTest { @@ -16,8 +16,8 @@ public class DefaultConfigurationTest Configuration actualConfig = new Configuration( defaultConfig ); - Assert.assertEquals( 10, actualConfig.getInt( "setting" ) ); - Assert.assertEquals( 11, actualConfig.getInt( "nested.setting" ) ); - Assert.assertEquals( 12, actualConfig.getInt( "double.nested.setting" ) ); + assertEquals( 10, actualConfig.getInt( "setting" ) ); + assertEquals( 11, actualConfig.getInt( "nested.setting" ) ); + assertEquals( 12, actualConfig.getInt( "double.nested.setting" ) ); } } diff --git a/event/src/test/java/net/md_5/bungee/event/EventBusTest.java b/event/src/test/java/net/md_5/bungee/event/EventBusTest.java index 2c737675..da2aa05d 100644 --- a/event/src/test/java/net/md_5/bungee/event/EventBusTest.java +++ b/event/src/test/java/net/md_5/bungee/event/EventBusTest.java @@ -1,8 +1,8 @@ package net.md_5.bungee.event; +import static org.junit.jupiter.api.Assertions.*; import java.util.concurrent.CountDownLatch; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class EventBusTest { @@ -15,14 +15,14 @@ public class EventBusTest { bus.register( this ); bus.post( new FirstEvent() ); - Assert.assertEquals( 0, latch.getCount() ); + assertEquals( 0, latch.getCount() ); } @EventHandler public void firstListener(FirstEvent event) { bus.post( new SecondEvent() ); - Assert.assertEquals( 1, latch.getCount() ); + assertEquals( 1, latch.getCount() ); latch.countDown(); } diff --git a/event/src/test/java/net/md_5/bungee/event/EventPriorityTest.java b/event/src/test/java/net/md_5/bungee/event/EventPriorityTest.java index 351d3724..3c5d45ea 100644 --- a/event/src/test/java/net/md_5/bungee/event/EventPriorityTest.java +++ b/event/src/test/java/net/md_5/bungee/event/EventPriorityTest.java @@ -1,8 +1,8 @@ package net.md_5.bungee.event; +import static org.junit.jupiter.api.Assertions.*; import java.util.concurrent.CountDownLatch; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class EventPriorityTest { @@ -16,41 +16,41 @@ public class EventPriorityTest bus.register( this ); bus.register( new EventPriorityListenerPartner() ); bus.post( new PriorityTestEvent() ); - Assert.assertEquals( 0, latch.getCount() ); + assertEquals( 0, latch.getCount() ); } @EventHandler(priority = Byte.MIN_VALUE) public void onMinPriority(PriorityTestEvent event) { - Assert.assertEquals( 7, latch.getCount() ); + assertEquals( 7, latch.getCount() ); latch.countDown(); } @EventHandler(priority = EventPriority.LOWEST) public void onLowestPriority(PriorityTestEvent event) { - Assert.assertEquals( 6, latch.getCount() ); + assertEquals( 6, latch.getCount() ); latch.countDown(); } @EventHandler public void onNormalPriority(PriorityTestEvent event) { - Assert.assertEquals( 4, latch.getCount() ); + assertEquals( 4, latch.getCount() ); latch.countDown(); } @EventHandler(priority = EventPriority.HIGHEST) public void onHighestPriority(PriorityTestEvent event) { - Assert.assertEquals( 2, latch.getCount() ); + assertEquals( 2, latch.getCount() ); latch.countDown(); } @EventHandler(priority = Byte.MAX_VALUE) public void onMaxPriority(PriorityTestEvent event) { - Assert.assertEquals( 1, latch.getCount() ); + assertEquals( 1, latch.getCount() ); latch.countDown(); } @@ -64,14 +64,14 @@ public class EventPriorityTest @EventHandler(priority = EventPriority.HIGH) public void onHighPriority(PriorityTestEvent event) { - Assert.assertEquals( 3, latch.getCount() ); + assertEquals( 3, latch.getCount() ); latch.countDown(); } @EventHandler(priority = EventPriority.LOW) public void onLowPriority(PriorityTestEvent event) { - Assert.assertEquals( 5, latch.getCount() ); + assertEquals( 5, latch.getCount() ); latch.countDown(); } } diff --git a/event/src/test/java/net/md_5/bungee/event/SubclassTest.java b/event/src/test/java/net/md_5/bungee/event/SubclassTest.java index be4b3804..50b4fde7 100644 --- a/event/src/test/java/net/md_5/bungee/event/SubclassTest.java +++ b/event/src/test/java/net/md_5/bungee/event/SubclassTest.java @@ -1,8 +1,8 @@ package net.md_5.bungee.event; +import static org.junit.jupiter.api.Assertions.*; import java.util.concurrent.CountDownLatch; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SubclassTest extends EventBusTest { @@ -14,13 +14,13 @@ public class SubclassTest extends EventBusTest public void testNestedEvents() { super.testNestedEvents(); - Assert.assertEquals( 0, latch.getCount() ); + assertEquals( 0, latch.getCount() ); } @EventHandler protected void extraListener(FirstEvent event) { - Assert.assertEquals( 1, latch.getCount() ); + assertEquals( 1, latch.getCount() ); latch.countDown(); } } diff --git a/event/src/test/java/net/md_5/bungee/event/UnregisteringListenerTest.java b/event/src/test/java/net/md_5/bungee/event/UnregisteringListenerTest.java index fbfbd546..014de202 100644 --- a/event/src/test/java/net/md_5/bungee/event/UnregisteringListenerTest.java +++ b/event/src/test/java/net/md_5/bungee/event/UnregisteringListenerTest.java @@ -1,7 +1,7 @@ package net.md_5.bungee.event; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.fail; +import org.junit.jupiter.api.Test; public class UnregisteringListenerTest { @@ -19,7 +19,7 @@ public class UnregisteringListenerTest @EventHandler public void onEvent(TestEvent evt) { - Assert.fail( "Event listener wasn't unregistered" ); + fail( "Event listener wasn't unregistered" ); } public static class TestEvent diff --git a/native/src/test/java/net/md_5/bungee/NativeCipherTest.java b/native/src/test/java/net/md_5/bungee/NativeCipherTest.java index b67862ea..f6833ebd 100644 --- a/native/src/test/java/net/md_5/bungee/NativeCipherTest.java +++ b/native/src/test/java/net/md_5/bungee/NativeCipherTest.java @@ -1,5 +1,6 @@ package net.md_5.bungee; +import static org.junit.jupiter.api.Assertions.*; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.Random; @@ -9,12 +10,11 @@ import net.md_5.bungee.jni.NativeCode; import net.md_5.bungee.jni.cipher.BungeeCipher; import net.md_5.bungee.jni.cipher.JavaCipher; import net.md_5.bungee.jni.cipher.NativeCipher; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; -@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@TestMethodOrder(MethodOrderer.MethodName.class) public class NativeCipherTest { @@ -34,7 +34,7 @@ public class NativeCipherTest if ( NativeCode.isSupported() ) { boolean loaded = factory.load(); - Assert.assertTrue( "Native cipher failed to load!", loaded ); + assertTrue( loaded, "Native cipher failed to load!" ); NativeCipher cipher = new NativeCipher(); System.out.println( "Testing native cipher..." ); @@ -48,7 +48,7 @@ public class NativeCipherTest if ( NativeCode.isSupported() ) { boolean loaded = factory.load(); - Assert.assertTrue( "Native cipher failed to load!", loaded ); + assertTrue( loaded, "Native cipher failed to load!" ); NativeCipher cipher = new NativeCipher(); @@ -98,7 +98,7 @@ public class NativeCipherTest // Encrypt cipher.init( true, secret ); cipher.cipher( nativePlain, out ); - Assert.assertEquals( nativeCiphered, out ); + assertEquals( nativeCiphered, out ); out.clear(); @@ -106,7 +106,7 @@ public class NativeCipherTest cipher.init( false, secret ); cipher.cipher( nativeCiphered, out ); nativePlain.resetReaderIndex(); - Assert.assertEquals( nativePlain, out ); + assertEquals( nativePlain, out ); System.out.println( "This cipher works correctly!" ); } diff --git a/native/src/test/java/net/md_5/bungee/NativeZlibTest.java b/native/src/test/java/net/md_5/bungee/NativeZlibTest.java index 60b71a13..030fae28 100644 --- a/native/src/test/java/net/md_5/bungee/NativeZlibTest.java +++ b/native/src/test/java/net/md_5/bungee/NativeZlibTest.java @@ -1,5 +1,6 @@ package net.md_5.bungee; +import static org.junit.jupiter.api.Assertions.*; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.Arrays; @@ -9,8 +10,7 @@ import net.md_5.bungee.jni.NativeCode; import net.md_5.bungee.jni.zlib.BungeeZlib; import net.md_5.bungee.jni.zlib.JavaZlib; import net.md_5.bungee.jni.zlib.NativeZlib; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class NativeZlibTest { @@ -22,7 +22,7 @@ public class NativeZlibTest { if ( NativeCode.isSupported() ) { - Assert.assertTrue( "Native code failed to load!", factory.load() ); + assertTrue( factory.load(), "Native code failed to load!" ); test( factory.newInstance() ); } test( new JavaZlib() ); @@ -64,6 +64,6 @@ public class NativeZlibTest long elapsed = System.currentTimeMillis() - start; System.out.println( "Took: " + elapsed + "ms" ); - Assert.assertTrue( "Results do not match", Arrays.equals( dataBuf, check ) ); + assertTrue( Arrays.equals( dataBuf, check ), "Results do not match" ); } } diff --git a/pom.xml b/pom.xml index c69a1d60..86e47b19 100644 --- a/pom.xml +++ b/pom.xml @@ -91,9 +91,9 @@ - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter + 5.10.0 test diff --git a/protocol/src/test/java/net/md_5/bungee/protocol/packet/PluginMessageTest.java b/protocol/src/test/java/net/md_5/bungee/protocol/packet/PluginMessageTest.java index 00a897a2..5d52f300 100644 --- a/protocol/src/test/java/net/md_5/bungee/protocol/packet/PluginMessageTest.java +++ b/protocol/src/test/java/net/md_5/bungee/protocol/packet/PluginMessageTest.java @@ -1,7 +1,7 @@ package net.md_5.bungee.protocol.packet; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class PluginMessageTest { @@ -9,9 +9,9 @@ public class PluginMessageTest @Test public void testModerniseChannel() { - Assert.assertEquals( "bungeecord:main", PluginMessage.MODERNISE.apply( "BungeeCord" ) ); - Assert.assertEquals( "BungeeCord", PluginMessage.MODERNISE.apply( "bungeecord:main" ) ); - Assert.assertEquals( "legacy:foo", PluginMessage.MODERNISE.apply( "FoO" ) ); - Assert.assertEquals( "foo:bar", PluginMessage.MODERNISE.apply( "foo:bar" ) ); + assertEquals( "bungeecord:main", PluginMessage.MODERNISE.apply( "BungeeCord" ) ); + assertEquals( "BungeeCord", PluginMessage.MODERNISE.apply( "bungeecord:main" ) ); + assertEquals( "legacy:foo", PluginMessage.MODERNISE.apply( "FoO" ) ); + assertEquals( "foo:bar", PluginMessage.MODERNISE.apply( "foo:bar" ) ); } } diff --git a/proxy/src/test/java/net/md_5/bungee/ThrottleTest.java b/proxy/src/test/java/net/md_5/bungee/ThrottleTest.java index 84510827..b6fa72d9 100644 --- a/proxy/src/test/java/net/md_5/bungee/ThrottleTest.java +++ b/proxy/src/test/java/net/md_5/bungee/ThrottleTest.java @@ -1,12 +1,12 @@ package net.md_5.bungee; +import static org.junit.jupiter.api.Assertions.*; import com.google.common.base.Ticker; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; import java.util.concurrent.TimeUnit; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ThrottleTest { @@ -38,18 +38,18 @@ public class ThrottleTest address = new InetSocketAddress( InetAddress.getByName( null ), 0 ); } - Assert.assertFalse( "Address should not be throttled", throttle.throttle( address ) ); // 1 - Assert.assertFalse( "Address should not be throttled", throttle.throttle( address ) ); // 2 - Assert.assertFalse( "Address should not be throttled", throttle.throttle( address ) ); // 3 - Assert.assertTrue( "Address should be throttled", throttle.throttle( address ) ); // The 3rd one must be throttled, but also increased the count to 4 + assertFalse( throttle.throttle( address ), "Address should not be throttled" ); // 1 + assertFalse( throttle.throttle( address ), "Address should not be throttled" ); // 2 + assertFalse( throttle.throttle( address ), "Address should not be throttled" ); // 3 + assertTrue( throttle.throttle( address ), "Address should be throttled" ); // The 3rd one must be throttled, but also increased the count to 4 throttle.unthrottle( address ); // We are back at 3, next attempt will make it 4 and throttle throttle.unthrottle( address ); // Now we are at 2, will not be throttled - Assert.assertFalse( "Address should not be throttled", throttle.throttle( address ) ); // 3 - Assert.assertTrue( "Address should be throttled", throttle.throttle( address ) ); // 4 + assertFalse( throttle.throttle( address ), "Address should not be throttled" ); // 3 + assertTrue( throttle.throttle( address ), "Address should be throttled" ); // 4 // Now test expiration ticker.value += TimeUnit.MILLISECONDS.toNanos( 50 ); - Assert.assertFalse( "Address should not be throttled", throttle.throttle( address ) ); + assertFalse( throttle.throttle( address ), "Address should not be throttled" ); } } diff --git a/proxy/src/test/java/net/md_5/bungee/scheduler/SchedulerTest.java b/proxy/src/test/java/net/md_5/bungee/scheduler/SchedulerTest.java index 25ac3729..6a7fb808 100644 --- a/proxy/src/test/java/net/md_5/bungee/scheduler/SchedulerTest.java +++ b/proxy/src/test/java/net/md_5/bungee/scheduler/SchedulerTest.java @@ -1,13 +1,13 @@ package net.md_5.bungee.scheduler; +import static org.junit.jupiter.api.Assertions.*; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import net.md_5.bungee.api.plugin.DummyPlugin; import net.md_5.bungee.api.scheduler.ScheduledTask; import net.md_5.bungee.api.scheduler.TaskScheduler; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SchedulerTest { @@ -31,7 +31,7 @@ public class SchedulerTest latch.await( 5, TimeUnit.SECONDS ); - Assert.assertEquals( 0, latch.getCount() ); + assertEquals( 0, latch.getCount() ); } @Test @@ -43,17 +43,17 @@ public class SchedulerTest ScheduledTask task = setup( scheduler, b ); scheduler.cancel( task.getId() ); Thread.sleep( 250 ); - Assert.assertFalse( b.get() ); + assertFalse( b.get() ); task = setup( scheduler, b ); scheduler.cancel( task ); Thread.sleep( 250 ); - Assert.assertFalse( b.get() ); + assertFalse( b.get() ); task = setup( scheduler, b ); scheduler.cancel( task.getOwner() ); Thread.sleep( 250 ); - Assert.assertFalse( b.get() ); + assertFalse( b.get() ); } @Test @@ -64,11 +64,11 @@ public class SchedulerTest setup( scheduler, b ); Thread.sleep( 250 ); - Assert.assertTrue( b.get() ); + assertTrue( b.get() ); b.set( false ); Thread.sleep( 250 ); - Assert.assertTrue( b.get() ); + assertTrue( b.get() ); } private ScheduledTask setup(TaskScheduler scheduler, final AtomicBoolean hasRun) diff --git a/proxy/src/test/java/net/md_5/bungee/util/AddressUtilTest.java b/proxy/src/test/java/net/md_5/bungee/util/AddressUtilTest.java index e2a3a481..edabc2b5 100644 --- a/proxy/src/test/java/net/md_5/bungee/util/AddressUtilTest.java +++ b/proxy/src/test/java/net/md_5/bungee/util/AddressUtilTest.java @@ -1,8 +1,8 @@ package net.md_5.bungee.util; +import static org.junit.jupiter.api.Assertions.*; import java.net.InetSocketAddress; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AddressUtilTest { @@ -11,9 +11,9 @@ public class AddressUtilTest public void testScope() { InetSocketAddress addr = new InetSocketAddress( "0:0:0:0:0:0:0:1%0", 25577 ); - Assert.assertEquals( "0:0:0:0:0:0:0:1", AddressUtil.sanitizeAddress( addr ) ); + assertEquals( "0:0:0:0:0:0:0:1", AddressUtil.sanitizeAddress( addr ) ); InetSocketAddress addr2 = new InetSocketAddress( "0:0:0:0:0:0:0:1", 25577 ); - Assert.assertEquals( "0:0:0:0:0:0:0:1", AddressUtil.sanitizeAddress( addr2 ) ); + assertEquals( "0:0:0:0:0:0:0:1", AddressUtil.sanitizeAddress( addr2 ) ); } }