diff --git a/openjdk/src/test/java/org/conscrypt/AddressUtilsTest.java b/openjdk/src/test/java/org/conscrypt/AddressUtilsTest.java index b210c0aee..59aba1521 100644 --- a/openjdk/src/test/java/org/conscrypt/AddressUtilsTest.java +++ b/openjdk/src/test/java/org/conscrypt/AddressUtilsTest.java @@ -16,40 +16,54 @@ package org.conscrypt; -import junit.framework.TestCase; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; /** * Test for AddressUtils */ -public class AddressUtilsTest extends TestCase { +@RunWith(JUnit4.class) +public class AddressUtilsTest { + @Test public void test_isValidSniHostname_Success() throws Exception { assertTrue(AddressUtils.isValidSniHostname("www.google.com")); } + @Test public void test_isValidSniHostname_NotFQDN_Failure() throws Exception { assertFalse(AddressUtils.isValidSniHostname("www")); } + @Test public void test_isValidSniHostname_Localhost_Success() throws Exception { assertTrue(AddressUtils.isValidSniHostname("LOCALhost")); } + @Test public void test_isValidSniHostname_IPv4_Failure() throws Exception { assertFalse(AddressUtils.isValidSniHostname("192.168.0.1")); } + @Test public void test_isValidSniHostname_IPv6_Failure() throws Exception { assertFalse(AddressUtils.isValidSniHostname("2001:db8::1")); } + @Test public void test_isValidSniHostname_TrailingDot() throws Exception { assertFalse(AddressUtils.isValidSniHostname("www.google.com.")); } + @Test public void test_isValidSniHostname_NullByte() throws Exception { assertFalse(AddressUtils.isValidSniHostname("www\0.google.com")); } + @Test public void test_isLiteralIpAddress_IPv4_Success() throws Exception { assertTrue(AddressUtils.isLiteralIpAddress("127.0.0.1")); assertTrue(AddressUtils.isLiteralIpAddress("255.255.255.255")); @@ -58,6 +72,7 @@ public void test_isLiteralIpAddress_IPv4_Success() throws Exception { assertTrue(AddressUtils.isLiteralIpAddress("254.249.190.094")); } + @Test public void test_isLiteralIpAddress_IPv4_ExtraCharacters_Failure() throws Exception { assertFalse(AddressUtils.isLiteralIpAddress("127.0.0.1a")); assertFalse(AddressUtils.isLiteralIpAddress(" 255.255.255.255")); @@ -68,12 +83,14 @@ public void test_isLiteralIpAddress_IPv4_ExtraCharacters_Failure() throws Except assertFalse(AddressUtils.isLiteralIpAddress("192.168.2.1%eth0")); } + @Test public void test_isLiteralIpAddress_IPv4_NumbersTooLarge_Failure() throws Exception { assertFalse(AddressUtils.isLiteralIpAddress("256.255.255.255")); assertFalse(AddressUtils.isLiteralIpAddress("255.255.255.256")); assertFalse(AddressUtils.isLiteralIpAddress("192.168.1.260")); } + @Test public void test_isLiteralIpAddress_IPv6_Success() throws Exception { assertTrue(AddressUtils.isLiteralIpAddress("::1")); assertTrue(AddressUtils.isLiteralIpAddress("2001:Db8::1")); @@ -85,6 +102,7 @@ public void test_isLiteralIpAddress_IPv6_Success() throws Exception { assertTrue(AddressUtils.isLiteralIpAddress("2001:cdba::3257:9652%int2.3!")); } + @Test public void test_isLiteralIpAddress_IPv6_Failure() throws Exception { assertFalse(AddressUtils.isLiteralIpAddress(":::1")); assertFalse(AddressUtils.isLiteralIpAddress("::11111")); diff --git a/openjdk/src/test/java/org/conscrypt/NativeRefTest.java b/openjdk/src/test/java/org/conscrypt/NativeRefTest.java index e13297b35..7b71dcdbf 100644 --- a/openjdk/src/test/java/org/conscrypt/NativeRefTest.java +++ b/openjdk/src/test/java/org/conscrypt/NativeRefTest.java @@ -16,9 +16,15 @@ package org.conscrypt; -import junit.framework.TestCase; +import static org.junit.Assert.fail; -public class NativeRefTest extends TestCase { +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class NativeRefTest { + @Test public void test_zeroContextThrowsNullPointException() { try { new NativeRef(0) { diff --git a/openjdk/src/test/java/org/conscrypt/OpenSSLKeyTest.java b/openjdk/src/test/java/org/conscrypt/OpenSSLKeyTest.java index 4d9db076b..0935c4994 100644 --- a/openjdk/src/test/java/org/conscrypt/OpenSSLKeyTest.java +++ b/openjdk/src/test/java/org/conscrypt/OpenSSLKeyTest.java @@ -16,13 +16,18 @@ package org.conscrypt; +import static org.junit.Assert.assertEquals; + import java.io.ByteArrayInputStream; import java.math.BigInteger; import java.nio.charset.StandardCharsets; -import junit.framework.TestCase; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; -public class OpenSSLKeyTest extends TestCase { +@RunWith(JUnit4.class) +public class OpenSSLKeyTest { static final String RSA_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\n" + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3G7PGpfZx68wTY9eLb4b\n" + @@ -84,6 +89,7 @@ public class OpenSSLKeyTest extends TestCase { "13e6825df950a3bd4509f9d3b12da304fe5b00c443ff33326b8bfb3fe111fd4b" + "8872822c7f2832dafa0fe10d9aba22310849e978e51c8aa9da7bc1c07511d883", 16); + @Test public void test_fromPublicKeyPemInputStream() throws Exception { ByteArrayInputStream is = new ByteArrayInputStream(RSA_PUBLIC_KEY.getBytes(StandardCharsets.UTF_8)); OpenSSLKey key = OpenSSLKey.fromPublicKeyPemInputStream(is); @@ -92,6 +98,7 @@ public void test_fromPublicKeyPemInputStream() throws Exception { assertEquals(RSA_PUBLIC_EXPONENT, publicKey.getPublicExponent()); } + @Test public void test_fromPrivateKeyPemInputStream() throws Exception { ByteArrayInputStream is = new ByteArrayInputStream(RSA_PRIVATE_KEY.getBytes(StandardCharsets.UTF_8)); OpenSSLKey key = OpenSSLKey.fromPrivateKeyPemInputStream(is);