package tachyon.util;

import java.net.UnknownHostException;

import org.junit.Assert;
import org.junit.Test;

public class NetworkUtilsTest {

  @Test
  public void replaceHostNameTest() throws UnknownHostException {
    Assert.assertEquals(NetworkUtils.replaceHostName(""), null);
    Assert.assertEquals(NetworkUtils.replaceHostName(null), null);

    String[] paths =
        new String[] { "hdfs://localhost:9000/dir", "hdfs://localhost/dir", "hdfs://localhost/",
            "hdfs://localhost", "file:///dir", "/dir", "anythingElse" };

    for (String path : paths) {
      Assert.assertEquals(NetworkUtils.replaceHostName(path), path);
    }
  }

  @Test
  public void resolveHostNameTest() throws UnknownHostException {
    Assert.assertEquals(NetworkUtils.resolveHostName(""), null);
    Assert.assertEquals(NetworkUtils.resolveHostName(null), null);
    Assert.assertEquals(NetworkUtils.resolveHostName("localhost"), "localhost");
  }
}

@@ -16,16 +16,51 @@
 .util;%0A%0A
+import java.net.InetSocketAddress;%0A
 import j
@@ -139,16 +139,51 @@
 .Test;%0A%0A
+import tachyon.thrift.NetAddress;%0A%0A
 public c
@@ -1008,11 +1008,296 @@
 t%22);%0A  %7D
+%0A%0A  @Test%0A  public void getFqdnHostTest() throws UnknownHostException %7B%0A    Assert.assertEquals(NetworkUtils.getFqdnHost(new InetSocketAddress(%22localhost%22, 0)),%0A        %22localhost%22);%0A    Assert.assertEquals(NetworkUtils.getFqdnHost(new NetAddress(%22localhost%22, 0, 0)), %22localhost%22);%0A  %7D
 %0A%7D%0A

add unit test to NetworkUtils