Skip to content

Commit

Permalink
Rewrite TestNG Assertions to AssertJ
Browse files Browse the repository at this point in the history
Changed automatically by openrewrite recipe
openrewrite/rewrite-testing-frameworks#520
```
<plugin>
    <groupId>org.openrewrite.maven</groupId>
    <artifactId>rewrite-maven-plugin</artifactId>
    <version>5.32.0</version>
    <configuration>
        <activeRecipes>
            <recipe>org.openrewrite.java.testing.assertj.TestNgToAssertj</recipe>
        </activeRecipes>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.openrewrite.recipe</groupId>
            <artifactId>rewrite-testing-frameworks</artifactId>
            <version>2.11.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</plugin>
```

run
```
./mvnw rewrite:run -Dmaven.javadoc.skip=true -DskipTests=true -Dmaven.site.skip=true -Dmaven.artifact.threads=16 -T 1C -e -Dair.check.skip-all=true --no-snapshot-updates -pl '!:trino-server-rpm'
```

Some formatting was fixed manually for readability.

Then, rewrite remaining TestNG Assertions to AssertJ manually, because
some entries were not migrated by `./mvnw rewrite:run`.
  • Loading branch information
ssheikin committed Jun 6, 2024
1 parent f946a79 commit ed4c0dd
Show file tree
Hide file tree
Showing 22 changed files with 103 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
import static org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;

@TestInstance(PER_CLASS)
@Execution(SAME_THREAD)
Expand Down Expand Up @@ -108,13 +106,13 @@ public void testStatementWarnings()
Statement statement = connection.createStatement()) {
assertThat(statement.execute("CREATE SCHEMA blackhole.test_schema")).isFalse();
SQLWarning warning = statement.getWarnings();
assertNotNull(warning);
assertThat((Object) warning).isNotNull();
TestingWarningCollectorConfig warningCollectorConfig = new TestingWarningCollectorConfig().setPreloadedWarnings(PRELOADED_WARNINGS);
TestingWarningCollector warningCollector = new TestingWarningCollector(new WarningCollectorConfig(), warningCollectorConfig);
List<TrinoWarning> expectedWarnings = warningCollector.getWarnings();
assertStartsWithExpectedWarnings(warning, fromTrinoWarnings(expectedWarnings));
statement.clearWarnings();
assertNull(statement.getWarnings());
assertThat((Object) statement.getWarnings()).isNull();
}
}

