From 12be4754f5f4d53da314c85cbe07e0fd43b9ce8b Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Mon, 26 Feb 2024 11:06:14 +0100 Subject: [PATCH] Remove redundant lambdas from test Whole test method asserts that every line of it succeeds, so using `assertThatNoException` is redundant. Of course there could be convention to clearly separate test setup and test assertions (given-when-then), but that's not a convention we use, thuse `assertThatNoException()` is redundant. --- .../TestFilterHideInacessibleColumnsSession.java | 7 +++---- .../filesystem/gcs/TestGcsFileSystemGcs.java | 15 +++++++-------- .../launcher/local/TestManuallyJdbcOauth2.java | 9 +++------ .../TestReportAfterMethodNotAlwaysRun.java | 3 +-- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/core/trino-main/src/test/java/io/trino/sql/query/TestFilterHideInacessibleColumnsSession.java b/core/trino-main/src/test/java/io/trino/sql/query/TestFilterHideInacessibleColumnsSession.java index 72a9bc1335c2..681ead0a02c2 100644 --- a/core/trino-main/src/test/java/io/trino/sql/query/TestFilterHideInacessibleColumnsSession.java +++ b/core/trino-main/src/test/java/io/trino/sql/query/TestFilterHideInacessibleColumnsSession.java @@ -25,7 +25,6 @@ import io.trino.sql.planner.OptimizerConfig; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.assertThatThrownBy; public class TestFilterHideInacessibleColumnsSession @@ -46,7 +45,7 @@ public void testEnableWhenAlreadyEnabledByDefault() FeaturesConfig featuresConfig = new FeaturesConfig(); featuresConfig.setHideInaccessibleColumns(true); SessionPropertyManager sessionPropertyManager = createSessionPropertyManager(featuresConfig); - assertThatNoException().isThrownBy(() -> sessionPropertyManager.validateSystemSessionProperty(SystemSessionProperties.HIDE_INACCESSIBLE_COLUMNS, "true")); + sessionPropertyManager.validateSystemSessionProperty(SystemSessionProperties.HIDE_INACCESSIBLE_COLUMNS, "true"); } @Test @@ -54,7 +53,7 @@ public void testDisableWhenAlreadyDisabledByDefault() { FeaturesConfig featuresConfig = new FeaturesConfig(); SessionPropertyManager sessionPropertyManager = createSessionPropertyManager(featuresConfig); - assertThatNoException().isThrownBy(() -> sessionPropertyManager.validateSystemSessionProperty(SystemSessionProperties.HIDE_INACCESSIBLE_COLUMNS, "false")); + sessionPropertyManager.validateSystemSessionProperty(SystemSessionProperties.HIDE_INACCESSIBLE_COLUMNS, "false"); } @Test @@ -62,7 +61,7 @@ public void testEnableWhenDisabledByDefault() { FeaturesConfig featuresConfig = new FeaturesConfig(); SessionPropertyManager sessionPropertyManager = createSessionPropertyManager(featuresConfig); - assertThatNoException().isThrownBy(() -> sessionPropertyManager.validateSystemSessionProperty(SystemSessionProperties.HIDE_INACCESSIBLE_COLUMNS, "true")); + sessionPropertyManager.validateSystemSessionProperty(SystemSessionProperties.HIDE_INACCESSIBLE_COLUMNS, "true"); } private SessionPropertyManager createSessionPropertyManager(FeaturesConfig featuresConfig) diff --git a/lib/trino-filesystem-gcs/src/test/java/io/trino/filesystem/gcs/TestGcsFileSystemGcs.java b/lib/trino-filesystem-gcs/src/test/java/io/trino/filesystem/gcs/TestGcsFileSystemGcs.java index 00f08df91377..f984c5d6e1bf 100644 --- a/lib/trino-filesystem-gcs/src/test/java/io/trino/filesystem/gcs/TestGcsFileSystemGcs.java +++ b/lib/trino-filesystem-gcs/src/test/java/io/trino/filesystem/gcs/TestGcsFileSystemGcs.java @@ -22,7 +22,6 @@ import java.io.OutputStream; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.assertj.core.api.Assertions.assertThatNoException; @TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestGcsFileSystemGcs @@ -37,17 +36,17 @@ void setup() @Test void testCreateFileRetry() + throws Exception { // Note: this test is meant to expose flakiness // Without retries it may fail non-deterministically. // Retries are enabled in the default GcsFileSystemConfig. // In practice this may happen between 7 and 20 retries. - assertThatNoException().isThrownBy(() -> { - for (int i = 1; i <= 30; i++) { - TrinoOutputFile outputFile = getFileSystem().newOutputFile(getRootLocation().appendPath("testFile")); - try (OutputStream out = outputFile.createOrOverwrite()) { - out.write("test".getBytes(UTF_8)); - } - }}); + for (int i = 1; i <= 30; i++) { + TrinoOutputFile outputFile = getFileSystem().newOutputFile(getRootLocation().appendPath("testFile")); + try (OutputStream out = outputFile.createOrOverwrite()) { + out.write("test".getBytes(UTF_8)); + } + } } } diff --git a/testing/trino-product-tests-launcher/src/test/java/io/trino/tests/product/launcher/local/TestManuallyJdbcOauth2.java b/testing/trino-product-tests-launcher/src/test/java/io/trino/tests/product/launcher/local/TestManuallyJdbcOauth2.java index ffd092f1a8a6..1c01dd118ce7 100644 --- a/testing/trino-product-tests-launcher/src/test/java/io/trino/tests/product/launcher/local/TestManuallyJdbcOauth2.java +++ b/testing/trino-product-tests-launcher/src/test/java/io/trino/tests/product/launcher/local/TestManuallyJdbcOauth2.java @@ -18,7 +18,6 @@ import java.net.InetAddress; import java.net.Socket; -import java.net.UnknownHostException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -27,20 +26,18 @@ import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatNoException; public class TestManuallyJdbcOauth2 { private static void verifyEtcHostsEntries() - throws UnknownHostException + throws Exception { assertThat(InetAddress.getByName("presto-master").isLoopbackAddress()).isTrue(); assertThat(InetAddress.getByName("hydra").isLoopbackAddress()).isTrue(); assertThat(InetAddress.getByName("hydra-consent").isLoopbackAddress()).isTrue(); - assertThatNoException() - .describedAs("Trino server is not available under 7778 port") - .isThrownBy(() -> new Socket("presto-master", 7778).close()); + // Trino server should be available under 7778 port + new Socket("presto-master", 7778).close(); } /** diff --git a/testing/trino-testing-services/src/test/java/io/trino/testng/services/TestReportAfterMethodNotAlwaysRun.java b/testing/trino-testing-services/src/test/java/io/trino/testng/services/TestReportAfterMethodNotAlwaysRun.java index 6ec8095c7db1..2c65c21d24d3 100644 --- a/testing/trino-testing-services/src/test/java/io/trino/testng/services/TestReportAfterMethodNotAlwaysRun.java +++ b/testing/trino-testing-services/src/test/java/io/trino/testng/services/TestReportAfterMethodNotAlwaysRun.java @@ -20,7 +20,6 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.assertThatThrownBy; public class TestReportAfterMethodNotAlwaysRun @@ -28,7 +27,7 @@ public class TestReportAfterMethodNotAlwaysRun @Test(dataProvider = "correctCases") public void testCorrectCases(Class testClass) { - assertThatNoException().isThrownBy(() -> ReportAfterMethodNotAlwaysRun.checkHasAfterMethodsNotAlwaysRun(testClass)); + ReportAfterMethodNotAlwaysRun.checkHasAfterMethodsNotAlwaysRun(testClass); } @DataProvider