AddressTest.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
00015  */
00016 
00017 package org.ros.address;
00018 
00019 import static org.junit.Assert.assertEquals;
00020 import static org.junit.Assert.assertFalse;
00021 import static org.junit.Assert.assertTrue;
00022 
00023 import org.junit.Test;
00024 
00025 import java.net.InetAddress;
00026 import java.net.UnknownHostException;
00027 
00031 public class AddressTest {
00032 
00033   @Test
00034   public void testLocalhost() {
00035     InetAddress localhost = InetAddressFactory.newFromHostString(Address.LOCALHOST);
00036     assertEquals(Address.LOCALHOST, localhost.getHostName());
00037     assertTrue(localhost.isLoopbackAddress());
00038   }
00039 
00040   @Test
00041   public void testLoopback() {
00042     InetAddress loopback = InetAddressFactory.newFromHostString(Address.LOOPBACK);
00043     assertEquals(Address.LOOPBACK, loopback.getHostName());
00044     assertTrue(loopback.isLoopbackAddress());
00045   }
00046 
00047   // TODO(damonkohler): This test fails if the host isn't registered with DNS.
00048   // These tests need to be changed to inject behavior into the
00049   // getAllInetAddressesByName() method.
00050   public void testPublicHost() throws UnknownHostException {
00051     String host = InetAddress.getLocalHost().getCanonicalHostName();
00052     InetAddress publicHost = InetAddressFactory.newFromHostString(host);
00053     assertEquals(host, publicHost.getHostName());
00054     assertFalse(publicHost.isLoopbackAddress());
00055   }
00056 
00057   @Test
00058   public void testPublicIpv4() {
00059     String host = "1.2.3.4";
00060     InetAddress publicHost = InetAddressFactory.newFromHostString(host);
00061     assertEquals(host, publicHost.getHostName());
00062     assertFalse(publicHost.isLoopbackAddress());
00063   }
00064 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49