From 388b882debd2192db66695d1f94f09b4d5ad0921 Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Tue, 30 Sep 2014 12:18:36 +0200 Subject: [PATCH] DATAMONGO-1062 - Fix failing test in ServerAddressPropertyEditorUnitTests. The test rejectsAddressConfigWithoutASingleParsableServerAddress fails because the supposedly non-existing hostname "bar" "now" resolves to a real host-address. The addresses "gugu.nonexistant.example.org, gaga.nonexistant.example.org" shouldn't be resolvable TM. Original pull request: #229. --- .../ServerAddressPropertyEditorUnitTests.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/config/ServerAddressPropertyEditorUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/config/ServerAddressPropertyEditorUnitTests.java index 2d7607ed67..b9804cfef2 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/config/ServerAddressPropertyEditorUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/config/ServerAddressPropertyEditorUnitTests.java @@ -15,14 +15,19 @@ */ package org.springframework.data.mongodb.config; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; import java.util.Collection; +import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -49,11 +54,17 @@ public void setUp() { /** * @see DATAMONGO-454 + * @see DATAMONGO-1062 */ @Test(expected = IllegalArgumentException.class) public void rejectsAddressConfigWithoutASingleParsableServerAddress() { - editor.setAsText("foo, bar"); + String unknownHost1 = "gugu.nonexistant.example.org"; + String unknownHost2 = "gaga.nonexistant.example.org"; + + assertUnresolveableHostnames(unknownHost1, unknownHost2); + + editor.setAsText(unknownHost1 + "," + unknownHost2); } /** @@ -193,4 +204,16 @@ private static void assertSingleAddressWithPort(String hostAddress, Integer port assertThat(addresses, hasItem(new ServerAddress(InetAddress.getByName(hostAddress), port))); } } + + private void assertUnresolveableHostnames(String... hostnames) { + + for (String hostname : hostnames) { + try { + InetAddress.getByName(hostname); + Assert.fail("Supposedly unresolveable hostname '" + hostname + "' can be resolved."); + } catch (UnknownHostException expected) { + // ok + } + } + } }