From d2e35e239a5dbfbe27e9b52f826b4bad733ccd24 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 9 Mar 2017 06:51:57 -0700 Subject: [PATCH] Windows Test Issue + Changing from @Test(expect=) to @Rule ExpectedException for ... * no exception occuring when one is expected is a test failure * wrong exception is a test failure * wrong cause is a test failure --- .../jetty/client/HttpClientURITest.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientURITest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientURITest.java index 4f175384f1b..00d6feb8a85 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientURITest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientURITest.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.client; +import static org.hamcrest.CoreMatchers.instanceOf; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -47,10 +49,15 @@ import org.eclipse.jetty.util.Fields; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; public class HttpClientURITest extends AbstractHttpClientServerTest { + @Rule + public ExpectedException expectedException = ExpectedException.none(); + public HttpClientURITest(SslContextFactory sslContextFactory) { super(sslContextFactory); @@ -74,14 +81,15 @@ public class HttpClientURITest extends AbstractHttpClientServerTest Assert.assertEquals(HttpStatus.OK_200, request.send().getStatus()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIDNHost() throws Exception { startClient(); + expectedException.expect(IllegalArgumentException.class); client.newRequest(scheme + "://пример.рф"); // example.com-like host in IDN domain } - @Test(expected = IllegalArgumentException.class) + @Test public void testIDNRedirect() throws Exception { // Internationalized Domain Name. @@ -104,19 +112,12 @@ public class HttpClientURITest extends AbstractHttpClientServerTest HttpField location = response.getHeaders().getField(HttpHeader.LOCATION); Assert.assertEquals(incorrectlyDecoded, location.getValue()); - try - { - client.newRequest("localhost", server.getLocalPort()) - .timeout(5, TimeUnit.SECONDS) - .followRedirects(true) - .send(); - } - catch (ExecutionException x) - { - Throwable cause = x.getCause(); - if (cause instanceof IllegalArgumentException) - throw (IllegalArgumentException)cause; - } + expectedException.expect(ExecutionException.class); + expectedException.expectCause(instanceOf(IllegalArgumentException.class)); + client.newRequest("localhost", server.getLocalPort()) + .timeout(5, TimeUnit.SECONDS) + .followRedirects(true) + .send(); } finally {