Skip to content

Commit

Permalink
Use assertEquals instead of assertTrue when testing equality
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo committed Aug 14, 2024
1 parent c624968 commit 78a8d18
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import static com.facebook.presto.testing.TestingConnectorSession.SESSION;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

public class TestBlackHoleMetadata
Expand Down Expand Up @@ -68,8 +67,8 @@ public void tableIsCreatedAfterCommits()
metadata.finishCreateTable(SESSION, table, ImmutableList.of(), ImmutableList.of());

List<SchemaTableName> tables = metadata.listTables(SESSION, Optional.empty());
assertTrue(tables.size() == 1, "Expected only one table.");
assertTrue(tables.get(0).getTableName().equals("temp_table"), "Expected table with name 'temp_table'");
assertEquals(tables.size(), 1, "Expected only one table.");
assertEquals(tables.get(0).getTableName(), "temp_table", "Expected table with name 'temp_table'");
}

@Test
Expand All @@ -82,7 +81,7 @@ public void testCreateTableInNotExistSchema()
}
catch (PrestoException ex) {
assertEquals(ex.getErrorCode(), NOT_FOUND.toErrorCode());
assertTrue(ex.getMessage().equals("Schema schema1 not found"));
assertEquals(ex.getMessage(), "Schema schema1 not found");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void testComparisons()
// of their indexes.
for (int i = 0; i < markers.size(); i++) {
for (int j = 0; j < markers.size(); j++) {
assertTrue(markers.get(i).compareTo(markers.get(j)) == Integer.compare(i, j));
assertEquals(markers.get(i).compareTo(markers.get(j)), Integer.compare(i, j));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void testCommitOutputForPartitions()

assertEquals(handle.getSerializedCommitOutputForRead(new SchemaTableName(TEST_SCHEMA, TEST_TABLE)), "");
assertFalse(handle.getSerializedCommitOutputForWrite(new SchemaTableName(TEST_SCHEMA, TEST_TABLE)).isEmpty());
assertTrue(handle.getSerializedCommitOutputForWrite(new SchemaTableName(TEST_SCHEMA, TEST_TABLE)).equals(serializedCommitOutput));
assertEquals(handle.getSerializedCommitOutputForWrite(new SchemaTableName(TEST_SCHEMA, TEST_TABLE)), serializedCommitOutput);
}

private HiveMetadata getHiveMetadata(TestingExtendedHiveMetastore metastore, HiveClientConfig hiveClientConfig, ListeningExecutorService listeningExecutor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2927,7 +2927,7 @@ else if (columnMetadata.getName().equals(ROW_ID_COLUMN_NAME)) {
int bucket = (int) row.getField(2);

assertEquals(col1, col0 + 11);
assertTrue(col1 % 2 == 0);
assertEquals(col1 % 2, 0);

// Because Hive's hash function for integer n is h(n) = n.
assertEquals(bucket, col0 % 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static com.facebook.presto.iceberg.IcebergSessionProperties.PUSHDOWN_FILTER_ENABLED;
import static com.facebook.presto.spi.connector.NotPartitionedPartitionHandle.NOT_PARTITIONED;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

Expand Down Expand Up @@ -180,7 +181,8 @@ private void validateSplitsPlannedForSql(SplitManager splitManager,
{
Session session = sessionWithFilterPushdown(filterPushdown);
List<TableScanNode> tableScanNodes = getTableScanFromOptimizedPlanOfSql(sql, session);
assertTrue(tableScanNodes != null && tableScanNodes.size() == 1);
assertNotNull(tableScanNodes);
assertEquals(tableScanNodes.size(), 1);

TransactionId transactionId = transactionManager.beginTransaction(false);
session = session.beginTransactionId(transactionId, transactionManager, new AllowAllAccessControl());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testIndexedPriorityQueue()
@Test
public void testStochasticPriorityQueue()
{
assertTrue(populateAndExtract(new StochasticPriorityQueue<>()).size() == 3);
assertEquals(populateAndExtract(new StochasticPriorityQueue<>()).size(), 3);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static GroupByHashYieldResult finishOperatorWithYieldingGroupByHash(List<
assertTrue(operator.getOperatorContext().isWaitingForMemory().isDone());

// assert the hash capacity is not changed; otherwise, we should have yielded
assertTrue(oldCapacity == getHashCapacity.apply(operator));
assertEquals(oldCapacity, getHashCapacity.apply(operator));

// We are not going to rehash; therefore, assert the memory increase only comes from the aggregator
assertLessThan(actualIncreasedMemory, additionalMemoryInBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void testBufferLimit()
// wait for client to decide there are no more pages
assertNull(getNextPage(exchangeClient));
assertEquals(exchangeClient.getStatus().getBufferedPages(), 0);
assertTrue(exchangeClient.getStatus().getBufferedBytes() == 0);
assertEquals(exchangeClient.getStatus().getBufferedBytes(), 0);
assertTrue(exchangeClient.isClosed());
assertStatus(exchangeClient.getStatus().getPageBufferClientStatuses().get(0), location, "closed", 3, 5, 5, "not scheduled");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void testNull()
Accumulator accumulator = factory.createAccumulator(UpdateMemory.NOOP);
Block result = getFinalBlock(accumulator);

assertTrue(result.getPositionCount() == 1);
assertEquals(result.getPositionCount(), 1);
assertTrue(result.isNull(0));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void testNull()
Accumulator accumulator = factory.createAccumulator(UpdateMemory.NOOP);
Block result = getFinalBlock(accumulator);

assertTrue(result.getPositionCount() == 1);
assertEquals(result.getPositionCount(), 1);
assertTrue(result.isNull(0));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public void assertFunctionDoubleArrayWithError(String projection, Type expectedT
Object actual = selectSingleValue(projection, expectedType, compiler);
assertTrue(actual instanceof ArrayList);
ArrayList<Object> arrayList = (ArrayList) actual;
assertTrue(arrayList.size() == expected.size());
assertEquals(arrayList.size(), expected.size());
for (int i = 0; i < arrayList.size(); ++i) {
assertEquals((double) arrayList.get(i), expected.get(i), delta);
}
Expand All @@ -295,7 +295,7 @@ public void assertFunctionFloatArrayWithError(String projection, Type expectedTy
Object actual = selectSingleValue(projection, expectedType, compiler);
assertTrue(actual instanceof ArrayList);
ArrayList<Object> arrayList = (ArrayList) actual;
assertTrue(arrayList.size() == expected.size());
assertEquals(arrayList.size(), expected.size());
for (int i = 0; i < arrayList.size(); ++i) {
assertEquals((float) arrayList.get(i), expected.get(i), delta);
}
Expand Down Expand Up @@ -350,7 +350,7 @@ private Object selectUniqueValue(String projection, Type expectedType, Session s
HashSet<Object> resultSet = new HashSet<>(results);

// we should only have a single result
assertTrue(resultSet.size() == 1, "Expected only one result unique result, but got " + resultSet);
assertEquals(resultSet.size(), 1, "Expected only one result unique result, but got " + resultSet);

return Iterables.getOnlyElement(resultSet);
}
Expand Down Expand Up @@ -733,7 +733,7 @@ private void assertFilter(String filter, boolean expected, boolean withNoInputCo
HashSet<Boolean> resultSet = new HashSet<>(results);

// we should only have a single result
assertTrue(resultSet.size() == 1, "Expected only [" + expected + "] result unique result, but got " + resultSet);
assertEquals(resultSet.size(), 1, "Expected only [" + expected + "] result unique result, but got " + resultSet);

assertEquals((boolean) Iterables.getOnlyElement(resultSet), expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ private void assertPositionValue(Block block, int position, Object expectedStack
assertEquals(block.isNull(position), expectedStackValue == null);

if (type.isOrderable()) {
assertTrue(ASC_NULLS_FIRST.compareBlockValue(type, block, position, expectedBlock, 0) == 0);
assertTrue(ASC_NULLS_LAST.compareBlockValue(type, block, position, expectedBlock, 0) == 0);
assertTrue(DESC_NULLS_FIRST.compareBlockValue(type, block, position, expectedBlock, 0) == 0);
assertTrue(DESC_NULLS_LAST.compareBlockValue(type, block, position, expectedBlock, 0) == 0);
assertEquals(ASC_NULLS_FIRST.compareBlockValue(type, block, position, expectedBlock, 0), 0);
assertEquals(ASC_NULLS_LAST.compareBlockValue(type, block, position, expectedBlock, 0), 0);
assertEquals(DESC_NULLS_FIRST.compareBlockValue(type, block, position, expectedBlock, 0), 0);
assertEquals(DESC_NULLS_LAST.compareBlockValue(type, block, position, expectedBlock, 0), 0);
}
else {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
import static java.util.Collections.nCopies;
import static java.util.Collections.singletonList;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

public class TestArrayOperators
Expand Down Expand Up @@ -852,7 +851,7 @@ public void testSubscript()
fail("Access to array with double subscript should fail");
}
catch (SemanticException e) {
assertTrue(e.getCode() == TYPE_MISMATCH);
assertEquals(e.getCode(), TYPE_MISMATCH);
}

assertFunction("ARRAY[NULL][1]", UNKNOWN, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ private NodeState getNodeState(URI uri, boolean useThriftEncoding, Protocol thri
return client.execute(request, new ThriftResponseHandler<>(thriftCodeManager.getCodec(NodeState.class))).getValue();
}
else {
requestBuilder = getJsonTransportBuilder(prepareGet());
return client.execute(request, createJsonResponseHandler(jsonCodec(NodeState.class)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void createTableWhenTableIsAlreadyCreated()
fail("Expected exception to be thrown here!");
}
catch (RuntimeException ex) { // it has to RuntimeException as FailureInfo$FailureException is private
assertTrue(ex.getMessage().equals("line 1:1: Destination table 'blackhole.default.nation' already exists"));
assertEquals(ex.getMessage(), "line 1:1: Destination table 'blackhole.default.nation' already exists");
}
finally {
assertThatQueryReturnsValue("DROP TABLE nation", true);
Expand All @@ -102,8 +102,8 @@ public void blackHoleConnectorUsage()
assertThatQueryReturnsValue("CREATE TABLE nation as SELECT * FROM tpch.tiny.nation", 25L);

List<QualifiedObjectName> tableNames = listBlackHoleTables();
assertTrue(tableNames.size() == 1, "Expected only one table.");
assertTrue(tableNames.get(0).getObjectName().equals("nation"), "Expected 'nation' table.");
assertEquals(tableNames.size(), 1, "Expected only one table.");
assertEquals(tableNames.get(0).getObjectName(), "nation", "Expected 'nation' table.");

assertThatQueryReturnsValue("INSERT INTO nation SELECT * FROM tpch.tiny.nation", 25L);

Expand Down Expand Up @@ -156,7 +156,7 @@ public void testCreateTableInNotExistSchema()
fail("Expected exception to be thrown here!");
}
catch (RuntimeException ex) {
assertTrue(ex.getMessage().equals("Schema schema1 not found"));
assertEquals(ex.getMessage(), "Schema schema1 not found");
}

int tablesAfterCreate = listBlackHoleTables().size();
Expand Down Expand Up @@ -344,7 +344,7 @@ public void pageProcessingDelay()

private void assertThatNoBlackHoleTableIsCreated()
{
assertTrue(listBlackHoleTables().size() == 0, "No blackhole tables expected");
assertTrue(listBlackHoleTables().isEmpty(), "No blackhole tables expected");
}

private List<QualifiedObjectName> listBlackHoleTables()
Expand All @@ -362,9 +362,9 @@ private void assertThatQueryReturnsValue(String sql, Object expected, Session se
MaterializedResult rows = session == null ? queryRunner.execute(sql) : queryRunner.execute(session, sql);
MaterializedRow materializedRow = Iterables.getOnlyElement(rows);
int fieldCount = materializedRow.getFieldCount();
assertTrue(fieldCount == 1, format("Expected only one column, but got '%d'", fieldCount));
assertEquals(fieldCount, 1, format("Expected only one column, but got '%d'", fieldCount));
Object value = materializedRow.getField(0);
assertEquals(value, expected);
assertTrue(Iterables.getOnlyElement(rows).getFieldCount() == 1);
assertEquals(Iterables.getOnlyElement(rows).getFieldCount(), 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import static java.util.concurrent.Executors.newCachedThreadPool;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

public class TestServerInfoResource
{
Expand Down Expand Up @@ -70,7 +69,7 @@ public void testServerActive()

ServerInfoResource serverInfoResource = coordinator.getServerInfoResource();
NodeState nodeState = serverInfoResource.getServerState();
assertTrue(nodeState == NodeState.ACTIVE);
assertEquals(nodeState, NodeState.ACTIVE);
}
}

Expand All @@ -89,11 +88,11 @@ public void testServerInactiveThenActive()
Response response = serverInfoResource.updateState(NodeState.INACTIVE);
assertEquals(response.getStatus(), 200);
NodeState nodeState = serverInfoResource.getServerState();
assertTrue(nodeState == NodeState.INACTIVE);
assertEquals(nodeState, NodeState.INACTIVE);
response = serverInfoResource.updateState(NodeState.ACTIVE);
assertEquals(response.getStatus(), 200);
nodeState = serverInfoResource.getServerState();
assertTrue(nodeState == NodeState.ACTIVE);
assertEquals(nodeState, NodeState.ACTIVE);
}
}

Expand All @@ -112,7 +111,7 @@ public void testServerShutdown()
Response response = serverInfoResource.updateState(NodeState.SHUTTING_DOWN);
assertEquals(response.getStatus(), 200);
NodeState nodeState = serverInfoResource.getServerState();
assertTrue(nodeState == NodeState.SHUTTING_DOWN);
assertEquals(nodeState, NodeState.SHUTTING_DOWN);
}
}

Expand Down

0 comments on commit 78a8d18

Please sign in to comment.