diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/RepositoryIntegrityHealthIndicatorServiceIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/RepositoryIntegrityHealthIndicatorServiceIT.java index b0d3aac76900f..e5e074e404675 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/RepositoryIntegrityHealthIndicatorServiceIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/RepositoryIntegrityHealthIndicatorServiceIT.java @@ -24,7 +24,6 @@ import static org.elasticsearch.health.HealthStatus.RED; import static org.elasticsearch.health.ServerHealthComponents.SNAPSHOT; import static org.elasticsearch.snapshots.RepositoryIntegrityHealthIndicatorService.NAME; -import static org.elasticsearch.test.hamcrest.ThrowableAssertions.assertThatThrows; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -58,9 +57,8 @@ public void testRepositoryIntegrityHealthIndicator() throws IOException, Interru corruptRepository(repository, location); // Currently, the health indicator is not proactively checking the repository and // instead relies on other operations to detect and flag repository corruption - assertThatThrows( - () -> createFullSnapshot(repository, "snapshot-2"), - RepositoryException.class, + assertThat( + expectThrows(RepositoryException.class, () -> createFullSnapshot(repository, "snapshot-2")).getMessage(), containsString("[" + repository + "] Could not read repository data") ); diff --git a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java index e16c71407c6a5..bfb128e88abe4 100644 --- a/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java +++ b/server/src/test/java/org/elasticsearch/repositories/RepositoriesServiceTests.java @@ -52,8 +52,7 @@ import java.util.function.Consumer; import java.util.function.Function; -import static org.elasticsearch.test.hamcrest.ThrowableAssertions.assertThatException; -import static org.elasticsearch.test.hamcrest.ThrowableAssertions.assertThatThrows; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.isA; import static org.mockito.Mockito.mock; @@ -188,9 +187,8 @@ public void testRemoveUnknownRepositoryTypeWhenApplyingClusterState() { repositoriesService.applyClusterState(new ClusterChangedEvent("starting", clusterState, emptyState())); repositoriesService.applyClusterState(new ClusterChangedEvent("removing repo", emptyState(), clusterState)); - assertThatThrows( - () -> repositoriesService.repository(repoName), - RepositoryMissingException.class, + assertThat( + expectThrows(RepositoryMissingException.class, () -> repositoriesService.repository(repoName)).getMessage(), equalTo("[" + repoName + "] missing") ); } @@ -207,7 +205,8 @@ public void onResponse(AcknowledgedResponse acknowledgedResponse) { @Override public void onFailure(Exception e) { - assertThatException(e, RepositoryException.class, equalTo("[" + repoName + "] repository type [unknown] does not exist")); + assertThat(e, isA(RepositoryException.class)); + assertThat(e.getMessage(), equalTo("[" + repoName + "] repository type [unknown] does not exist")); } }); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ThrowableAssertions.java b/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ThrowableAssertions.java deleted file mode 100644 index 2aa43444af72d..0000000000000 --- a/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ThrowableAssertions.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -package org.elasticsearch.test.hamcrest; - -import org.apache.lucene.tests.util.LuceneTestCase; -import org.hamcrest.Matcher; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.isA; - -/** - * Assertions for exceptions and their messages - */ -public class ThrowableAssertions { - - public static void assertThatThrows( - LuceneTestCase.ThrowingRunnable code, - Class exceptionType, - Matcher messageMatcher - ) { - try { - code.run(); - } catch (Throwable e) { - assertThatException(e, exceptionType, messageMatcher); - } - } - - public static void assertThatException(Throwable exception, Class exceptionType, Matcher messageMatcher) { - assertThat(exception, isA(exceptionType)); - assertThat(exception.getMessage(), messageMatcher); - } -}