Permalink
Browse files

refactor: replace some usages of assertTrue (#957)

  • Loading branch information...
AlexElin authored and vlsi committed Oct 20, 2017
1 parent 83dd5fe commit c759a58313c4344924a311021e1c860580f3e318
Showing with 211 additions and 238 deletions.
  1. +2 −2 pgjdbc/src/test/java/org/postgresql/core/ParserTest.java
  2. +3 −5 pgjdbc/src/test/java/org/postgresql/core/ReturningParserTest.java
  3. +5 −4 pgjdbc/src/test/java/org/postgresql/test/jdbc2/BlobTest.java
  4. +2 −1 pgjdbc/src/test/java/org/postgresql/test/jdbc2/ConnectionTest.java
  5. +5 −9 pgjdbc/src/test/java/org/postgresql/test/jdbc2/CopyTest.java
  6. +20 −19 pgjdbc/src/test/java/org/postgresql/test/jdbc2/DatabaseMetaDataPropertiesTest.java
  7. +77 −106 pgjdbc/src/test/java/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java
  8. +2 −1 pgjdbc/src/test/java/org/postgresql/test/jdbc2/GetXXXTest.java
  9. +2 −2 pgjdbc/src/test/java/org/postgresql/test/jdbc2/PGTimeTest.java
  10. +2 −2 pgjdbc/src/test/java/org/postgresql/test/jdbc2/PreparedStatementTest.java
  11. +9 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc2/RefCursorTest.java
  12. +7 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc2/TimestampTest.java
  13. +4 −4 pgjdbc/src/test/java/org/postgresql/test/jdbc2/UpdateableResultTest.java
  14. +9 −7 pgjdbc/src/test/java/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java
  15. +34 −34 pgjdbc/src/test/java/org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java
  16. +4 −4 pgjdbc/src/test/java/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java
  17. +4 −4 pgjdbc/src/test/java/org/postgresql/test/jdbc3/Jdbc3BlobTest.java
  18. +18 −17 pgjdbc/src/test/java/org/postgresql/test/jdbc3/Jdbc3CallableStatementTest.java
  19. +2 −1 pgjdbc/src/test/java/org/postgresql/test/jdbc4/ClientInfoTest.java
@@ -146,7 +146,7 @@ public void insertSelectFakeReturning() throws SQLException {
"insert test(id, name) select 1, 'value' as RETURNING from test2";
List<NativeQuery> qry =
Parser.parseJdbcSql(
query, true, true, true, true, new String[0]);
query, true, true, true, true);
boolean returningKeywordPresent = qry.get(0).command.isReturningKeywordPresent();
Assert.assertFalse("Query does not have returning clause " + query, returningKeywordPresent);
}
@@ -157,7 +157,7 @@ public void insertSelectReturning() throws SQLException {
"insert test(id, name) select 1, 'value' from test2 RETURNING id";
List<NativeQuery> qry =
Parser.parseJdbcSql(
query, true, true, true, true, new String[0]);
query, true, true, true, true);
boolean returningKeywordPresent = qry.get(0).command.isReturningKeywordPresent();
Assert.assertTrue("Query has a returning clause " + query, returningKeywordPresent);
}
@@ -53,14 +53,12 @@ public void test() throws SQLException {
String query =
"insert into\"prep\"(a, " + prefix + columnName + suffix + ")values(1,2)" + prefix
+ returning + suffix;
List<NativeQuery> qry =
Parser.parseJdbcSql(
query, true, true, true, true, new String[0]);
List<NativeQuery> qry = Parser.parseJdbcSql(query, true, true, true, true);
boolean returningKeywordPresent = qry.get(0).command.isReturningKeywordPresent();
boolean expectedReturning = this.returning.equalsIgnoreCase("returning")
&& (prefix.length() == 0 || !Character.isJavaIdentifierStart(prefix.charAt(0)))
&& (suffix.length() == 0 || !Character.isJavaIdentifierPart(suffix.charAt(0)));
&& (prefix.isEmpty() || !Character.isJavaIdentifierStart(prefix.charAt(0)))
&& (suffix.isEmpty() || !Character.isJavaIdentifierPart(suffix.charAt(0)));
if (expectedReturning != returningKeywordPresent) {
Assert.assertEquals("Wrong <returning_clause> detected in SQL " + query,
expectedReturning,
@@ -8,6 +8,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.postgresql.core.ServerVersion;
import org.postgresql.largeobject.LargeObject;
@@ -275,7 +276,7 @@ private long uploadFile(String file, int method) throws Exception {
break;
default:
assertTrue("Unknown method in uploadFile", false);
fail("Unknown method in uploadFile");
}
blob.close();
@@ -323,7 +324,7 @@ private boolean compareBlobsLOAPI() throws Exception {
result = result && f == -1 && b == -1;
if (!result) {
assertTrue("Large Object API Blob compare failed at " + c + " of " + blob.size(), false);
fail("Large Object API Blob compare failed at " + c + " of " + blob.size());
}
blob.close();
@@ -364,7 +365,7 @@ private boolean compareBlobs() throws Exception {
result = result && f == -1 && b == -1;
if (!result) {
assertTrue("JDBC API Blob compare failed at " + c + " of " + blob.length(), false);
fail("JDBC API Blob compare failed at " + c + " of " + blob.length());
}
bis.close();
@@ -405,7 +406,7 @@ private boolean compareClobs() throws Exception {
result = result && f == -1 && b == -1;
if (!result) {
assertTrue("Clob compare failed at " + c + " of " + clob.length(), false);
fail("Clob compare failed at " + c + " of " + clob.length());
}
bis.close();
@@ -7,6 +7,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -195,7 +196,7 @@ public void testWarnings() throws Exception {
// Finally test clearWarnings() this time there must be something to delete
con.clearWarnings();
assertTrue(con.getWarnings() == null);
assertNull(con.getWarnings());
TestUtil.closeDB(con);
}
@@ -6,6 +6,7 @@
package org.postgresql.test.jdbc2;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -107,10 +108,8 @@ public void testCopyInByRow() throws SQLException {
long count1 = cp.endCopy();
long count2 = cp.getHandledRowCount();
long expectedResult = -1;
expectedResult = dataRows;
assertEquals(expectedResult, count1);
assertEquals(expectedResult, count2);
assertEquals(dataRows, count1);
assertEquals(dataRows, count2);
try {
cp.cancelCopy();
@@ -212,10 +211,8 @@ public void testCopyOutByRow() throws SQLException, IOException {
assertEquals(dataRows, count);
long rowCount = cp.getHandledRowCount();
long expectedResult = -1;
expectedResult = dataRows;
assertEquals(expectedResult, rowCount);
assertEquals(dataRows, rowCount);
assertEquals(dataRows, getCount());
}
@@ -229,10 +226,9 @@ public void testCopyOut() throws SQLException, IOException {
assertEquals(dataRows, getCount());
// deep comparison of data written and read
byte[] copybytes = copydata.toByteArray();
assertTrue(copybytes != null);
assertNotNull(copybytes);
for (int i = 0, l = 0; i < origData.length; i++) {
byte[] origBytes = origData[i].getBytes();
assertTrue(origBytes != null);
assertTrue("Copy is shorter than original", copybytes.length >= l + origBytes.length);
for (int j = 0; j < origBytes.length; j++, l++) {
assertEquals("content changed at byte#" + j + ": " + origBytes[j] + copybytes[l],
@@ -6,6 +6,7 @@
package org.postgresql.test.jdbc2;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -109,10 +110,10 @@ public void testNulls() throws SQLException {
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);
assertTrue(!dbmd.nullsAreSortedAtStart());
assertTrue(dbmd.nullsAreSortedAtEnd() != true);
assertTrue(dbmd.nullsAreSortedHigh() == true);
assertTrue(!dbmd.nullsAreSortedLow());
assertFalse(dbmd.nullsAreSortedAtStart());
assertFalse(dbmd.nullsAreSortedAtEnd());
assertTrue(dbmd.nullsAreSortedHigh());
assertFalse(dbmd.nullsAreSortedLow());
assertTrue(dbmd.nullPlusNonNullIsNull());
@@ -133,16 +134,16 @@ public void testIdentifiers() throws SQLException {
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);
assertTrue(!dbmd.supportsMixedCaseIdentifiers()); // always false
assertTrue(dbmd.supportsMixedCaseQuotedIdentifiers()); // always true
assertFalse(dbmd.supportsMixedCaseIdentifiers());
assertTrue(dbmd.supportsMixedCaseQuotedIdentifiers());
assertTrue(!dbmd.storesUpperCaseIdentifiers()); // always false
assertTrue(dbmd.storesLowerCaseIdentifiers()); // always true
assertTrue(!dbmd.storesUpperCaseQuotedIdentifiers()); // always false
assertTrue(!dbmd.storesLowerCaseQuotedIdentifiers()); // always false
assertTrue(!dbmd.storesMixedCaseQuotedIdentifiers()); // always false
assertFalse(dbmd.storesUpperCaseIdentifiers());
assertTrue(dbmd.storesLowerCaseIdentifiers());
assertFalse(dbmd.storesUpperCaseQuotedIdentifiers());
assertFalse(dbmd.storesLowerCaseQuotedIdentifiers());
assertFalse(dbmd.storesMixedCaseQuotedIdentifiers());
assertTrue(dbmd.getIdentifierQuoteString().equals("\""));
assertEquals( "\"", dbmd.getIdentifierQuoteString());
}
@@ -183,8 +184,8 @@ public void testDBParams() throws SQLException {
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);
assertTrue(dbmd.getURL().equals(TestUtil.getURL()));
assertTrue(dbmd.getUserName().equals(TestUtil.getUser()));
assertEquals(TestUtil.getURL(), dbmd.getURL());
assertEquals(TestUtil.getUser(), dbmd.getUserName());
}
@Test
@@ -194,7 +195,7 @@ public void testDbProductDetails() throws SQLException {
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);
assertTrue(dbmd.getDatabaseProductName().equals("PostgreSQL"));
assertEquals("PostgreSQL", dbmd.getDatabaseProductName());
assertTrue(dbmd.getDatabaseMajorVersion() >= 8);
assertTrue(dbmd.getDatabaseMinorVersion() >= 0);
assertTrue(dbmd.getDatabaseProductVersion().startsWith(String.valueOf(dbmd.getDatabaseMajorVersion())));
@@ -205,10 +206,10 @@ public void testDriverVersioning() throws SQLException {
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);
assertTrue(dbmd.getDriverName().equals("PostgreSQL JDBC Driver"));
assertTrue(dbmd.getDriverVersion().equals(org.postgresql.util.DriverInfo.DRIVER_VERSION));
assertTrue(dbmd.getDriverMajorVersion() == new org.postgresql.Driver().getMajorVersion());
assertTrue(dbmd.getDriverMinorVersion() == new org.postgresql.Driver().getMinorVersion());
assertEquals("PostgreSQL JDBC Driver", dbmd.getDriverName());
assertEquals(org.postgresql.util.DriverInfo.DRIVER_VERSION, dbmd.getDriverVersion());
assertEquals(new org.postgresql.Driver().getMajorVersion(), dbmd.getDriverMajorVersion());
assertEquals(new org.postgresql.Driver().getMinorVersion(), dbmd.getDriverMinorVersion());
assertTrue(dbmd.getJDBCMajorVersion() >= 4);
assertTrue(dbmd.getJDBCMinorVersion() >= 0);
}
Oops, something went wrong.

0 comments on commit c759a58

Please sign in to comment.