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.
  • Loading branch information
ssheikin committed Jun 6, 2024
1 parent 6ee9fe5 commit 14f31de
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 100 deletions.
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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.entry;
import static org.testng.Assert.assertEquals;

public class TestDeltaLakeColumnMappingMode
extends BaseTestDeltaLakeS3Storage
Expand Down Expand Up @@ -350,8 +349,8 @@ public void testColumnMappingModeNameWithNonLowerCaseColumn()

// Verify column comments
onTrino().executeQuery("COMMENT ON COLUMN delta.default." + tableName + ".mixed_case IS 'test column comment'");
assertEquals(getColumnCommentOnTrino("default", tableName, "mixed_case"), "test column comment");
assertEquals(getColumnCommentOnDelta("default", tableName, "mixed_case"), "test column comment");
assertThat(getColumnCommentOnTrino("default", tableName, "mixed_case")).isEqualTo("test column comment");
assertThat(getColumnCommentOnDelta("default", tableName, "mixed_case")).isEqualTo("test column comment");
}
finally {
dropDeltaTableWithRetry("default." + tableName);
Expand Down Expand Up @@ -394,11 +393,11 @@ public void testCreateTableWithCommentsColumnMappingModeName()
" column_mapping_mode = 'name'" +
")");
try {
assertEquals(getTableCommentOnTrino("default", tableName), "test table comment");
assertEquals(getTableCommentOnDelta("default", tableName), "test table comment");
assertThat(getTableCommentOnTrino("default", tableName)).isEqualTo("test table comment");
assertThat(getTableCommentOnDelta("default", tableName)).isEqualTo("test table 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 All @@ -420,12 +419,12 @@ public void testColumnMappingModeNameCommentOnTable()
")");
try {
onTrino().executeQuery("COMMENT ON TABLE delta.default." + tableName + " IS 'test comment by trino'");
assertEquals(getTableCommentOnTrino("default", tableName), "test comment by trino");
assertEquals(getTableCommentOnDelta("default", tableName), "test comment by trino");
assertThat(getTableCommentOnTrino("default", tableName)).isEqualTo("test comment by trino");
assertThat(getTableCommentOnDelta("default", tableName)).isEqualTo("test comment by trino");

onDelta().executeQuery("COMMENT ON TABLE default." + tableName + " IS 'test comment by delta'");
assertEquals(getTableCommentOnTrino("default", tableName), "test comment by delta");
assertEquals(getTableCommentOnDelta("default", tableName), "test comment by delta");
assertThat(getTableCommentOnTrino("default", tableName)).isEqualTo("test comment by delta");
assertThat(getTableCommentOnDelta("default", tableName)).isEqualTo("test comment by delta");
}
finally {
dropDeltaTableWithRetry("default." + tableName);
Expand All @@ -447,12 +446,12 @@ public void testColumnMappingModeNameCommentOnColumn()

try {
onTrino().executeQuery("COMMENT ON COLUMN delta.default." + tableName + ".col IS 'test column comment by trino'");
assertEquals(getColumnCommentOnTrino("default", tableName, "col"), "test column comment by trino");
assertEquals(getColumnCommentOnDelta("default", tableName, "col"), "test column comment by trino");
assertThat(getColumnCommentOnTrino("default", tableName, "col")).isEqualTo("test column comment by trino");
assertThat(getColumnCommentOnDelta("default", tableName, "col")).isEqualTo("test column comment by trino");

onDelta().executeQuery("ALTER TABLE default." + tableName + " ALTER COLUMN col COMMENT 'test column comment by delta'");
assertEquals(getColumnCommentOnTrino("default", tableName, "col"), "test column comment by delta");
assertEquals(getColumnCommentOnDelta("default", tableName, "col"), "test column comment by delta");
assertThat(getColumnCommentOnTrino("default", tableName, "col")).isEqualTo("test column comment by delta");
assertThat(getColumnCommentOnDelta("default", tableName, "col")).isEqualTo("test column comment by delta");
}
finally {
dropDeltaTableWithRetry("default." + tableName);
Expand Down Expand Up @@ -1188,7 +1187,7 @@ public void testRenameNonLowercaseColumn(String mode)
onTrino().executeQuery("ALTER TABLE delta.default." + tableName + " RENAME COLUMN upper_col TO new_col");
assertThat(getColumnNamesOnDelta("default", tableName))
.containsExactly("new_col", "UPPER_PART");
assertEquals(getColumnCommentOnDelta("default", tableName, "new_col"), "test comment");
assertThat(getColumnCommentOnDelta("default", tableName, "new_col")).isEqualTo("test comment");
assertQueryFailure(() -> onTrino().executeQuery("INSERT INTO delta.default." + tableName + " (new_col) VALUES NULL"))
.hasMessageContaining("NULL value not allowed for NOT NULL column: new_col");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
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.assertEquals;

public class TestDeltaLakeDatabricksCreateTableCompatibility
extends BaseTestDeltaLakeS3Storage
Expand Down Expand Up @@ -258,8 +257,8 @@ public void testCreateTableWithTableComment()
tableDirectory));

try {
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 All @@ -279,13 +278,13 @@ public void testCreateTableWithColumnCommentOnTrino()
tableDirectory));

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

// Verify that adding a new column doesn't remove existing column comments
onTrino().executeQuery("ALTER TABLE delta.default." + tableName + " ADD COLUMN new_col INT");
assertEquals(getColumnCommentOnTrino("default", tableName, "col"), "test comment");
assertEquals(getColumnCommentOnDelta("default", tableName, "col"), "test comment");
assertThat(getColumnCommentOnTrino("default", tableName, "col")).isEqualTo("test comment");
assertThat(getColumnCommentOnDelta("default", tableName, "col")).isEqualTo("test comment");
}
finally {
onTrino().executeQuery("DROP TABLE delta.default." + tableName);
Expand All @@ -305,7 +304,7 @@ public void testCreateTableWithColumnCommentOnDelta()
tableDirectory));

try {
assertEquals(getColumnCommentOnTrino("default", tableName, "col"), "test comment");
assertThat(getColumnCommentOnTrino("default", tableName, "col")).isEqualTo("test comment");
}
finally {
dropDeltaTableWithRetry("default." + tableName);
Expand Down
Loading

0 comments on commit 14f31de

Please sign in to comment.