Skip to content

Commit

Permalink
Move AddressUtilsTest to JUnit4 (#1249)
Browse files Browse the repository at this point in the history
Signed-off-by: Thiébaud Weksteen <[email protected]>
  • Loading branch information
tweksteen authored Oct 28, 2024
1 parent d286b36 commit 6e1d23a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions openjdk/src/test/java/org/conscrypt/AddressUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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"));
Expand All @@ -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"));
Expand All @@ -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"));
Expand Down

0 comments on commit 6e1d23a

Please sign in to comment.