Update tests to JUnit 5
This commit is contained in:
@@ -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() );
|
||||
}
|
||||
}
|
||||
|
@@ -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<Object[]> data()
|
||||
public static Stream<Arguments> 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 );
|
||||
|
@@ -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<Object> 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
|
||||
}
|
||||
}
|
||||
|
@@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user