From a49244eac7a8b8fe914a16aa536739107c17c090 Mon Sep 17 00:00:00 2001 From: Dominik Przybysz Date: Tue, 30 Apr 2024 12:03:01 +0200 Subject: [PATCH] SNOW-1356389: Use junit assertions instead of jvm assert in tests --- .../client/core/SessionUtilTest.java | 2 +- .../client/jdbc/CustomProxyLatestIT.java | 4 +- .../jdbc/FileUploaderExpandFileNamesTest.java | 18 ++++---- .../SnowflakeDriverConnectionStressTest.java | 4 +- .../client/jdbc/SnowflakeDriverIT.java | 24 +++++------ .../client/jdbc/SnowflakeDriverLatestIT.java | 42 +++++++++++-------- .../client/jdbc/StatementLatestIT.java | 2 +- .../pooling/LogicalConnectionLatestIT.java | 2 +- 8 files changed, 53 insertions(+), 45 deletions(-) diff --git a/src/test/java/net/snowflake/client/core/SessionUtilTest.java b/src/test/java/net/snowflake/client/core/SessionUtilTest.java index 5cb118c56..0b5a542c1 100644 --- a/src/test/java/net/snowflake/client/core/SessionUtilTest.java +++ b/src/test/java/net/snowflake/client/core/SessionUtilTest.java @@ -66,7 +66,7 @@ public void testParameterParsing() { parameterMap.put("other_parameter", BooleanNode.getTrue()); SFBaseSession session = new MockConnectionTest.MockSnowflakeConnectionImpl().getSFSession(); SessionUtil.updateSfDriverParamValues(parameterMap, session); - assert (((BooleanNode) session.getOtherParameter("other_parameter")).asBoolean()); + assertTrue(((BooleanNode) session.getOtherParameter("other_parameter")).asBoolean()); } @Test diff --git a/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java b/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java index 0a2482cca..c6fb29bf4 100644 --- a/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java @@ -741,7 +741,7 @@ public PasswordAuthentication getPasswordAuthentication() { // Make sure that the downloaded file exists, it should be gzip compressed File downloaded = new File(destFolderCanonicalPathWithSeparator + TEST_DATA_FILE + ".gz"); - assert (downloaded.exists()); + assertTrue(downloaded.exists()); Process p = Runtime.getRuntime() @@ -750,7 +750,7 @@ public PasswordAuthentication getPasswordAuthentication() { File original = new File(sourceFilePath); File unzipped = new File(destFolderCanonicalPathWithSeparator + TEST_DATA_FILE); - assert (original.length() == unzipped.length()); + assertEquals(original.length(), unzipped.length()); } catch (Throwable t) { t.printStackTrace(); } finally { diff --git a/src/test/java/net/snowflake/client/jdbc/FileUploaderExpandFileNamesTest.java b/src/test/java/net/snowflake/client/jdbc/FileUploaderExpandFileNamesTest.java index 02ef84747..67f5a175b 100644 --- a/src/test/java/net/snowflake/client/jdbc/FileUploaderExpandFileNamesTest.java +++ b/src/test/java/net/snowflake/client/jdbc/FileUploaderExpandFileNamesTest.java @@ -4,6 +4,7 @@ package net.snowflake.client.jdbc; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.io.IOException; @@ -114,15 +115,14 @@ public int read() throws IOException { SnowflakeFileTransferConfig config = builder.build(); // Assert setting fields are in config - assert (config.getSnowflakeFileTransferMetadata() == metadata); - assert (config.getUploadStream() == input); - assert (config.getOcspMode() == OCSPMode.FAIL_CLOSED); - assert (!config.getRequireCompress()); - assert (config.getNetworkTimeoutInMilli() == 12345); - assert (config.getProxyProperties() == props); - assert (config.getPrefix().equals("dummy_prefix")); - assert (config.getDestFileName().equals("dummy_dest_file_name")); - + assertEquals(metadata, config.getSnowflakeFileTransferMetadata()); + assertEquals(input, config.getUploadStream()); + assertEquals(OCSPMode.FAIL_CLOSED, config.getOcspMode()); + assertFalse(config.getRequireCompress()); + assertEquals(12345, config.getNetworkTimeoutInMilli()); + assertEquals(props, config.getProxyProperties()); + assertEquals("dummy_prefix", config.getPrefix()); + assertEquals("dummy_dest_file_name", config.getDestFileName()); assertEquals(expectedThrowCount, throwCount); } } diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverConnectionStressTest.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverConnectionStressTest.java index 7d9cc5f05..161e9c939 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverConnectionStressTest.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverConnectionStressTest.java @@ -4,6 +4,8 @@ package net.snowflake.client.jdbc; +import static org.junit.Assert.assertNotNull; + import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -88,7 +90,7 @@ private static void connectAndQuery(int num_queries) throws SQLException { try (ResultSet resultSet = statement.executeQuery(QUERY)) { while (resultSet.next()) { final String user = resultSet.getString(1); - assert user != null; + assertNotNull(user); } } } diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverIT.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverIT.java index 13bcee4e5..a66dd4c4a 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverIT.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverIT.java @@ -769,7 +769,7 @@ public void testPutWithWildcardGCP() throws Throwable { for (int i = 0; i < fileNames.length; i++) { // Make sure that the downloaded file exists, it should be gzip compressed downloaded = new File(destFolderCanonicalPathWithSeparator + fileNames[i] + ".gz"); - assert (downloaded.exists()); + assertTrue(downloaded.exists()); Process p = Runtime.getRuntime() @@ -780,8 +780,8 @@ public void testPutWithWildcardGCP() throws Throwable { File original = new File(individualFilePath); File unzipped = new File(destFolderCanonicalPathWithSeparator + fileNames[i]); - assert (original.length() == unzipped.length()); - assert (FileUtils.contentEquals(original, unzipped)); + assertEquals(original.length(), unzipped.length()); + assertTrue(FileUtils.contentEquals(original, unzipped)); } } finally { statement.execute("DROP STAGE IF EXISTS wildcard_stage"); @@ -862,7 +862,7 @@ public void testPutGetLargeFileGCP() throws Throwable { // Make sure that the downloaded file exists; it should be gzip compressed File downloaded = new File(destFolderCanonicalPathWithSeparator + "bigFile.csv.gz"); - assert (downloaded.exists()); + assertTrue(downloaded.exists()); // unzip the file Process p = @@ -874,8 +874,8 @@ public void testPutGetLargeFileGCP() throws Throwable { // back into a stage, // downloaded, and unzipped File unzipped = new File(destFolderCanonicalPathWithSeparator + "bigFile.csv"); - assert (largeTempFile.length() == unzipped.length()); - assert (FileUtils.contentEquals(largeTempFile, unzipped)); + assertEquals(largeTempFile.length(), unzipped.length()); + assertTrue(FileUtils.contentEquals(largeTempFile, unzipped)); } finally { statement.execute("DROP STAGE IF EXISTS largefile_stage"); statement.execute("DROP STAGE IF EXISTS extra_stage"); @@ -937,7 +937,7 @@ public void testPutOverwrite() throws Throwable { // Make sure that the downloaded file exists; it should be gzip compressed File downloaded = new File(destFolderCanonicalPathWithSeparator + "testfile.csv.gz"); - assert (downloaded.exists()); + assertTrue(downloaded.exists()); // unzip the file Process p = @@ -946,7 +946,7 @@ public void testPutOverwrite() throws Throwable { p.waitFor(); File unzipped = new File(destFolderCanonicalPathWithSeparator + "testfile.csv"); - assert (FileUtils.contentEqualsIgnoreEOL(file2, unzipped, null)); + assertTrue(FileUtils.contentEqualsIgnoreEOL(file2, unzipped, null)); } finally { statement.execute("DROP TABLE IF EXISTS testLoadToLocalFS"); } @@ -2695,7 +2695,7 @@ public void testPutGet() throws Throwable { // Make sure that the downloaded file exists, it should be gzip compressed File downloaded = new File(destFolderCanonicalPathWithSeparator + TEST_DATA_FILE + ".gz"); - assert (downloaded.exists()); + assertTrue(downloaded.exists()); Process p = Runtime.getRuntime() @@ -2704,7 +2704,7 @@ public void testPutGet() throws Throwable { File original = new File(sourceFilePath); File unzipped = new File(destFolderCanonicalPathWithSeparator + TEST_DATA_FILE); - assert (original.length() == unzipped.length()); + assertEquals(original.length(), unzipped.length()); } finally { statement.execute("DROP STAGE IF EXISTS testGetPut_stage"); } @@ -2754,7 +2754,7 @@ public void testPutGetToUnencryptedStage() throws Throwable { // Make sure that the downloaded file exists, it should be gzip compressed File downloaded = new File(destFolderCanonicalPathWithSeparator + TEST_DATA_FILE + ".gz"); - assert (downloaded.exists()); + assertTrue(downloaded.exists()); Process p = Runtime.getRuntime() @@ -2763,7 +2763,7 @@ public void testPutGetToUnencryptedStage() throws Throwable { File original = new File(sourceFilePath); File unzipped = new File(destFolderCanonicalPathWithSeparator + TEST_DATA_FILE); - assert (original.length() == unzipped.length()); + assertEquals(original.length(), unzipped.length()); } finally { statement.execute("DROP STAGE IF EXISTS testPutGet_unencstage"); } diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java index 01bff3e2e..da9847c9b 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java @@ -224,7 +224,7 @@ public void testGCPFileTransferMetadataWithOneFile() throws Throwable { for (SnowflakeFileTransferMetadata oneMetadata : metadatas1) { InputStream inputStream = new FileInputStream(srcPath1); - assert (oneMetadata.isForOneFile()); + assertTrue(oneMetadata.isForOneFile()); SnowflakeFileTransferAgent.uploadWithoutConnection( SnowflakeFileTransferConfig.Builder.newInstance() .setSnowflakeFileTransferMetadata(oneMetadata) @@ -252,7 +252,7 @@ public void testGCPFileTransferMetadataWithOneFile() throws Throwable { p.waitFor(); InputStream gzInputStream = new FileInputStream(gzfilePath); - assert (oneMetadata.isForOneFile()); + assertTrue(oneMetadata.isForOneFile()); SnowflakeFileTransferAgent.uploadWithoutConnection( SnowflakeFileTransferConfig.Builder.newInstance() .setSnowflakeFileTransferMetadata(oneMetadata) @@ -271,8 +271,10 @@ public void testGCPFileTransferMetadataWithOneFile() throws Throwable { // Make sure that the downloaded files are EQUAL, // they should be gzip compressed - assert (isFileContentEqual(srcPath1, false, destFolderCanonicalPath + "/file1.gz", true)); - assert (isFileContentEqual(srcPath2, false, destFolderCanonicalPath + "/file2.gz", true)); + assertTrue( + isFileContentEqual(srcPath1, false, destFolderCanonicalPath + "/file1.gz", true)); + assertTrue( + isFileContentEqual(srcPath2, false, destFolderCanonicalPath + "/file2.gz", true)); } finally { statement.execute("DROP STAGE if exists " + testStageName); } @@ -360,8 +362,10 @@ public void testAzureS3FileTransferMetadataWithOneFile() throws Throwable { // Make sure that the downloaded files are EQUAL, // they should be gzip compressed - assert (isFileContentEqual(srcPath1, false, destFolderCanonicalPath + "/file1.gz", true)); - assert (isFileContentEqual(srcPath2, false, destFolderCanonicalPath + "/file2.gz", true)); + assertTrue( + isFileContentEqual(srcPath1, false, destFolderCanonicalPath + "/file1.gz", true)); + assertTrue( + isFileContentEqual(srcPath2, false, destFolderCanonicalPath + "/file2.gz", true)); } finally { statement.execute("DROP STAGE if exists " + testStageName); } @@ -1057,7 +1061,7 @@ private void putAndGetFile(Statement statement) throws Throwable { // Make sure that the downloaded file exists, it should be gzip compressed File downloaded = new File(destFolderCanonicalPathWithSeparator + TEST_DATA_FILE_2 + ".gz"); - assert (downloaded.exists()); + assertTrue(downloaded.exists()); Process p = Runtime.getRuntime() @@ -1070,7 +1074,7 @@ private void putAndGetFile(Statement statement) throws Throwable { "Original file: " + original.getAbsolutePath() + ", size: " + original.length()); System.out.println( "Unzipped file: " + unzipped.getAbsolutePath() + ", size: " + unzipped.length()); - assert (original.length() == unzipped.length()); + assertEquals(original.length(), unzipped.length()); } finally { statement.execute("DROP STAGE IF EXISTS testGetPut_stage"); } @@ -1137,7 +1141,7 @@ public void testPutGetLargeFileGCSDownscopedCredential() throws Throwable { // Make sure that the downloaded file exists; it should be gzip compressed File downloaded = new File(destFolderCanonicalPathWithSeparator + "bigFile.csv.gz"); - assert (downloaded.exists()); + assertTrue(downloaded.exists()); // unzip the file Process p = @@ -1149,8 +1153,8 @@ public void testPutGetLargeFileGCSDownscopedCredential() throws Throwable { // back into a stage, // downloaded, and unzipped File unzipped = new File(destFolderCanonicalPathWithSeparator + "bigFile.csv"); - assert (largeTempFile.length() == unzipped.length()); - assert (FileUtils.contentEquals(largeTempFile, unzipped)); + assertEquals(largeTempFile.length(), unzipped.length()); + assertTrue(FileUtils.contentEquals(largeTempFile, unzipped)); } finally { statement.execute("DROP STAGE IF EXISTS largefile_stage"); statement.execute("DROP STAGE IF EXISTS extra_stage"); @@ -1213,7 +1217,7 @@ public void testPutGetLargeFileAzure() throws Throwable { // Make sure that the downloaded file exists; it should be gzip compressed File downloaded = new File(destFolderCanonicalPathWithSeparator + "bigFile.csv.gz"); - assert (downloaded.exists()); + assertTrue(downloaded.exists()); // unzip the file Process p = @@ -1225,8 +1229,8 @@ public void testPutGetLargeFileAzure() throws Throwable { // back into a stage, // downloaded, and unzipped File unzipped = new File(destFolderCanonicalPathWithSeparator + "bigFile.csv"); - assert (largeTempFile.length() == unzipped.length()); - assert (FileUtils.contentEquals(largeTempFile, unzipped)); + assertEquals(largeTempFile.length(), unzipped.length()); + assertTrue(FileUtils.contentEquals(largeTempFile, unzipped)); } finally { statement.execute("DROP STAGE IF EXISTS largefile_stage"); statement.execute("DROP STAGE IF EXISTS extra_stage"); @@ -1349,8 +1353,10 @@ public void testPutS3RegionalUrl() throws Throwable { // Make sure that the downloaded files are EQUAL, // they should be gzip compressed - assert (isFileContentEqual(srcPath1, false, destFolderCanonicalPath + "/file1.gz", true)); - assert (isFileContentEqual(srcPath2, false, destFolderCanonicalPath + "/file2.gz", true)); + assertTrue( + isFileContentEqual(srcPath1, false, destFolderCanonicalPath + "/file1.gz", true)); + assertTrue( + isFileContentEqual(srcPath2, false, destFolderCanonicalPath + "/file2.gz", true)); } finally { statement.execute("DROP STAGE if exists " + testStageName); } @@ -1489,7 +1495,7 @@ public void testUploadWithGCSPresignedUrlWithoutConnection() throws Throwable { for (SnowflakeFileTransferMetadata oneMetadata : metadata) { InputStream inputStream = new FileInputStream(srcPath); - assert (oneMetadata.isForOneFile()); + assertTrue(oneMetadata.isForOneFile()); SnowflakeFileTransferAgent.uploadWithoutConnection( SnowflakeFileTransferConfig.Builder.newInstance() .setSnowflakeFileTransferMetadata(oneMetadata) @@ -1504,7 +1510,7 @@ public void testUploadWithGCSPresignedUrlWithoutConnection() throws Throwable { "Failed to get files", statement.execute( "GET @" + testStageName + " 'file://" + destFolderCanonicalPath + "/' parallel=8")); - assert (isFileContentEqual(srcPath, false, destFolderCanonicalPath + "/file1.gz", true)); + assertTrue(isFileContentEqual(srcPath, false, destFolderCanonicalPath + "/file1.gz", true)); } finally { statement.execute("DROP STAGE if exists " + testStageName); } diff --git a/src/test/java/net/snowflake/client/jdbc/StatementLatestIT.java b/src/test/java/net/snowflake/client/jdbc/StatementLatestIT.java index 56bd318b8..d37d88118 100644 --- a/src/test/java/net/snowflake/client/jdbc/StatementLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/StatementLatestIT.java @@ -132,7 +132,7 @@ public void testCopyAndUpload() throws Exception { // Make sure that the downloaded file exists, it should be gzip compressed File downloaded = new File(tempFolder.getCanonicalPath() + File.separator + fileName + ".gz"); - assert (downloaded.exists()); + assertTrue(downloaded.exists()); } // unzip the new file Process p = diff --git a/src/test/java/net/snowflake/client/pooling/LogicalConnectionLatestIT.java b/src/test/java/net/snowflake/client/pooling/LogicalConnectionLatestIT.java index 627f1db31..bf05325e0 100644 --- a/src/test/java/net/snowflake/client/pooling/LogicalConnectionLatestIT.java +++ b/src/test/java/net/snowflake/client/pooling/LogicalConnectionLatestIT.java @@ -161,7 +161,7 @@ public void testTransactionStatement() throws SQLException { PooledConnection pooledConnection = poolDataSource.getPooledConnection(); try (Connection logicalConnection = pooledConnection.getConnection()) { logicalConnection.setAutoCommit(false); - assert (!logicalConnection.getAutoCommit()); + assertFalse(logicalConnection.getAutoCommit()); logicalConnection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); assertEquals(2, logicalConnection.getTransactionIsolation());