Expand Down Expand Up @@ -157,7 +155,7 @@ public void testExecuteQueryWarnings()
try (Connection connection = createConnection();
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("SELECT a FROM (VALUES 1, 2, 3) t(a)")) {
assertNull(statement.getConnection().getWarnings());
assertThat((Object) statement.getConnection().getWarnings()).isNull();
Set<WarningEntry> currentWarnings = new HashSet<>();
assertWarnings(rs.getWarnings(), currentWarnings);
while (rs.next()) {
Expand Down Expand Up @@ -288,16 +286,16 @@ private static void assertWarnings(SQLWarning warning, Set<WarningEntry> current

private static void assertStartsWithExpectedWarnings(SQLWarning warning, SQLWarning expected)
{
assertNotNull(expected);
assertNotNull(warning);
assertThat((Object) expected).isNotNull();
assertThat((Object) warning).isNotNull();
while (true) {
assertWarningsEqual(warning, expected);
warning = warning.getNextWarning();
expected = expected.getNextWarning();
if (expected == null) {
return;
}
assertNotNull(warning);
assertThat((Object) warning).isNotNull();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import static io.trino.spi.type.RealType.REAL;
import static io.trino.testing.TestingConnectorSession.SESSION;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.assertEquals;

public class TestByteStreamSplitEncoding
{
Expand Down Expand Up @@ -89,10 +88,10 @@ private static void readAndCompare(ParquetReader reader, List<List<Double>> expe
List<Double> expectedValues = expected.get(channel);
for (int postition = 0; postition < block.getPositionCount(); postition++) {
if (block instanceof IntArrayBlock) {
assertEquals(REAL.getObjectValue(SESSION, block, postition), expectedValues.get(rowCount + postition).floatValue());
assertThat(REAL.getObjectValue(SESSION, block, postition)).isEqualTo(expectedValues.get(rowCount + postition).floatValue());
}
else {
assertEquals(DOUBLE.getObjectValue(SESSION, block, postition), expectedValues.get(rowCount + postition));
assertThat(DOUBLE.getObjectValue(SESSION, block, postition)).isEqualTo(expectedValues.get(rowCount + postition));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static io.trino.tests.product.TestGroups.FUNCTIONS;
import static io.trino.tests.product.utils.QueryExecutors.onTrino;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.assertEquals;

public class TestFunctions
extends ProductTest
Expand All @@ -41,8 +40,7 @@ public void testPosition()
@Test(groups = FUNCTIONS)
public void testVersion()
{
assertEquals(
onTrino().executeQuery("SELECT version()").getOnlyValue(),
onTrino().executeQuery("SELECT node_version FROM system.runtime.nodes WHERE coordinator = TRUE").getOnlyValue());
assertThat(onTrino().executeQuery("SELECT version()").getOnlyValue())
.isEqualTo(onTrino().executeQuery("SELECT node_version FROM system.runtime.nodes WHERE coordinator = TRUE").getOnlyValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import static io.trino.tests.product.utils.QueryExecutors.connectToTrino;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.assertEquals;

public class TestImpersonation
extends ProductTest
Expand Down Expand Up @@ -90,7 +89,7 @@ public void testExternalLocationTableCreationFailure()
String tableLocationBob = commonExternalLocationPath + "/bob_table";
bobExecutor.executeQuery(format("CREATE TABLE %s (a bigint) WITH (external_location = '%s')", tableNameBob, tableLocationBob));
String owner = hdfsClient.getOwner(commonExternalLocationPath);
assertEquals(owner, bobJdbcUser);
assertThat(owner).isEqualTo(bobJdbcUser);

String tableNameAlice = "alice_external_table" + randomNameSuffix();
String tableLocationAlice = commonExternalLocationPath + "/alice_table";
Expand All @@ -110,14 +109,14 @@ public void testExternalLocationTableCreationSuccess()
String tableLocationBob = commonExternalLocationPath + "/bob_table";
bobExecutor.executeQuery(format("CREATE TABLE %s (a bigint) WITH (external_location = '%s')", tableNameBob, tableLocationBob));
String owner = hdfsClient.getOwner(tableLocationBob);
assertEquals(owner, configuredHdfsUser);
assertThat(owner).isEqualTo(configuredHdfsUser);

String tableNameAlice = "alice_external_table" + randomNameSuffix();
String tableLocationAlice = commonExternalLocationPath + "/alice_table";
aliceExecutor.executeQuery(format("CREATE TABLE %s (a bigint) WITH (external_location = '%s')", tableNameAlice, tableLocationAlice));
assertThat(aliceExecutor.executeQuery(format("SELECT * FROM %s", tableNameAlice))).hasRowsCount(0);
owner = hdfsClient.getOwner(tableLocationAlice);
assertEquals(owner, configuredHdfsUser);
assertThat(owner).isEqualTo(configuredHdfsUser);

bobExecutor.executeQuery(format("DROP TABLE IF EXISTS %s", tableNameBob));
aliceExecutor.executeQuery(format("DROP TABLE IF EXISTS %s", tableNameAlice));
Expand Down Expand Up @@ -155,7 +154,7 @@ private void checkTableOwner(String tableName, String expectedOwner, QueryExecut
executor.executeQuery(format("CREATE TABLE %s AS SELECT 'abc' c", tableName));
String tableLocation = getTableLocation(executor, tableName);
String owner = hdfsClient.getOwner(tableLocation);
assertEquals(owner, expectedOwner);
assertThat(owner).isEqualTo(expectedOwner);
executor.executeQuery(format("DROP TABLE IF EXISTS %s", tableName));
}

Expand All @@ -171,6 +170,6 @@ private void checkTableGroup(String tableName, QueryExecutor executor)
// user alice doesn't have permission to setOwner, so the user group info should be alice:supergroup still
String warehouseLocationGroup = hdfsClient.getGroup(warehouseLocation);
String tableLocationGroup = hdfsClient.getGroup(warehouseLocation);
assertEquals(tableLocationGroup, warehouseLocationGroup);
assertThat(tableLocationGroup).isEqualTo(warehouseLocationGroup);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.testng.Assert.assertTrue;

public class TestTrinoCli
extends TrinoCliLauncher
Expand Down Expand Up @@ -185,7 +184,7 @@ public void shouldExecuteEmptyListOfStatements()
throws Exception
{
launchTrinoCliWithServerArgument("--execute", "");
assertTrue(trimLines(trino.readRemainingOutputLines()).isEmpty());
assertThat(trimLines(trino.readRemainingOutputLines()).isEmpty()).isTrue();
trino.waitForWithTimeoutAndKill();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static io.trino.tests.product.utils.QueryExecutors.onTrino;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.assertEquals;

public class TestDeltaLakeAlluxioCaching
extends ProductTest
Expand Down Expand Up @@ -72,8 +71,8 @@ private void testReadFromTable(String tableNameSuffix)
// query via caching catalog should read exclusively from cache
CacheStats afterQueryCacheStats = getCacheStats("delta");
assertGreaterThan(afterQueryCacheStats.cacheReads(), beforeQueryCacheStats.cacheReads());
assertEquals(afterQueryCacheStats.externalReads(), beforeQueryCacheStats.externalReads());
assertEquals(afterQueryCacheStats.cacheSpaceUsed(), beforeQueryCacheStats.cacheSpaceUsed());
assertThat(afterQueryCacheStats.externalReads()).isEqualTo(beforeQueryCacheStats.externalReads());
assertThat(afterQueryCacheStats.cacheSpaceUsed()).isEqualTo(beforeQueryCacheStats.cacheSpaceUsed());
});

onTrino().executeQuery("DROP TABLE " + nonCachedTableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import static io.trino.tests.product.utils.QueryExecutors.onTrino;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.assertEquals;

public class TestDeltaLakeAlterTableCompatibility
extends BaseTestDeltaLakeS3Storage
Expand All @@ -61,8 +60,8 @@ public void testAddColumnWithCommentOnTrino()

try {
onTrino().executeQuery("ALTER TABLE delta.default." + tableName + " ADD COLUMN new_col INT COMMENT 'new column comment'");
assertEquals(getColumnCommentOnTrino("default", tableName, "new_col"), "new column comment");
assertEquals(getColumnCommentOnDelta("default", tableName, "new_col"), "new column comment");
assertThat(getColumnCommentOnTrino("default", tableName, "new_col")).isEqualTo("new column comment");
assertThat(getColumnCommentOnDelta("default", tableName, "new_col")).isEqualTo("new column comment");
}
finally {
onTrino().executeQuery("DROP TABLE delta.default." + tableName);
Expand Down Expand Up @@ -209,8 +208,8 @@ public void testCommentOnTable()

try {
onTrino().executeQuery("COMMENT ON TABLE delta.default." + tableName + " IS 'test comment'");
assertEquals(getTableCommentOnTrino("default", tableName), "test comment");
assertEquals(getTableCommentOnDelta("default", tableName), "test comment");
assertThat(getTableCommentOnTrino("default", tableName)).isEqualTo("test comment");
assertThat(getTableCommentOnDelta("default", tableName)).isEqualTo("test comment");
}
finally {
onTrino().executeQuery("DROP TABLE delta.default." + tableName);
Expand Down Expand Up @@ -255,8 +254,8 @@ public void testCommentOnColumn()

try {
onTrino().executeQuery("COMMENT ON COLUMN delta.default." + tableName + ".col IS 'test column comment'");
assertEquals(getColumnCommentOnTrino("default", tableName, "col"), "test column comment");
assertEquals(getColumnCommentOnDelta("default", tableName, "col"), "test column comment");
assertThat(getColumnCommentOnTrino("default", tableName, "col")).isEqualTo("test column comment");
assertThat(getColumnCommentOnDelta("default", tableName, "col")).isEqualTo("test column comment");
}
finally {
onTrino().executeQuery("DROP TABLE delta.default." + tableName);
Expand Down Expand Up @@ -360,7 +359,7 @@ public void testTrinoAlterTablePreservesChangeDataFeed()
onTrino().executeQuery("ALTER TABLE delta.default." + tableName + " ADD COLUMN new_column INT");

Object enableChangeDataFeed = getOnlyElement(onDelta().executeQuery("SHOW TBLPROPERTIES " + tableName + "(delta.enableChangeDataFeed)").column(2));
assertEquals(enableChangeDataFeed, "true");
assertThat(enableChangeDataFeed).isEqualTo("true");
}
finally {
onTrino().executeQuery("DROP TABLE delta.default." + tableName);
Expand Down Expand Up @@ -390,9 +389,9 @@ public void testTrinoPreservesReaderAndWriterVersions()
onTrino().executeQuery("MERGE INTO delta.default." + tableName + " t USING delta.default." + tableName + " s " + "ON (t.col = s.col) WHEN MATCHED THEN UPDATE SET new_col = 3");

List<?> minReaderVersion = getOnlyElement(onDelta().executeQuery("SHOW TBLPROPERTIES " + tableName + "(delta.minReaderVersion)").rows());
assertEquals((String) minReaderVersion.get(1), "1");
assertThat((String) minReaderVersion.get(1)).isEqualTo("1");
List<?> minWriterVersion = getOnlyElement(onDelta().executeQuery("SHOW TBLPROPERTIES " + tableName + "(delta.minWriterVersion)").rows());
assertEquals((String) minWriterVersion.get(1), "1");
assertThat((String) minWriterVersion.get(1)).isEqualTo("1");
}
finally {
onTrino().executeQuery("DROP TABLE delta.default." + tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import static io.trino.tests.product.utils.QueryExecutors.onTrino;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.testng.Assert.assertEquals;

public class TestDeltaLakeCaseInsensitiveMapping
extends BaseTestDeltaLakeS3Storage
Expand Down Expand Up @@ -122,13 +121,13 @@ public void testColumnCommentWithNonLowerCaseColumnName()
"LOCATION 's3://" + bucketName + "/databricks-compatibility-test-" + tableName + "'");

try {
assertEquals(getColumnCommentOnTrino("default", tableName, "upper_case"), "test column comment");
assertEquals(getColumnCommentOnDelta("default", tableName, "UPPER_CASE"), "test column comment");
assertThat(getColumnCommentOnTrino("default", tableName, "upper_case")).isEqualTo("test column comment");
assertThat(getColumnCommentOnDelta("default", tableName, "UPPER_CASE")).isEqualTo("test column comment");

onTrino().executeQuery("COMMENT ON COLUMN delta.default." + tableName + ".upper_case IS 'test updated comment'");

assertEquals(getColumnCommentOnTrino("default", tableName, "upper_case"), "test updated comment");
assertEquals(getColumnCommentOnDelta("default", tableName, "UPPER_CASE"), "test updated comment");
assertThat(getColumnCommentOnTrino("default", tableName, "upper_case")).isEqualTo("test updated comment");
assertThat(getColumnCommentOnDelta("default", tableName, "UPPER_CASE")).isEqualTo("test updated comment");
}
finally {
dropDeltaTableWithRetry("default." + tableName);
Expand Down
Loading

0 comments on commit ed4c0dd

Please sign in to comment.