1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.integration.beans;
21
22 import java.net.InetSocketAddress;
23
24 import junit.framework.TestCase;
25
26
27
28
29
30
31 public class InetSocketAddressEditorTest extends TestCase {
32 InetSocketAddressEditor editor;
33
34 @Override
35 protected void setUp() throws Exception {
36 editor = new InetSocketAddressEditor();
37 }
38
39 public void testSetAsTextWithWildcardAddress() throws Exception {
40 editor.setAsText("1");
41 assertEquals(new InetSocketAddress(1), editor.getValue());
42 editor.setAsText(":10");
43 assertEquals(new InetSocketAddress(10), editor.getValue());
44 }
45
46 public void testSetAsTextWithHostName() throws Exception {
47 editor.setAsText("www.google.com:80");
48 assertEquals(new InetSocketAddress("www.google.com", 80), editor
49 .getValue());
50 }
51
52 public void testSetAsTextWithIpAddress() throws Exception {
53 editor.setAsText("192.168.0.1:1000");
54 assertEquals(new InetSocketAddress("192.168.0.1", 1000), editor
55 .getValue());
56 }
57
58 public void testSetAsTextWithIllegalValues() throws Exception {
59 try {
60 editor.setAsText("bar");
61 fail("Illegal port number. IllegalArgumentException expected.");
62 } catch (IllegalArgumentException iae) {
63 }
64 try {
65 editor.setAsText(":foo");
66 fail("Illegal port number. IllegalArgumentException expected.");
67 } catch (IllegalArgumentException iae) {
68 }
69 try {
70 editor.setAsText("www.foo.com:yada");
71 fail("Illegal port number. IllegalArgumentException expected.");
72 } catch (IllegalArgumentException iae) {
73 }
74 }
75
76 }