diff --git a/core/trino-main/src/test/java/io/trino/sql/TestSqlEnvironmentConfig.java b/core/trino-main/src/test/java/io/trino/sql/TestSqlEnvironmentConfig.java index 21f3a3c81c5e..db94d8df26cb 100644 --- a/core/trino-main/src/test/java/io/trino/sql/TestSqlEnvironmentConfig.java +++ b/core/trino-main/src/test/java/io/trino/sql/TestSqlEnvironmentConfig.java @@ -22,6 +22,7 @@ import static io.airlift.configuration.testing.ConfigAssertions.assertFullMapping; import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults; import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults; +import static org.assertj.core.api.Assertions.assertThatThrownBy; public class TestSqlEnvironmentConfig { @@ -54,10 +55,12 @@ public void testExplicitPropertyMappings() assertFullMapping(properties, expected); } - @Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "\\Qline 1:9: mismatched input '.'. Expecting: ',', \\E") + @Test public void testInvalidPath() { SqlEnvironmentConfig config = new SqlEnvironmentConfig().setPath("too.many.qualifiers"); - new SqlPath(config.getPath()).getParsedPath(); + assertThatThrownBy(() -> new SqlPath(config.getPath()).getParsedPath()) + .isInstanceOf(ParsingException.class) + .hasMessageMatching("\\Qline 1:9: mismatched input '.'. Expecting: ',', \\E"); } } diff --git a/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/TestJoinNodeFlattener.java b/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/TestJoinNodeFlattener.java index 5bc6f69b95e5..12a78c8d9a7f 100644 --- a/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/TestJoinNodeFlattener.java +++ b/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/TestJoinNodeFlattener.java @@ -65,6 +65,7 @@ import static io.trino.sql.tree.ComparisonExpression.Operator.LESS_THAN; import static io.trino.sql.tree.ComparisonExpression.Operator.NOT_EQUAL; import static io.trino.testing.TestingSession.testSessionBuilder; +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; @@ -88,7 +89,7 @@ public void tearDown() queryRunner = null; } - @Test(expectedExceptions = IllegalStateException.class) + @Test public void testDoesNotAllowOuterJoin() { PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator(); @@ -103,7 +104,9 @@ public void testDoesNotAllowOuterJoin() ImmutableList.of(a1), ImmutableList.of(b1), Optional.empty()); - toMultiJoinNode(queryRunner.getMetadata(), outerJoin, noLookup(), planNodeIdAllocator, DEFAULT_JOIN_LIMIT, false, testSessionBuilder().build(), new TypeAnalyzer(new SqlParser(), queryRunner.getMetadata()), p.getTypes()); + assertThatThrownBy(() -> toMultiJoinNode(queryRunner.getMetadata(), outerJoin, noLookup(), planNodeIdAllocator, DEFAULT_JOIN_LIMIT, false, testSessionBuilder().build(), new TypeAnalyzer(new SqlParser(), queryRunner.getMetadata()), p.getTypes())) + .isInstanceOf(IllegalStateException.class) + .hasMessageMatching("join type must be.*"); } @Test diff --git a/plugin/trino-password-authenticators/src/test/java/io/trino/plugin/password/salesforce/TestSalesforceBasicAuthenticator.java b/plugin/trino-password-authenticators/src/test/java/io/trino/plugin/password/salesforce/TestSalesforceBasicAuthenticator.java index 56928a7919eb..2bd8f069e2f0 100644 --- a/plugin/trino-password-authenticators/src/test/java/io/trino/plugin/password/salesforce/TestSalesforceBasicAuthenticator.java +++ b/plugin/trino-password-authenticators/src/test/java/io/trino/plugin/password/salesforce/TestSalesforceBasicAuthenticator.java @@ -31,6 +31,7 @@ import static io.airlift.http.client.HttpStatus.OK; import static io.airlift.http.client.testing.TestingResponse.mockResponse; import static java.lang.String.format; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail; @@ -79,7 +80,7 @@ public void createAuthenticatedPrincipalSuccess() assertEquals(principal.getName(), username, "Test principal name from expired cache."); } - @Test(expectedExceptions = AccessDeniedException.class) + @Test public void createAuthenticatedPrincipalWrongOrg() { String org = "my18CharOrgId"; // As if from ssalesforce.allowed-organizations property. @@ -93,10 +94,12 @@ public void createAuthenticatedPrincipalWrongOrg() HttpClient testHttpClient = new TestingHttpClient((request -> mockResponse(OK, ANY_TEXT_TYPE, xmlResponse))); SalesforceBasicAuthenticator authenticator = new SalesforceBasicAuthenticator(config, testHttpClient); - authenticator.createAuthenticatedPrincipal(username, password); + assertThatThrownBy(() -> authenticator.createAuthenticatedPrincipal(username, password)) + .isInstanceOf(AccessDeniedException.class) + .hasMessageMatching("Access Denied:.*"); } - @Test(expectedExceptions = AccessDeniedException.class) + @Test public void createAuthenticatedPrincipalBadPass() { String org = "my18CharOrgId"; // As if from salesforce.allowed-organizations property. @@ -110,7 +113,9 @@ public void createAuthenticatedPrincipalBadPass() HttpClient testHttpClient = new TestingHttpClient((request -> mockResponse(HttpStatus.INTERNAL_SERVER_ERROR, ANY_TEXT_TYPE, xmlResponse))); SalesforceBasicAuthenticator authenticator = new SalesforceBasicAuthenticator(config, testHttpClient); - authenticator.createAuthenticatedPrincipal(username, password); + assertThatThrownBy(() -> authenticator.createAuthenticatedPrincipal(username, password)) + .isInstanceOf(AccessDeniedException.class) + .hasMessageMatching("Access Denied: Invalid response for login\n.*"); } @Test @@ -192,7 +197,7 @@ public void createAuthenticatedPrincipalRealSuccess() } // Test a real login for a different org. - @Test(expectedExceptions = AccessDeniedException.class, description = "Test got wrong org for real, yo!") + @Test public void createAuthenticatedPrincipalRealWrongOrg() { // Skip this test if SALESFORCE_TEST_FORREAL is not set to TRUE. @@ -212,7 +217,9 @@ public void createAuthenticatedPrincipalRealWrongOrg() HttpClient testHttpClient = new JettyHttpClient(); SalesforceBasicAuthenticator authenticator = new SalesforceBasicAuthenticator(config, testHttpClient); - authenticator.createAuthenticatedPrincipal(username, password); + assertThatThrownBy(() -> authenticator.createAuthenticatedPrincipal(username, password)) + .isInstanceOf(AccessDeniedException.class) + .hasMessage("Test got wrong org for real, yo!"); } // Test a real login for a different org. @@ -241,7 +248,7 @@ public void createAuthenticatedPrincipalRealAllOrgs() } // Test a login with a bad password. - @Test(expectedExceptions = AccessDeniedException.class, description = "Test bad password for real, yo!") + @Test public void createAuthenticatedPrincipalRealBadPassword() { // Skip this test if SALESFORCE_TEST_FORREAL is not set to TRUE. @@ -263,6 +270,8 @@ public void createAuthenticatedPrincipalRealBadPassword() .setAllowedOrganizations(org); HttpClient testHttpClient = new JettyHttpClient(); SalesforceBasicAuthenticator authenticator = new SalesforceBasicAuthenticator(config, testHttpClient); - authenticator.createAuthenticatedPrincipal(username, "NotMyPassword"); + assertThatThrownBy(() -> authenticator.createAuthenticatedPrincipal(username, "NotMyPassword")) + .isInstanceOf(AccessDeniedException.class) + .hasMessage("Test bad password for real, yo!"); } }