From f37bb67f4c16635d2c50e21e89df76f0172e27c9 Mon Sep 17 00:00:00 2001 From: mthomas Date: Thu, 5 Mar 2020 11:47:04 -0600 Subject: [PATCH] BAEL-2552 - use JUnit @Rule --- .../spring/serverconfig/TimeoutLiveTest.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/TimeoutLiveTest.java b/spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/TimeoutLiveTest.java index 09d8032d41..78e61dce5f 100644 --- a/spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/TimeoutLiveTest.java +++ b/spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/TimeoutLiveTest.java @@ -6,7 +6,9 @@ import javax.net.ssl.SSLException; import org.junit.Assert; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -35,6 +37,9 @@ public class TimeoutLiveTest { private WebTestClient webTestClient; + @Rule + public ExpectedException exception = ExpectedException.none(); + @Before public void setup() throws SSLException { webTestClient = WebTestClient.bindToServer(getConnector()) @@ -44,28 +49,22 @@ public class TimeoutLiveTest { @Test public void shouldTimeout() { - try { - webTestClient.get() - .uri("/timeout/{timeout}", 3) - .exchange(); - Assert.fail(); - } catch (ReadTimeoutException ignore) { - } + exception.expect(ReadTimeoutException.class); + webTestClient.get() + .uri("/timeout/{timeout}", 3) + .exchange(); + Assert.fail(); } @Test public void shouldNotTimeout() { - try { - WebTestClient.ResponseSpec response = webTestClient.get() - .uri("/timeout/{timeout}", 1) - .exchange(); - response.expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo("OK"); - } catch (ReadTimeoutException e) { - Assert.fail(); - } + WebTestClient.ResponseSpec response = webTestClient.get() + .uri("/timeout/{timeout}", 1) + .exchange(); + response.expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("OK"); } private ReactorClientHttpConnector getConnector() throws SSLException {