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
32 public class InetSocketAddressEditorTest extends TestCase {
33 InetSocketAddressEditor editor;
34
35 @Override
36 protected void setUp() throws Exception {
37 editor = new InetSocketAddressEditor();
38 }
39
40 public void testSetAsTextWithWildcardAddress() throws Exception {
41 editor.setAsText("1");
42 assertEquals(new InetSocketAddress(1), editor.getValue());
43 editor.setAsText(":10");
44 assertEquals(new InetSocketAddress(10), editor.getValue());
45 }
46
47 public void testSetAsTextWithHostName() throws Exception {
48 editor.setAsText("www.google.com:80");
49 assertEquals(new InetSocketAddress("www.google.com", 80), editor
50 .getValue());
51 }
52
53 public void testSetAsTextWithIpAddress() throws Exception {
54 editor.setAsText("192.168.0.1:1000");
55 assertEquals(new InetSocketAddress("192.168.0.1", 1000), editor
56 .getValue());
57 }
58
59 public void testSetAsTextWithIllegalValues() throws Exception {
60 try {
61 editor.setAsText("bar");
62 fail("Illegal port number. IllegalArgumentException expected.");
63 } catch (IllegalArgumentException iae) {
64 }
65 try {
66 editor.setAsText(":foo");
67 fail("Illegal port number. IllegalArgumentException expected.");
68 } catch (IllegalArgumentException iae) {
69 }
70 try {
71 editor.setAsText("www.foo.com:yada");
72 fail("Illegal port number. IllegalArgumentException expected.");
73 } catch (IllegalArgumentException iae) {
74 }
75 }
76
77 }