Skip to content

Commit 0430962

Browse files
author
Thomas Darimont
committed
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.
1 parent 8bb62a6 commit 0430962

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/config/ServerAddressPropertyEditorUnitTests.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@
1515
*/
1616
package org.springframework.data.mongodb.config;
1717

18-
import static org.hamcrest.Matchers.*;
19-
import static org.junit.Assert.*;
18+
import static org.hamcrest.Matchers.hasItem;
19+
import static org.hamcrest.Matchers.hasSize;
20+
import static org.hamcrest.Matchers.instanceOf;
21+
import static org.hamcrest.Matchers.is;
22+
import static org.junit.Assert.assertNull;
23+
import static org.junit.Assert.assertThat;
2024

2125
import java.net.InetAddress;
2226
import java.net.UnknownHostException;
2327
import java.util.Arrays;
2428
import java.util.Collection;
2529

30+
import org.junit.Assert;
2631
import org.junit.Before;
2732
import org.junit.Rule;
2833
import org.junit.Test;
@@ -49,11 +54,17 @@ public void setUp() {
4954

5055
/**
5156
* @see DATAMONGO-454
57+
* @see DATAMONGO-1062
5258
*/
5359
@Test(expected = IllegalArgumentException.class)
54-
public void rejectsAddressConfigWithoutASingleParsableServerAddress() {
60+
public void rejectsAddressConfigWithoutASingleParsableAndResolvableServerAddress() {
5561

56-
editor.setAsText("foo, bar");
62+
String unknownHost1 = "gugu.nonexistant.example.org";
63+
String unknownHost2 = "gaga.nonexistant.example.org";
64+
65+
assertUnresolveableHostnames(unknownHost1, unknownHost2);
66+
67+
editor.setAsText(unknownHost1 + "," + unknownHost2);
5768
}
5869

5970
/**
@@ -193,4 +204,16 @@ private static void assertSingleAddressWithPort(String hostAddress, Integer port
193204
assertThat(addresses, hasItem(new ServerAddress(InetAddress.getByName(hostAddress), port)));
194205
}
195206
}
207+
208+
private void assertUnresolveableHostnames(String... hostnames) {
209+
210+
for (String hostname : hostnames) {
211+
try {
212+
InetAddress.getByName(hostname);
213+
Assert.fail("Supposedly unresolveable hostname '" + hostname + "' can be resolved.");
214+
} catch (UnknownHostException expected) {
215+
// ok
216+
}
217+
}
218+
}
196219
}

0 commit comments

Comments
 (0)