Commit 1d35b629 authored by Phillip Webb's avatar Phillip Webb

Merge branch '2.0.x'

parents bd8106d7 abe92eba
......@@ -52,7 +52,7 @@ public class InetAddressFormatterTests {
@Test
public void convertFromInetAddressToStringShouldConvert()
throws UnknownHostException {
assumeResolves("example.com");
assumeResolves("example.com", true);
InetAddress address = InetAddress.getByName("example.com");
String converted = this.conversionService.convert(address, String.class);
assertThat(converted).isEqualTo(address.getHostAddress());
......@@ -60,7 +60,7 @@ public class InetAddressFormatterTests {
@Test
public void convertFromStringToInetAddressShouldConvert() {
assumeResolves("example.com");
assumeResolves("example.com", true);
InetAddress converted = this.conversionService.convert("example.com",
InetAddress.class);
assertThat(converted.toString()).startsWith("example.com");
......@@ -68,16 +68,27 @@ public class InetAddressFormatterTests {
@Test
public void convertFromStringToInetAddressWhenHostDoesNotExistShouldThrowException() {
String missingDomain = "ireallydontexist.example.com";
assumeResolves(missingDomain, false);
this.thrown.expect(ConversionFailedException.class);
this.conversionService.convert("ireallydontexist.example.com", InetAddress.class);
this.conversionService.convert(missingDomain, InetAddress.class);
}
private void assumeResolves(String host) {
private void assumeResolves(String host, boolean expectedToResolve) {
boolean resolved = isResolvable(host);
if (resolved != expectedToResolve) {
throw new AssumptionViolatedException(
"Host " + host + " resolved " + resolved);
}
}
private boolean isResolvable(String host) {
try {
InetAddress.getByName(host);
return true;
}
catch (UnknownHostException ex) {
throw new AssumptionViolatedException("Host " + host + " not resolvable", ex);
return false;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment