KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > net > util > InetSocketAddressListTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc;
10
11 public final class InetSocketAddressListTest extends TCTestCase {
12
13   private InetSocketAddress JavaDoc[] addresses;
14   private InetSocketAddressList list;
15
16   protected void setUp() throws Exception JavaDoc {
17     addresses = new InetSocketAddress JavaDoc[] { new InetSocketAddress JavaDoc("localhost", 0),
18         new InetSocketAddress JavaDoc("www.terracottatech.com", 80), new InetSocketAddress JavaDoc("15.0.0.1", 5) };
19     list = new InetSocketAddressList(addresses);
20     super.setUp();
21   }
22
23   public final void testConstructor() throws Exception JavaDoc {
24     new InetSocketAddressList(new InetSocketAddress JavaDoc[0]);
25     new InetSocketAddressList(addresses);
26     try {
27       new InetSocketAddressList(null);
28     } catch (NullPointerException JavaDoc npe) {
29       // Expected
30
}
31     try {
32       new InetSocketAddressList(new InetSocketAddress JavaDoc[] { new InetSocketAddress JavaDoc("localhost", 0), null,
33           new InetSocketAddress JavaDoc("www.terracottatech.com", 80) });
34     } catch (NullPointerException JavaDoc npe) {
35       // Expected
36
}
37   }
38
39   public final void testToString() throws Exception JavaDoc {
40     String JavaDoc toString = list.toString();
41     assertTrue(toString.matches("^(?:[^:]+:\\p{Digit}+)(?:,[^:]+:\\p{Digit}+){2}$"));
42   }
43
44   public final void testParseAddresses() throws Exception JavaDoc {
45     InetSocketAddress JavaDoc[] 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