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 static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.fail;
24
25 import java.net.InetSocketAddress;
26
27 import org.junit.Before;
28 import org.junit.Test;
29
30
31
32
33
34
35 public class InetSocketAddressEditorTest {
36 InetSocketAddressEditor editor;
37
38 @Before
39 public void setUp() throws Exception {
40 editor = new InetSocketAddressEditor();
41 }
42
43 @Test
44 public void testSetAsTextWithWildcardAddress() throws Exception {
45 editor.setAsText("1");
46 assertEquals(new InetSocketAddress(1), editor.getValue());
47 editor.setAsText(":10");
48 assertEquals(new InetSocketAddress(10), editor.getValue());
49 }
50
51 @Test
52 public void testSetAsTextWithHostName() throws Exception {
53 editor.setAsText("www.google.com:80");
54 assertEquals(new InetSocketAddress("www.google.com", 80), editor
55 .getValue());
56 }
57
58 public void testSetAsTextWithIpAddress() throws Exception {
59 editor.setAsText("192.168.0.1:1000");
60 assertEquals(new InetSocketAddress("192.168.0.1", 1000), editor
61 .getValue());
62 }
63
64 @Test
65 public void testSetAsTextWithIllegalValues() throws Exception {
66 try {
67 editor.setAsText("bar");
68 fail("Illegal port number. IllegalArgumentException expected.");
69 } catch (IllegalArgumentException iae) {
70 }
71 try {
72 editor.setAsText(":foo");
73 fail("Illegal port number. IllegalArgumentException expected.");
74 } catch (IllegalArgumentException iae) {
75 }
76 try {
77 editor.setAsText("www.foo.com:yada");
78 fail("Illegal port number. IllegalArgumentException expected.");
79 } catch (IllegalArgumentException iae) {
80 }
81 }
82 }