Skip to content

Commit

Permalink
Remove redundant lambdas from test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
findepi committed Feb 26, 2024
1 parent d0e16c6 commit 786cacd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,23 +45,23 @@ 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
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
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
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
{
@Test(dataProvider = "correctCases")
public void testCorrectCases(Class<?> testClass)
{
assertThatNoException().isThrownBy(() -> ReportAfterMethodNotAlwaysRun.checkHasAfterMethodsNotAlwaysRun(testClass));
ReportAfterMethodNotAlwaysRun.checkHasAfterMethodsNotAlwaysRun(testClass);
}

@DataProvider
Expand Down

0 comments on commit 786cacd

Please sign in to comment.