01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.net.util;
05:
06: import com.tc.test.TCTestCase;
07: import com.tc.util.Assert;
08:
09: 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[] {
18: new InetSocketAddress("localhost", 0),
19: new InetSocketAddress("www.terracottatech.com", 80),
20: new InetSocketAddress("15.0.0.1", 5) };
21: list = new InetSocketAddressList(addresses);
22: super .setUp();
23: }
24:
25: public final void testConstructor() throws Exception {
26: new InetSocketAddressList(new InetSocketAddress[0]);
27: new InetSocketAddressList(addresses);
28: try {
29: new InetSocketAddressList(null);
30: } catch (NullPointerException npe) {
31: // Expected
32: }
33: try {
34: new InetSocketAddressList(
35: new InetSocketAddress[] {
36: new InetSocketAddress("localhost", 0),
37: null,
38: new InetSocketAddress(
39: "www.terracottatech.com", 80) });
40: } catch (NullPointerException npe) {
41: // Expected
42: }
43: }
44:
45: public final void testToString() throws Exception {
46: String toString = list.toString();
47: assertTrue(toString
48: .matches("^(?:[^:]+:\\p{Digit}+)(?:,[^:]+:\\p{Digit}+){2}$"));
49: }
50:
51: public final void testParseAddresses() throws Exception {
52: InetSocketAddress[] fromStringAddresses = InetSocketAddressList
53: .parseAddresses(list.toString());
54: assertEquals(addresses.length, fromStringAddresses.length);
55: for (int pos = 0; pos < fromStringAddresses.length; pos++) {
56: Assert.assertEquals(addresses[pos],
57: fromStringAddresses[pos]);
58: }
59: }
60:
61: }
|