| 1 7 8 package org.sapia.ubik.util; 9 10 import java.util.regex.Pattern ; 11 import junit.framework.TestCase; 12 import org.sapia.ubik.rmi.Consts; 13 14 18 public class LocalhostTest extends TestCase { 19 20 public LocalhostTest(String testName) { 21 super(testName); 22 } 23 24 27 public void testGetLocalAddress() throws Exception { 28 String addr = Localhost.getLocalAddress().getHostAddress(); 29 super.assertTrue(!addr.equals("localhost")); 30 super.assertTrue(!addr.equals("127.0.0.1")); 31 super.assertTrue(!addr.equals("0.0.0.0")); 32 } 33 34 public void testIsLocalAddress(){ 35 Pattern p = Pattern.compile("\\d{3}\\.\\d{3}\\.\\d+\\.\\d+"); 36 super.assertTrue(!Localhost.isLocalAddress(p, "127.0.0.1")); 37 super.assertTrue(!Localhost.isLocalAddress(p, "10.10.10.1")); 38 super.assertTrue(!Localhost.isLocalAddress(p, "localhost")); 39 super.assertTrue(Localhost.isLocalAddress(p, "192.168.0.10")); 40 } 41 42 43 } 44 | Popular Tags |