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.getValue());
55 }
56
57 public void testSetAsTextWithIpAddress() throws Exception {
58 editor.setAsText("192.168.0.1:1000");
59 assertEquals(new InetSocketAddress("192.168.0.1", 1000), editor.getValue());
60 }
61
62 @Test
63 public void testSetAsTextWithIllegalValues() throws Exception {
64 try {
65 editor.setAsText("bar");
66 fail("Illegal port number. IllegalArgumentException expected.");
67 } catch (IllegalArgumentException iae) {
68 }
69 try {
70 editor.setAsText(":foo");
71 fail("Illegal port number. IllegalArgumentException expected.");
72 } catch (IllegalArgumentException iae) {
73 }
74 try {
75 editor.setAsText("www.foo.com:yada");
76 fail("Illegal port number. IllegalArgumentException expected.");
77 } catch (IllegalArgumentException iae) {
78 }
79 }
80 }