Skip to content

Instantly share code, notes, and snippets.

@alexlehm
Created January 2, 2016 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexlehm/0fb30c57f39b7c0eaa98 to your computer and use it in GitHub Desktop.
Save alexlehm/0fb30c57f39b7c0eaa98 to your computer and use it in GitHub Desktop.
GetHostnameIsAsync.java
package io.vertx.ext.mail.impl;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.powermock.api.easymock.PowerMock.*;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.junit.Assert.*;
import static org.easymock.EasyMock.*;
/**
* @author <a href="http://oss.lehmann.cx/">Alexander Lehmann</a>
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({GetHostnameIsAsync.class})
public class GetHostnameIsAsync {
private static final Logger log = LoggerFactory.getLogger(GetHostnameIsAsync.class);
@Test
public void test() throws UnknownHostException {
mockStatic(InetAddress.class);
final InetAddress mockAddr = mock(InetAddress.class);
expect(mockAddr.getCanonicalHostName()).andReturn("hostname");
expect(InetAddress.getLocalHost()).andReturn(mockAddr);
replayAll();
InetAddress ip = InetAddress.getLocalHost();
log.info("InetAddress:"+ip);
String hostname = ip.getCanonicalHostName();
verifyAll();
assertEquals("hostname", hostname);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment