diff options
author | Adam Tanner <adamtanner@google.com> | 2015-07-20 14:01:45 -0700 |
---|---|---|
committer | Adam Tanner <adamtanner@google.com> | 2015-07-20 14:03:52 -0700 |
commit | 457541611c0f95979ab6b9227fc688730439f2d6 (patch) | |
tree | 5bb48519333375058c41977037ae4108e4bc46e2 | |
parent | 8e570ee3a2b5dc637c0fd270e09f67e72de35f83 (diff) | |
download | android_external_gson-457541611c0f95979ab6b9227fc688730439f2d6.tar.gz android_external_gson-457541611c0f95979ab6b9227fc688730439f2d6.tar.bz2 android_external_gson-457541611c0f95979ab6b9227fc688730439f2d6.zip |
Replace localhost lookup with static IP to fix test.
Calling InetAddress.getLocalHost() will cause a lookup to occur that may
fail with a java.net.UnknownHostException if the system the test is
running on is not configured correctly.
This is often fixed by echoing "127.0.0.1 $HOSTNAME" to /etc/hosts, but
in this case it seems easier to pick a static IP string to avoid the
lookup entirely and prevent false negatives in the test.
-rw-r--r-- | gson/src/test/java/com/google/gson/DefaultInetAddressTypeAdapterTest.java | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/gson/src/test/java/com/google/gson/DefaultInetAddressTypeAdapterTest.java b/gson/src/test/java/com/google/gson/DefaultInetAddressTypeAdapterTest.java index 7c67d975..6b853f5d 100644 --- a/gson/src/test/java/com/google/gson/DefaultInetAddressTypeAdapterTest.java +++ b/gson/src/test/java/com/google/gson/DefaultInetAddressTypeAdapterTest.java @@ -35,11 +35,11 @@ public class DefaultInetAddressTypeAdapterTest extends TestCase { } public void testInetAddressSerializationAndDeserialization() throws Exception { - InetAddress localhost = InetAddress.getLocalHost(); - String localInetAddress = gson.toJson(localhost); - assertEquals("\"" + localhost.getHostAddress() + "\"", localInetAddress); + InetAddress address = InetAddress.getByName("8.8.8.8"); + String jsonAddress = gson.toJson(address); + assertEquals("\"8.8.8.8\"", jsonAddress); - InetAddress value = gson.fromJson(localInetAddress, InetAddress.class); - assertEquals(localhost, value); + InetAddress value = gson.fromJson(jsonAddress, InetAddress.class); + assertEquals(value, address); } } |