diff --git a/plugin/trino-example-http/src/test/java/io/trino/plugin/example/TestExampleMetadata.java b/plugin/trino-example-http/src/test/java/io/trino/plugin/example/TestExampleMetadata.java index ae7969a7ee53..9386a37c75e8 100644 --- a/plugin/trino-example-http/src/test/java/io/trino/plugin/example/TestExampleMetadata.java +++ b/plugin/trino-example-http/src/test/java/io/trino/plugin/example/TestExampleMetadata.java @@ -134,15 +134,17 @@ public void getColumnMetadata() // directly. } - @Test(expectedExceptions = TrinoException.class) + @Test public void testCreateTable() { - metadata.createTable( + assertThatThrownBy(() -> metadata.createTable( SESSION, new ConnectorTableMetadata( new SchemaTableName("example", "foo"), ImmutableList.of(new ColumnMetadata("text", createUnboundedVarcharType()))), - false); + false)) + .isInstanceOf(TrinoException.class) + .hasMessage("This connector does not support creating tables"); } @Test(expectedExceptions = TrinoException.class) diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/s3/TestTrinoS3FileSystem.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/s3/TestTrinoS3FileSystem.java index 89d795a8ab42..6889e18d856e 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/s3/TestTrinoS3FileSystem.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/s3/TestTrinoS3FileSystem.java @@ -99,6 +99,7 @@ import static java.nio.file.Files.createTempDirectory; import static java.nio.file.Files.createTempFile; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; @@ -327,7 +328,7 @@ public void testGetMetadataRetryCounter() } @SuppressWarnings("ResultOfMethodCallIgnored") - @Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = ".*Failing getObject call with " + HTTP_NOT_FOUND + ".*") + @Test public void testReadNotFound() throws Exception { @@ -337,13 +338,15 @@ public void testReadNotFound() fs.initialize(new URI("s3n://test-bucket/"), new Configuration(false)); fs.setS3Client(s3); try (FSDataInputStream inputStream = fs.open(new Path("s3n://test-bucket/test"))) { - inputStream.read(); + assertThatThrownBy(() -> inputStream.read()) + .isInstanceOf(IOException.class) + .hasMessageContaining("Failing getObject call with " + HTTP_NOT_FOUND); } } } @SuppressWarnings("ResultOfMethodCallIgnored") - @Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = ".*Failing getObject call with " + HTTP_FORBIDDEN + ".*") + @Test public void testReadForbidden() throws Exception { @@ -353,7 +356,9 @@ public void testReadForbidden() fs.initialize(new URI("s3n://test-bucket/"), new Configuration(false)); fs.setS3Client(s3); try (FSDataInputStream inputStream = fs.open(new Path("s3n://test-bucket/test"))) { - inputStream.read(); + assertThatThrownBy(inputStream::read) + .isInstanceOf(IOException.class) + .hasMessageContaining("Failing getObject call with " + HTTP_FORBIDDEN); } } } @@ -382,7 +387,7 @@ public void testCreateWithNonexistentStagingDirectory() } } - @Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = "Configured staging path is not a directory: .*") + @Test public void testCreateWithStagingDirectoryFile() throws Exception { @@ -395,7 +400,9 @@ public void testCreateWithStagingDirectoryFile() conf.set(S3_STAGING_DIRECTORY, staging.toString()); fs.initialize(new URI("s3n://test-bucket/"), conf); fs.setS3Client(s3); - fs.create(new Path("s3n://test-bucket/test")); + assertThatThrownBy(() -> fs.create(new Path("s3n://test-bucket/test"))) + .isInstanceOf(IOException.class) + .hasMessageStartingWith("Configured staging path is not a directory:"); } finally { Files.deleteIfExists(staging); @@ -451,7 +458,7 @@ public void testReadRequestRangeNotSatisfiable() } } - @Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = ".*Failing getObjectMetadata call with " + HTTP_FORBIDDEN + ".*") + @Test public void testGetMetadataForbidden() throws Exception { @@ -460,7 +467,9 @@ public void testGetMetadataForbidden() s3.setGetObjectMetadataHttpCode(HTTP_FORBIDDEN); fs.initialize(new URI("s3n://test-bucket/"), new Configuration(false)); fs.setS3Client(s3); - fs.getS3ObjectMetadata(new Path("s3n://test-bucket/test")); + assertThatThrownBy(() -> fs.getS3ObjectMetadata(new Path("s3n://test-bucket/test"))) + .isInstanceOf(IOException.class) + .hasMessageContaining("Failing getObjectMetadata call with " + HTTP_FORBIDDEN); } }