1 4 package com.tc.net.util; 5 6 import com.tc.test.TCTestCase; 7 import com.tc.util.Assert; 8 9 import java.net.InetSocketAddress ; 10 11 public final class InetSocketAddressListTest extends TCTestCase { 12 13 private InetSocketAddress [] addresses; 14 private InetSocketAddressList list; 15 16 protected void setUp() throws Exception { 17 addresses = new InetSocketAddress [] { new InetSocketAddress ("localhost", 0), 18 new InetSocketAddress ("www.terracottatech.com", 80), new InetSocketAddress ("15.0.0.1", 5) }; 19 list = new InetSocketAddressList(addresses); 20 super.setUp(); 21 } 22 23 public final void testConstructor() throws Exception { 24 new InetSocketAddressList(new InetSocketAddress [0]); 25 new InetSocketAddressList(addresses); 26 try { 27 new InetSocketAddressList(null); 28 } catch (NullPointerException npe) { 29 } 31 try { 32 new InetSocketAddressList(new InetSocketAddress [] { new InetSocketAddress ("localhost", 0), null, 33 new InetSocketAddress ("www.terracottatech.com", 80) }); 34 } catch (NullPointerException npe) { 35 } 37 } 38 39 public final void testToString() throws Exception { 40 String toString = list.toString(); 41 assertTrue(toString.matches("^(?:[^:]+:\\p{Digit}+)(?:,[^:]+:\\p{Digit}+){2}$")); 42 } 43 44 public final void testParseAddresses() throws Exception { 45 InetSocketAddress [] fromStringAddresses = InetSocketAddressList.parseAddresses(list.toString()); 46 assertEquals(addresses.length, fromStringAddresses.length); 47 for (int pos = 0; pos < fromStringAddresses.length; pos++) { 48 Assert.assertEquals(addresses[pos], fromStringAddresses[pos]); 49 } 50 } 51 52 } 53 | Popular Tags |