diff --git a/plugin/trino-accumulo/src/test/java/io/trino/plugin/accumulo/model/TestRow.java b/plugin/trino-accumulo/src/test/java/io/trino/plugin/accumulo/model/TestRow.java index df5e088339be..c6237a744d10 100644 --- a/plugin/trino-accumulo/src/test/java/io/trino/plugin/accumulo/model/TestRow.java +++ b/plugin/trino-accumulo/src/test/java/io/trino/plugin/accumulo/model/TestRow.java @@ -38,6 +38,7 @@ import static io.trino.spi.type.VarcharType.VARCHAR; import static java.lang.Float.floatToIntBits; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.testng.Assert.assertEquals; public class TestRow @@ -67,10 +68,12 @@ public void testRow() assertEquals(r2, r1); } - @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "type is null") + @Test public void testRowTypeIsNull() { Row r1 = new Row(); - r1.addField(VARCHAR, null); + assertThatThrownBy(() -> r1.addField(VARCHAR, null)) + .isInstanceOf(NullPointerException.class) + .hasMessage("type is null"); } } diff --git a/plugin/trino-atop/src/test/java/io/trino/plugin/atop/TestAtopSecurity.java b/plugin/trino-atop/src/test/java/io/trino/plugin/atop/TestAtopSecurity.java index ffaa7a58705a..420582615984 100644 --- a/plugin/trino-atop/src/test/java/io/trino/plugin/atop/TestAtopSecurity.java +++ b/plugin/trino-atop/src/test/java/io/trino/plugin/atop/TestAtopSecurity.java @@ -29,6 +29,7 @@ import static io.trino.plugin.atop.LocalAtopQueryRunner.createQueryRunner; import static io.trino.testing.TestingSession.testSessionBuilder; +import static org.assertj.core.api.Assertions.assertThatThrownBy; public class TestAtopSecurity { @@ -57,11 +58,13 @@ public void testAdminCanRead() queryRunner.execute(admin, "SELECT * FROM disks"); } - @Test(expectedExceptions = AccessDeniedException.class) + @Test public void testNonAdminCannotRead() { Session bob = getSession("bob"); - queryRunner.execute(bob, "SELECT * FROM disks"); + assertThatThrownBy(() -> queryRunner.execute(bob, "SELECT * FROM disks")) + .isInstanceOf(AccessDeniedException.class) + .hasMessageMatching("Access Denied:.*"); } private Session getSession(String user) diff --git a/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryConnectorTest.java b/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryConnectorTest.java index 41d4638b0be8..0e0cd5ad71df 100644 --- a/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryConnectorTest.java +++ b/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryConnectorTest.java @@ -47,6 +47,7 @@ import static io.trino.testing.assertions.Assert.assertEquals; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; @@ -117,12 +118,15 @@ protected TestTable createTableWithDefaultColumns() throw new SkipException("Memory connector does not support column default values"); } - // it has to be RuntimeException as FailureInfo$FailureException is private - @Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "line 1:1: Destination table 'memory.default.nation' already exists") + @Test public void testCreateTableWhenTableIsAlreadyCreated() { @Language("SQL") String createTableSql = "CREATE TABLE nation AS SELECT * FROM tpch.tiny.nation"; - assertUpdate(createTableSql); + + // it has to be RuntimeException as FailureInfo$FailureException is private + assertThatThrownBy(() -> assertUpdate(createTableSql)) + .isInstanceOf(RuntimeException.class) + .hasMessage("line 1:1: Destination table 'memory.default.nation' already exists"); } @Test diff --git a/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryMetadata.java b/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryMetadata.java index beff350ce852..9b52e4413157 100644 --- a/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryMetadata.java +++ b/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryMetadata.java @@ -41,6 +41,7 @@ import static io.trino.testing.TestingConnectorSession.SESSION; import static io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy; 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.assertNotEquals; import static org.testng.Assert.assertNull; @@ -163,7 +164,7 @@ public void testCreateSchema() assertEquals(metadata.listTables(SESSION, Optional.of("default")), ImmutableList.of()); } - @Test(expectedExceptions = TrinoException.class, expectedExceptionsMessageRegExp = "View already exists: test\\.test_view") + @Test public void testCreateViewWithoutReplace() { SchemaTableName test = new SchemaTableName("test", "test_view"); @@ -174,7 +175,9 @@ public void testCreateViewWithoutReplace() catch (Exception e) { fail("should have succeeded"); } - metadata.createView(SESSION, test, testingViewDefinition("test"), false); + assertThatThrownBy(() -> metadata.createView(SESSION, test, testingViewDefinition("test"), false)) + .isInstanceOf(TrinoException.class) + .hasMessageMatching("View already exists: test\\.test_view"); } @Test diff --git a/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryPagesStore.java b/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryPagesStore.java index e734cf7d6f93..916e9de563c6 100644 --- a/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryPagesStore.java +++ b/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryPagesStore.java @@ -31,6 +31,7 @@ import static io.trino.spi.type.BigintType.BIGINT; import static io.trino.testing.TestingConnectorSession.SESSION; +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.assertTrue; @@ -78,12 +79,14 @@ public void testReadFromUnknownTable() pagesStore.getPages(0L, 0, 1, ImmutableList.of(0), 0, OptionalLong.empty(), OptionalDouble.empty()); } - @Test(expectedExceptions = TrinoException.class) + @Test public void testTryToReadFromEmptyTable() { createTable(0L, 0L); assertEquals(pagesStore.getPages(0L, 0, 1, ImmutableList.of(0), 0, OptionalLong.empty(), OptionalDouble.empty()), ImmutableList.of()); - pagesStore.getPages(0L, 0, 1, ImmutableList.of(0), 42, OptionalLong.empty(), OptionalDouble.empty()); + assertThatThrownBy(() -> pagesStore.getPages(0L, 0, 1, ImmutableList.of(0), 42, OptionalLong.empty(), OptionalDouble.empty())) + .isInstanceOf(TrinoException.class) + .hasMessageMatching("Expected to find.*"); } @Test @@ -110,12 +113,14 @@ public void testCleanUp() assertTrue(pagesStore.contains(2L)); } - @Test(expectedExceptions = TrinoException.class) + @Test public void testMemoryLimitExceeded() { createTable(0L, 0L); insertToTable(0L, createOneMegaBytePage(), 0L); - insertToTable(0L, createOneMegaBytePage(), 0L); + assertThatThrownBy(() -> insertToTable(0L, createOneMegaBytePage(), 0L)) + .isInstanceOf(TrinoException.class) + .hasMessageMatching("Memory limit.*"); } private void insertToTable(long tableId, Long... activeTableIds) diff --git a/plugin/trino-thrift-api/src/test/java/io/trino/plugin/thrift/api/datatypes/TestTrinoThriftBigint.java b/plugin/trino-thrift-api/src/test/java/io/trino/plugin/thrift/api/datatypes/TestTrinoThriftBigint.java index 3a5417bfe1ba..8002605004cd 100644 --- a/plugin/trino-thrift-api/src/test/java/io/trino/plugin/thrift/api/datatypes/TestTrinoThriftBigint.java +++ b/plugin/trino-thrift-api/src/test/java/io/trino/plugin/thrift/api/datatypes/TestTrinoThriftBigint.java @@ -27,6 +27,7 @@ import static io.trino.spi.type.BigintType.BIGINT; import static io.trino.spi.type.IntegerType.INTEGER; import static java.util.Collections.unmodifiableList; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; @@ -84,18 +85,22 @@ public void testReadBlockAllNonNullOption2() assertBlockEquals(actual, list(2L, 7L, 1L, 3L, 8L, 4L, 5L)); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testReadBlockWrongActualType() { TrinoThriftBlock columnsData = integerData(new TrinoThriftInteger(null, null)); - columnsData.toBlock(BIGINT); + assertThatThrownBy(() -> columnsData.toBlock(BIGINT)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageMatching("type doesn't match:.*"); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testReadBlockWrongDesiredType() { TrinoThriftBlock columnsData = longColumn(null, null); - columnsData.toBlock(INTEGER); + assertThatThrownBy(() -> columnsData.toBlock(INTEGER)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageMatching("type doesn't match:.*"); } @Test