1 20 package org.apache.mina.integration.spring; 21 22 import java.net.InetSocketAddress ; 23 24 import junit.framework.TestCase; 25 26 32 public class InetSocketAddressEditorTest extends TestCase { 33 InetSocketAddressEditor editor; 34 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(null); 61 fail("null string. IllegalArgumentException expected."); 62 } catch (IllegalArgumentException iae) { 63 } 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 81 } 82 | Popular Tags |