Created
January 2, 2016 17:06
-
-
Save alexlehm/0fb30c57f39b7c0eaa98 to your computer and use it in GitHub Desktop.
GetHostnameIsAsync.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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