This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch 4.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/4.1.x-fixes by this push:
     new f8bce9c3041 Removing deprecated junit ExpectedException.none (#3187)
f8bce9c3041 is described below

commit f8bce9c304173c228925468cc0c98783f65b0a6b
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Fri Jun 5 14:03:41 2026 +0100

    Removing deprecated junit ExpectedException.none (#3187)
    
    (cherry picked from commit 011c52d2e90fd132ea360888fbe4870c1f43dfc7)
---
 .../autoconfigure/CxfAutoConfigurationTest.java    | 12 ++--
 .../apache/cxf/jaxrs/impl/UriBuilderImplTest.java  | 14 ++---
 .../impl/tl/ThreadLocalInvocationHandlerTest.java  | 40 +++++--------
 .../jaxrs/sse/SseEventSinkContextProviderTest.java | 21 +++----
 .../jaxrs/sse/client/SseEventSourceImplTest.java   | 10 +---
 .../jaxrs/metrics/JAXRSClientMetricsTest.java      | 31 +++++-----
 .../jaxrs/metrics/JAXRSServerMetricsTest.java      | 24 +++-----
 .../jaxws/metrics/JAXWSClientMetricsTest.java      | 11 +---
 .../brave/jaxrs/AbstractBraveTracingTest.java      | 23 +++----
 .../JaxrsOpenTelemetryTracingTest.java             | 21 +++----
 .../opentracing/JaxrsOpenTracingTracingTest.java   | 21 +++----
 .../systest/http/HTTPConduitIoExceptionsTest.java  | 70 ++++++----------------
 12 files changed, 99 insertions(+), 199 deletions(-)

diff --git 
a/integration/spring-boot/autoconfigure/src/test/java/org/apache/cxf/spring/boot/autoconfigure/CxfAutoConfigurationTest.java
 
b/integration/spring-boot/autoconfigure/src/test/java/org/apache/cxf/spring/boot/autoconfigure/CxfAutoConfigurationTest.java
index cc6b1b335f7..d7f05ac097d 100644
--- 
a/integration/spring-boot/autoconfigure/src/test/java/org/apache/cxf/spring/boot/autoconfigure/CxfAutoConfigurationTest.java
+++ 
b/integration/spring-boot/autoconfigure/src/test/java/org/apache/cxf/spring/boot/autoconfigure/CxfAutoConfigurationTest.java
@@ -36,9 +36,7 @@ import org.springframework.test.util.ReflectionTestUtils;
 import 
org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
 
 import org.junit.After;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.allOf;
@@ -50,6 +48,7 @@ import static org.hamcrest.Matchers.hasProperty;
 import static org.hamcrest.Matchers.instanceOf;
 import static org.hamcrest.collection.IsEmptyCollection.empty;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 /**
@@ -59,9 +58,6 @@ import static org.junit.Assert.assertTrue;
  */
 public class CxfAutoConfigurationTest {
 
-    @Rule
-    public ExpectedException thrown = ExpectedException.none();
-
     private AnnotationConfigWebApplicationContext context;
 
     @After
@@ -80,13 +76,13 @@ public class CxfAutoConfigurationTest {
 
     @Test
     public void customPathMustBeginWithASlash() {
-        this.thrown.expect(UnsatisfiedDependencyException.class);
-        this.thrown.expectCause(
+        UnsatisfiedDependencyException exception = 
assertThrows(UnsatisfiedDependencyException.class,
+            () -> load(CxfAutoConfiguration.class, "cxf.path=invalid"));
+        assertThat(exception.getCause(),
             allOf(instanceOf(ConfigurationPropertiesBindException.class), 
hasProperty("cause", 
                 allOf(instanceOf(BindException.class), hasProperty("cause",
                     allOf(instanceOf(BindValidationException.class), 
                         hasProperty("message", containsString("Path must start 
with /"))))))));
-        load(CxfAutoConfiguration.class, "cxf.path=invalid");
     }
 
     @Test
diff --git 
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
index 63dfe41ff68..a5778ee9293 100644
--- 
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
+++ 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
@@ -38,9 +38,7 @@ import org.apache.cxf.jaxrs.resources.BookStore;
 import org.apache.cxf.jaxrs.resources.UriBuilderWrongAnnotations;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThrows;
@@ -48,9 +46,6 @@ import static org.junit.Assert.fail;
 
 public class UriBuilderImplTest {
 
-    @Rule
-    public ExpectedException thrown = ExpectedException.none();
-
     @Test
     public void testFromUriRelativePath() throws Exception {
         UriBuilder builder = UriBuilder.fromUri("path");
@@ -863,12 +858,11 @@ public class UriBuilderImplTest {
 
     @Test
     public void testAddPathMethodNoAnnotation() throws Exception {
-        thrown.expect(IllegalArgumentException.class);
-        thrown.expectMessage(
-                String.format("Method '%s.getBook' is not annotated with Path",
-                BookStore.class.getCanonicalName()));
         Method noAnnot = BookStore.class.getMethod("getBook", String.class);
-        new UriBuilderImpl().path(noAnnot).build();
+        IllegalArgumentException ex = 
assertThrows(IllegalArgumentException.class,
+            () -> new UriBuilderImpl().path(noAnnot).build());
+        assertEquals(String.format("Method '%s.getBook' is not annotated with 
Path",
+            BookStore.class.getCanonicalName()), ex.getMessage());
     }
 
     @Test
diff --git 
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandlerTest.java
 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandlerTest.java
index cc534b9c8b2..812572edd7f 100644
--- 
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandlerTest.java
+++ 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandlerTest.java
@@ -24,9 +24,10 @@ import java.lang.reflect.Proxy;
 import java.net.SocketException;
 
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
 
 public class ThreadLocalInvocationHandlerTest {
 
@@ -37,13 +38,6 @@ public class ThreadLocalInvocationHandlerTest {
 
     private TestIface testIface;
 
-    private ExpectedException expectedException = ExpectedException.none();
-
-    @Rule
-    public ExpectedException getExpectedExceptionRule() {
-        return expectedException;
-    }
-
     @Before
     public void setUp() throws Exception {
         ThreadLocalInvocationHandler<TestClass> subject = new 
ThreadLocalInvocationHandler<>();
@@ -55,34 +49,30 @@ public class ThreadLocalInvocationHandlerTest {
 
     @Test
     public void testCheckedExceptionPropagation() throws Exception {
-        expectedException.expect(SocketException.class);
-        expectedException.expectMessage(CHECKED_EXCEPTION_MSG);
-
-        testIface.throwCheckedException();
+        SocketException ex = assertThrows(SocketException.class,
+                () -> testIface.throwCheckedException());
+        assertEquals(CHECKED_EXCEPTION_MSG, ex.getMessage());
     }
 
     @Test
     public void testUncheckedExceptionPropagation() {
-        expectedException.expect(IndexOutOfBoundsException.class);
-        expectedException.expectMessage(UNCHECKED_EXCEPTION_MSG);
-
-        testIface.throwUncheckedException();
+        IndexOutOfBoundsException ex = 
assertThrows(IndexOutOfBoundsException.class,
+                () -> testIface.throwUncheckedException());
+        assertEquals(UNCHECKED_EXCEPTION_MSG, ex.getMessage());
     }
 
     @Test
     public void testErrorPropagation() {
-        expectedException.expect(AnnotationFormatError.class);
-        expectedException.expectMessage(ERROR_MSG);
-
-        testIface.throwError();
+        AnnotationFormatError ex = assertThrows(AnnotationFormatError.class,
+                () -> testIface.throwError());
+        assertEquals(ERROR_MSG, ex.getMessage());
     }
 
     @Test
     public void testThrowablePropagation() throws Throwable {
-        expectedException.expect(Throwable.class);
-        expectedException.expectMessage(THROWABLE_MSG);
-
-        testIface.throwThrowable();
+        Throwable ex = assertThrows(Throwable.class,
+                () -> testIface.throwThrowable());
+        assertEquals(THROWABLE_MSG, ex.getMessage());
     }
 
     private interface TestIface {
diff --git 
a/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/SseEventSinkContextProviderTest.java
 
b/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/SseEventSinkContextProviderTest.java
index 8f59c4104e3..b91e0a8214a 100644
--- 
a/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/SseEventSinkContextProviderTest.java
+++ 
b/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/SseEventSinkContextProviderTest.java
@@ -37,20 +37,17 @@ import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
 
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.startsWith;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 public class SseEventSinkContextProviderTest {
     private static final OutboundSseEvent EVENT = new 
OutboundSseEventImpl.BuilderImpl().build();
-
-    @Rule
-    public ExpectedException exception = ExpectedException.none();
     
     private SseEventSinkContextProvider provider;
     private Message message;
@@ -96,11 +93,10 @@ public class SseEventSinkContextProviderTest {
         // The buffer overflow should trigger message rejection and 
exceptional completion
         final CompletableFuture<?> overflow = 
sink.send(EVENT).toCompletableFuture();
         assertThat(overflow.isCompletedExceptionally(), equalTo(true));
-        
-        exception.expect(CompletionException.class);
-        exception.expectMessage("The buffer is full (10000), unable to queue 
SSE event for send.");
 
-        overflow.join();
+        final CompletionException ex = assertThrows(CompletionException.class, 
overflow::join);
+        assertThat(ex.getCause().getMessage(),
+            startsWith("The buffer is full (10000)"));
     }
     
     @Test
@@ -118,10 +114,9 @@ public class SseEventSinkContextProviderTest {
         // The buffer overflow should trigger message rejection and 
exceptional completion
         final CompletableFuture<?> overflow = 
sink.send(EVENT).toCompletableFuture();
         assertThat(overflow.isCompletedExceptionally(), equalTo(true));
-        
-        exception.expect(CompletionException.class);
-        exception.expectMessage("The buffer is full (20000), unable to queue 
SSE event for send."); 
 
-        overflow.join();
+        final CompletionException ex = assertThrows(CompletionException.class, 
overflow::join);
+        assertThat(ex.getCause().getMessage(),
+            startsWith("The buffer is full (20000)"));
     }
 }
diff --git 
a/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImplTest.java
 
b/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImplTest.java
index 501840bef88..5b65870007a 100644
--- 
a/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImplTest.java
+++ 
b/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImplTest.java
@@ -51,15 +51,14 @@ import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 import static org.awaitility.Awaitility.await;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 
 
 public class SseEventSourceImplTest {
@@ -109,9 +108,6 @@ public class SseEventSourceImplTest {
 
     private static final Map<Type, Server> SERVERS = new EnumMap<>(Type.class);
 
-    @Rule
-    public ExpectedException exception = ExpectedException.none();
-
     private final List<InboundSseEvent> events = new ArrayList<>();
     private final List<Throwable> errors = new ArrayList<>();
 
@@ -207,8 +203,8 @@ public class SseEventSourceImplTest {
             // The attempt to open the SSE connection in another thread at the 
same
             // time should fail
             final Future<?> future = executor.submit(() -> eventSource.open());
-            exception.expectCause(instanceOf(IllegalStateException.class));
-            assertThat(future.get(), equalTo(null));
+            final ExecutionException ex = 
assertThrows(ExecutionException.class, future::get);
+            assertThat(ex.getCause(), instanceOf(IllegalStateException.class));
 
             assertThat(eventSource.isOpen(), equalTo(true));
             assertThat(events.size(), equalTo(1));
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/metrics/JAXRSClientMetricsTest.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/metrics/JAXRSClientMetricsTest.java
index 310b4fb61fd..8d4c8e8929d 100644
--- 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/metrics/JAXRSClientMetricsTest.java
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/metrics/JAXRSClientMetricsTest.java
@@ -42,7 +42,6 @@ import org.apache.cxf.testutil.common.TestUtil;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.junit.runner.RunWith;
 import org.mockito.Mockito;
 import org.mockito.junit.MockitoJUnitRunner;
@@ -53,6 +52,7 @@ import static 
com.github.tomakehurst.wiremock.client.WireMock.get;
 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
 import static 
com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.Mockito.times;
@@ -60,7 +60,6 @@ import static org.mockito.Mockito.times;
 @RunWith(MockitoJUnitRunner.class)
 public class JAXRSClientMetricsTest {
     @Rule public WireMockRule wireMockRule = new 
WireMockRule(wireMockConfig().dynamicPort());
-    @Rule public ExpectedException expectedException = 
ExpectedException.none();
     
     private MetricsProvider provider;
     private MetricsContext operationContext;
@@ -102,8 +101,7 @@ public class JAXRSClientMetricsTest {
 
         try {
             final Library client = factory.create(Library.class);
-            expectedException.expect(NotFoundException.class);
-            client.getBook(10);
+            assertThrows(NotFoundException.class, () -> client.getBook(10));
         } finally {
             Mockito.verify(resourceContext, 
times(1)).start(any(Exchange.class));
             Mockito.verify(resourceContext, times(1)).stop(anyLong(), 
anyLong(), anyLong(), any(Exchange.class));
@@ -123,11 +121,11 @@ public class JAXRSClientMetricsTest {
                 .withStatus(404)));
 
         try {
-            expectedException.expect(ProcessingException.class);
-            client
-                .target("http://localhost:"; + wireMockRule.port() + 
"/books/10")
-                .request(MediaType.APPLICATION_JSON).get()
-                .readEntity(Book.class);
+            assertThrows(ProcessingException.class,
+                () -> client
+                    .target("http://localhost:"; + wireMockRule.port() + 
"/books/10")
+                    .request(MediaType.APPLICATION_JSON).get()
+                    .readEntity(Book.class));
         } finally {
             Mockito.verify(resourceContext, 
times(1)).start(any(Exchange.class));
             Mockito.verify(resourceContext, times(1)).stop(anyLong(), 
anyLong(), anyLong(), any(Exchange.class));
@@ -145,12 +143,12 @@ public class JAXRSClientMetricsTest {
             .register(JacksonJsonProvider.class);
 
         try {
-            expectedException.expect(ProcessingException.class);
-            client
-                .target("http://localhost:"; + port + "/books/10")
-                .request(MediaType.APPLICATION_JSON)
-                .get()
-                .readEntity(Book.class);
+            assertThrows(ProcessingException.class,
+                () -> client
+                    .target("http://localhost:"; + port + "/books/10")
+                    .request(MediaType.APPLICATION_JSON)
+                    .get()
+                    .readEntity(Book.class));
         } finally {
             Mockito.verify(resourceContext, 
times(1)).start(any(Exchange.class));
             Mockito.verify(resourceContext, times(1)).stop(anyLong(), 
anyLong(), anyLong(), any(Exchange.class));
@@ -195,8 +193,7 @@ public class JAXRSClientMetricsTest {
                 .withStatus(404)));
 
         try {
-            expectedException.expect(ProcessingException.class);
-            client.get().readEntity(Book.class);
+            assertThrows(ProcessingException.class, () -> 
client.get().readEntity(Book.class));
         } finally {
             Mockito.verify(resourceContext, 
times(1)).start(any(Exchange.class));
             Mockito.verify(resourceContext, times(1)).stop(anyLong(), 
anyLong(), anyLong(), any(Exchange.class));
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/metrics/JAXRSServerMetricsTest.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/metrics/JAXRSServerMetricsTest.java
index 26671708749..5b9f8496fee 100644
--- 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/metrics/JAXRSServerMetricsTest.java
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/metrics/JAXRSServerMetricsTest.java
@@ -45,13 +45,12 @@ import 
org.apache.cxf.testutil.common.AbstractServerTestServerBase;
 
 import org.junit.Before;
 import org.junit.BeforeClass;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.junit.runner.RunWith;
 import org.mockito.Mockito;
 import org.mockito.junit.MockitoJUnitRunner;
 
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyLong;
@@ -64,8 +63,6 @@ public class JAXRSServerMetricsTest extends 
AbstractClientServerTestBase {
     private static MetricsProvider provider;
     private static MetricsContext operationContext;
     private static MetricsContext resourceContext;
-        
-    @Rule public ExpectedException expectedException = 
ExpectedException.none();
     
     public static class BookLibrary implements Library {
         @Override
@@ -136,8 +133,7 @@ public class JAXRSServerMetricsTest extends 
AbstractClientServerTestBase {
         
         try {
             final Library client = factory.create(Library.class);
-            expectedException.expect(NotFoundException.class);
-            client.getBook(10);
+            assertThrows(NotFoundException.class, () -> client.getBook(10));
         } finally {
             Mockito.verify(resourceContext, 
times(1)).start(any(Exchange.class));
             Mockito.verify(resourceContext, times(1)).stop(anyLong(), 
anyLong(), anyLong(), any(Exchange.class));
@@ -152,11 +148,11 @@ public class JAXRSServerMetricsTest extends 
AbstractClientServerTestBase {
             .register(JacksonJsonProvider.class);
 
         try {
-            expectedException.expect(ProcessingException.class);
-            client
-                .target("http://localhost:"; + PORT + "/books/10")
-                .request(MediaType.APPLICATION_JSON).get()
-                .readEntity(Book.class);
+            assertThrows(ProcessingException.class,
+                () -> client
+                    .target("http://localhost:"; + PORT + "/books/10")
+                    .request(MediaType.APPLICATION_JSON).get()
+                    .readEntity(Book.class));
         } finally {
             Mockito.verify(resourceContext, 
times(1)).start(any(Exchange.class));
             Mockito.verify(resourceContext, times(1)).stop(anyLong(), 
anyLong(), anyLong(), any(Exchange.class));
@@ -189,8 +185,7 @@ public class JAXRSServerMetricsTest extends 
AbstractClientServerTestBase {
             Arrays.asList(JacksonJsonProvider.class));
         
         try {
-            expectedException.expect(ProcessingException.class);
-            client.get().readEntity(Book.class);
+            assertThrows(ProcessingException.class, () -> 
client.get().readEntity(Book.class));
         } finally {
             Mockito.verify(resourceContext, 
times(1)).start(any(Exchange.class));
             Mockito.verify(resourceContext, times(1)).stop(anyLong(), 
anyLong(), anyLong(), any(Exchange.class));
@@ -204,8 +199,7 @@ public class JAXRSServerMetricsTest extends 
AbstractClientServerTestBase {
             Arrays.asList(JacksonJsonProvider.class));
         
         try {
-            expectedException.expect(ProcessingException.class);
-            client.get().readEntity(Book.class);
+            assertThrows(ProcessingException.class, () -> 
client.get().readEntity(Book.class));
         } finally {
             Mockito.verifyNoInteractions(resourceContext);
             Mockito.verifyNoInteractions(operationContext);
diff --git 
a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/metrics/JAXWSClientMetricsTest.java
 
b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/metrics/JAXWSClientMetricsTest.java
index 8ff02602d61..5e4fa611b7c 100644
--- 
a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/metrics/JAXWSClientMetricsTest.java
+++ 
b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/metrics/JAXWSClientMetricsTest.java
@@ -34,22 +34,19 @@ import org.apache.cxf.service.model.BindingOperationInfo;
 import org.apache.cxf.test.AbstractCXFSpringTest;
 
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.junit.runner.RunWith;
 import org.mockito.Mockito;
 import org.mockito.junit.MockitoJUnitRunner;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.Mockito.times;
 
 @RunWith(MockitoJUnitRunner.class)
 public class JAXWSClientMetricsTest extends AbstractCXFSpringTest {
-    @Rule public ExpectedException expectedException = 
ExpectedException.none();
-    
     private MetricsProvider provider;
     private MetricsContext operationContext;
     private MetricsContext resourceContext;
@@ -107,8 +104,7 @@ public class JAXWSClientMetricsTest extends 
AbstractCXFSpringTest {
         
         try {
             final Client client = factory.create();
-            expectedException.expect(SoapFault.class);
-            client.invoke("getBook", 11);
+            assertThrows(SoapFault.class, () -> client.invoke("getBook", 11));
         } finally {
             Mockito.verify(operationContext, 
times(1)).start(any(Exchange.class));
             Mockito.verify(operationContext, times(1)).stop(anyLong(), 
anyLong(), anyLong(), any(Exchange.class));
@@ -127,8 +123,7 @@ public class JAXWSClientMetricsTest extends 
AbstractCXFSpringTest {
         
         try {
             final Client client = factory.create();
-            expectedException.expect(UncheckedException.class);
-            client.invoke("getBooks");
+            assertThrows(UncheckedException.class, () -> 
client.invoke("getBooks"));
         } finally {
             Mockito.verifyNoInteractions(endpointContext);
             Mockito.verifyNoInteractions(operationContext);
diff --git 
a/systests/tracing/src/test/java/org/apache/cxf/systest/brave/jaxrs/AbstractBraveTracingTest.java
 
b/systests/tracing/src/test/java/org/apache/cxf/systest/brave/jaxrs/AbstractBraveTracingTest.java
index c7839595cf3..43afd0cc56b 100644
--- 
a/systests/tracing/src/test/java/org/apache/cxf/systest/brave/jaxrs/AbstractBraveTracingTest.java
+++ 
b/systests/tracing/src/test/java/org/apache/cxf/systest/brave/jaxrs/AbstractBraveTracingTest.java
@@ -45,9 +45,7 @@ import 
org.apache.cxf.testutil.common.AbstractClientServerTestBase;
 import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
 
 import org.junit.After;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 import static org.apache.cxf.systest.HasSize.hasSize;
 import static 
org.apache.cxf.systest.brave.BraveTestSupport.PARENT_SPAN_ID_NAME;
@@ -65,14 +63,12 @@ import static 
org.hamcrest.collection.IsMapContaining.hasEntry;
 import static org.hamcrest.collection.IsMapContaining.hasKey;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
 
 public abstract class AbstractBraveTracingTest extends 
AbstractClientServerTestBase {
 
     private static final AtomicLong RANDOM = new AtomicLong();
 
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-
     private final Tracing brave = Tracing.newBuilder()
         .addSpanHandler(new TestSpanHandler())
         .build();
@@ -337,16 +333,13 @@ public abstract class AbstractBraveTracingTest extends 
AbstractClientServerTestB
         httpClientPolicy.setReceiveTimeout(100);
         
WebClient.getConfig(client).getHttpConduit().setClient(httpClientPolicy);
 
-        expectedException.expect(ProcessingException.class);
-        try {
-            client.get();
-        } finally {
-            await().atMost(Duration.ofSeconds(5L)).untilAsserted(() ->
-                assertThat(TestSpanHandler.getAllSpans(), hasSize(2)));
-            assertThat(TestSpanHandler.getAllSpans().get(0).name(), 
equalTo("GET " + client.getCurrentURI()));
-            assertThat(TestSpanHandler.getAllSpans().get(0).tags(), 
hasKey("error"));
-            assertThat(TestSpanHandler.getAllSpans().get(1).name(), 
equalTo("GET /bookstore/books/long"));
-        }
+        assertThrows(ProcessingException.class, () -> client.get());
+
+        await().atMost(Duration.ofSeconds(5L)).untilAsserted(() ->
+            assertThat(TestSpanHandler.getAllSpans(), hasSize(2)));
+        assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("GET " 
+ client.getCurrentURI()));
+        assertThat(TestSpanHandler.getAllSpans().get(0).tags(), 
hasKey("error"));
+        assertThat(TestSpanHandler.getAllSpans().get(1).name(), equalTo("GET 
/bookstore/books/long"));
     }
 
     @Test
diff --git 
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentelemetry/JaxrsOpenTelemetryTracingTest.java
 
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentelemetry/JaxrsOpenTelemetryTracingTest.java
index 2240f000fc7..ebec4e09c2a 100644
--- 
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentelemetry/JaxrsOpenTelemetryTracingTest.java
+++ 
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentelemetry/JaxrsOpenTelemetryTracingTest.java
@@ -76,9 +76,7 @@ import io.opentelemetry.semconv.UserAgentAttributes;
 import org.junit.After;
 import org.junit.BeforeClass;
 import org.junit.ClassRule;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 import static org.apache.cxf.systest.HasSize.hasSize;
 import static 
org.apache.cxf.systest.jaxrs.tracing.opentelemetry.HasAttribute.hasAttribute;
@@ -91,6 +89,7 @@ import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.notNullValue;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 public class JaxrsOpenTelemetryTracingTest extends 
AbstractClientServerTestBase {
@@ -101,9 +100,6 @@ public class JaxrsOpenTelemetryTracingTest extends 
AbstractClientServerTestBase
 
     private static final AtomicLong RANDOM = new AtomicLong();
 
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-
     @BeforeClass
     public static void startServers() {
         AbstractResourceInfo.clearAllMaps();
@@ -435,15 +431,12 @@ public class JaxrsOpenTelemetryTracingTest extends 
AbstractClientServerTestBase
         httpClientPolicy.setReceiveTimeout(100);
         
WebClient.getConfig(client).getHttpConduit().setClient(httpClientPolicy);
 
-        expectedException.expect(ProcessingException.class);
-        try {
-            client.get();
-        } finally {
-            await().atMost(Duration.ofSeconds(5L)).untilAsserted(() -> 
assertThat(otelRule.getSpans(), hasSize(2)));
-            assertThat(otelRule.getSpans().get(0).getName(), equalTo("GET " + 
client.getCurrentURI()));
-            assertThat(otelRule.getSpans().get(0).getStatus().getStatusCode(), 
equalTo(StatusCode.ERROR));
-            assertThat(otelRule.getSpans().get(1).getName(), equalTo("GET 
/bookstore/books/long"));
-        }
+        assertThrows(ProcessingException.class, () -> client.get());
+
+        await().atMost(Duration.ofSeconds(5L)).untilAsserted(() -> 
assertThat(otelRule.getSpans(), hasSize(2)));
+        assertThat(otelRule.getSpans().get(0).getName(), equalTo("GET " + 
client.getCurrentURI()));
+        assertThat(otelRule.getSpans().get(0).getStatus().getStatusCode(), 
equalTo(StatusCode.ERROR));
+        assertThat(otelRule.getSpans().get(1).getName(), equalTo("GET 
/bookstore/books/long"));
     }
 
     @Test
diff --git 
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentracing/JaxrsOpenTracingTracingTest.java
 
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentracing/JaxrsOpenTracingTracingTest.java
index aa647cba4a5..fcda200d788 100644
--- 
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentracing/JaxrsOpenTracingTracingTest.java
+++ 
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentracing/JaxrsOpenTracingTracingTest.java
@@ -67,9 +67,7 @@ import io.opentracing.tag.Tags;
 
 import org.junit.After;
 import org.junit.BeforeClass;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 import static org.apache.cxf.systest.HasSize.hasSize;
 import static org.apache.cxf.systest.jaxrs.tracing.opentracing.HasSpan.hasSpan;
@@ -81,6 +79,7 @@ import static org.hamcrest.CoreMatchers.not;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.empty;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 public class JaxrsOpenTracingTracingTest extends AbstractClientServerTestBase {
@@ -90,9 +89,6 @@ public class JaxrsOpenTracingTracingTest extends 
AbstractClientServerTestBase {
 
     private static final InMemoryReporter REPORTER = new InMemoryReporter();
 
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-
     private final Tracer tracer = new JaegerTracer.Builder("tracer-jaxrs")
         .withSampler(new ConstSampler(true))
         .withReporter(REPORTER)
@@ -383,15 +379,12 @@ public class JaxrsOpenTracingTracingTest extends 
AbstractClientServerTestBase {
         httpClientPolicy.setReceiveTimeout(100);
         
WebClient.getConfig(client).getHttpConduit().setClient(httpClientPolicy);
 
-        expectedException.expect(ProcessingException.class);
-        try {
-            client.get();
-        } finally {
-            await().atMost(Duration.ofSeconds(5L)).untilAsserted(() -> 
assertThat(REPORTER.getSpans(), hasSize(2)));
-            assertThat(REPORTER.getSpans().get(0).getOperationName(), 
equalTo("GET " + client.getCurrentURI()));
-            assertThat(REPORTER.getSpans().get(0).getTags(), 
hasItem(Tags.ERROR.getKey(), Boolean.TRUE));
-            assertThat(REPORTER.getSpans().get(1).getOperationName(), 
equalTo("GET /bookstore/books/long"));
-        }
+        assertThrows(ProcessingException.class, () -> client.get());
+
+        await().atMost(Duration.ofSeconds(5L)).untilAsserted(() -> 
assertThat(REPORTER.getSpans(), hasSize(2)));
+        assertThat(REPORTER.getSpans().get(0).getOperationName(), equalTo("GET 
" + client.getCurrentURI()));
+        assertThat(REPORTER.getSpans().get(0).getTags(), 
hasItem(Tags.ERROR.getKey(), Boolean.TRUE));
+        assertThat(REPORTER.getSpans().get(1).getOperationName(), equalTo("GET 
/bookstore/books/long"));
     }
 
     @Test
diff --git 
a/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitIoExceptionsTest.java
 
b/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitIoExceptionsTest.java
index 9a7b7993b9e..8817031d95d 100644
--- 
a/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitIoExceptionsTest.java
+++ 
b/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitIoExceptionsTest.java
@@ -33,20 +33,16 @@ import org.apache.cxf.transport.http.HTTPConduit;
 import org.apache.cxf.transport.http.HTTPException;
 import org.apache.hello_world.Greeter;
 import org.apache.hello_world.services.SOAPService;
-import org.hamcrest.Description;
-import org.hamcrest.TypeSafeMatcher;
 
 import org.junit.BeforeClass;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 public class HTTPConduitIoExceptionsTest extends 
AbstractBusClientServerTestBase {
-    @Rule public final ExpectedException exception = ExpectedException.none();
-
     private final QName serviceName =
         new QName("http://apache.org/hello_world";, "SOAPService");
       
@@ -68,11 +64,9 @@ public class HTTPConduitIoExceptionsTest extends 
AbstractBusClientServerTestBase
 
         try (Client client = (Client)greeter) {
             client.getRequestContext().put(HTTPConduit.NO_IO_EXCEPTIONS, true);
-            
-            exception.expect(SOAPFaultException.class);
-            exception.expectMessage("Go away");
-            
-            greeter.sayHi();
+
+            SOAPFaultException ex = assertThrows(SOAPFaultException.class, () 
-> greeter.sayHi());
+            assertTrue(ex.getMessage().contains("Go away"));
         }
     }
 
@@ -80,54 +74,24 @@ public class HTTPConduitIoExceptionsTest extends 
AbstractBusClientServerTestBase
     public void testServiceUnavailable() throws Exception {
         final Greeter greeter = getGreeter();
 
-        exception.expect(WebServiceException.class);
-        exception.expectCause(new TypeSafeMatcher<Throwable>() {
-            private static final String message = "HTTP response '503: Service 
Unavailable' when "
-                + "communicating with http://localhost:"; + BadServer.PORT + 
"/Mortimer";
-
-            @Override
-            public void describeTo(Description description) {
-                description
-                    .appendValue(HTTPException.class)
-                    .appendText(" and message ")
-                    .appendValue(message);
-            }
-
-            @Override
-            protected boolean matchesSafely(Throwable item) {
-                return item instanceof HTTPException && 
item.getMessage().equals(message);
-            }
-        });
-        
-        
-        greeter.sayHi();
+        WebServiceException ex = assertThrows(WebServiceException.class, () -> 
greeter.sayHi());
+        final String message = "HTTP response '503: Service Unavailable' when "
+            + "communicating with http://localhost:"; + BadServer.PORT + 
"/Mortimer";
+        Throwable cause = ex.getCause();
+        assertTrue(cause instanceof HTTPException);
+        assertEquals(message, cause.getMessage());
     }
 
     @Test
     public void testNotFound() throws Exception {
         final Greeter greeter = getGreeter();
 
-        exception.expect(WebServiceException.class);
-        exception.expectCause(new TypeSafeMatcher<Throwable>() {
-            private static final String message = "HTTP response '404: Not 
Found' when "
-                + "communicating with http://localhost:"; + BadServer.PORT + 
"/Mortimer";
-
-            @Override
-            public void describeTo(Description description) {
-                description
-                    .appendValue(HTTPException.class)
-                    .appendText(" and message ")
-                    .appendValue(message);
-            }
-
-            @Override
-            protected boolean matchesSafely(Throwable item) {
-                return item instanceof HTTPException && 
item.getMessage().equals(message);
-            }
-        });
-        
-        
-        greeter.greetMe("Test");
+        WebServiceException ex = assertThrows(WebServiceException.class, () -> 
greeter.greetMe("Test"));
+        final String message = "HTTP response '404: Not Found' when "
+            + "communicating with http://localhost:"; + BadServer.PORT + 
"/Mortimer";
+        Throwable cause = ex.getCause();
+        assertTrue(cause instanceof HTTPException);
+        assertEquals(message, cause.getMessage());
     }
     
     private Greeter getGreeter() throws MalformedURLException {


Reply via email to