Permalink
Browse files

style: cleanup and Java 5' features for tests (#602)

add acces modifiers
Java 5's for-each
simplify some expressions
  • Loading branch information...
AlexElin authored and vlsi committed Jul 10, 2016
1 parent 1d8ebfc commit 28c0c2217d739678056a4cb193c4ec886cc9fada
Showing with 232 additions and 263 deletions.
  1. +1 −2 pgjdbc/src/test/java/org/postgresql/core/v3/V3ParameterListTests.java
  2. +1 −2 pgjdbc/src/test/java/org/postgresql/jdbc/DeepBatchedInsertStatementTest.java
  3. +6 −8 pgjdbc/src/test/java/org/postgresql/jdbc/InsertRewriteWithAlternatingTypesIssue584.java
  4. 0 pgjdbc/src/test/java/org/postgresql/test/{README → README.md}
  5. +2 −2 pgjdbc/src/test/java/org/postgresql/test/extensions/HStoreTest.java
  6. +1 −2 pgjdbc/src/test/java/org/postgresql/test/hostchooser/MultiHostsConnectionTest.java
  7. +2 −2 pgjdbc/src/test/java/org/postgresql/test/jdbc2/BaseTest4.java
  8. +2 −2 pgjdbc/src/test/java/org/postgresql/test/jdbc2/BatchFailureTest.java
  9. +1 −2 pgjdbc/src/test/java/org/postgresql/test/jdbc2/BatchedInsertReWriteEnabledTest.java
  10. +1 −2 pgjdbc/src/test/java/org/postgresql/test/jdbc2/BlobTransactionTest.java
  11. +2 −3 pgjdbc/src/test/java/org/postgresql/test/jdbc2/ConnectTimeoutTest.java
  12. +1 −3 pgjdbc/src/test/java/org/postgresql/test/jdbc2/CopyLargeFileTest.java
  13. +3 −5 pgjdbc/src/test/java/org/postgresql/test/jdbc2/CopyTest.java
  14. +44 −45 pgjdbc/src/test/java/org/postgresql/test/jdbc2/CursorFetchTest.java
  15. +19 −19 pgjdbc/src/test/java/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java
  16. +2 −2 pgjdbc/src/test/java/org/postgresql/test/jdbc2/DriverTest.java
  17. +2 −3 pgjdbc/src/test/java/org/postgresql/test/jdbc2/EncodingTest.java
  18. +1 −1 pgjdbc/src/test/java/org/postgresql/test/jdbc2/GetXXXTest.java
  19. +9 −7 pgjdbc/src/test/java/org/postgresql/test/jdbc2/LoginTimeoutTest.java
  20. +1 −4 pgjdbc/src/test/java/org/postgresql/test/jdbc2/OID74Test.java
  21. +1 −1 pgjdbc/src/test/java/org/postgresql/test/jdbc2/PGTimeTest.java
  22. +1 −1 pgjdbc/src/test/java/org/postgresql/test/jdbc2/PGTimestampTest.java
  23. +19 −26 pgjdbc/src/test/java/org/postgresql/test/jdbc2/PreparedStatementTest.java
  24. +1 −1 pgjdbc/src/test/java/org/postgresql/test/jdbc2/QuotationTest.java
  25. +2 −2 pgjdbc/src/test/java/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java
  26. +2 −3 pgjdbc/src/test/java/org/postgresql/test/jdbc2/StatementTest.java
  27. +16 −18 pgjdbc/src/test/java/org/postgresql/test/jdbc2/TimeTest.java
  28. +44 −42 pgjdbc/src/test/java/org/postgresql/test/jdbc2/TimestampTest.java
  29. +2 −1 pgjdbc/src/test/java/org/postgresql/test/jdbc2/TimezoneTest.java
  30. +1 −1 pgjdbc/src/test/java/org/postgresql/test/jdbc2/TypeCacheDLLStressTest.java
  31. +2 −5 pgjdbc/src/test/java/org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java
  32. +6 −6 pgjdbc/src/test/java/org/postgresql/test/jdbc3/Jdbc3CallableStatementTest.java
  33. +5 −7 pgjdbc/src/test/java/org/postgresql/test/jdbc4/BlobTest.java
  34. +0 −2 pgjdbc/src/test/java/org/postgresql/test/jdbc4/WrapperTest.java
  35. +1 −1 pgjdbc/src/test/java/org/postgresql/test/jdbc42/CustomizeDefaultFetchSizeTest.java
  36. +4 −2 pgjdbc/src/test/java/org/postgresql/test/socketfactory/SocketFactoryTestSuite.java
  37. +1 −1 pgjdbc/src/test/java/org/postgresql/test/ssl/SingleCertValidatingFactoryTestSuite.java
  38. +14 −16 pgjdbc/src/test/java/org/postgresql/test/ssl/SslTest.java
  39. +7 −8 pgjdbc/src/test/java/org/postgresql/test/ssl/SslTestSuite.java
  40. +2 −3 pgjdbc/src/test/java/org/postgresql/test/util/LruCacheTest.java
@@ -65,8 +65,7 @@ public V3ParameterListTests(String test) {
@Override
@Before
protected void setUp() throws Exception {
SocketFactory socketFactory = SocketFactoryFactory.getSocketFactory(System
.getProperties());
SocketFactory socketFactory = SocketFactoryFactory.getSocketFactory(System.getProperties());
HostSpec hostSpec = new HostSpec(TestUtil.getServer(), TestUtil.getPort());
pci = new ProtocolConnectionImpl(new PGStream(socketFactory, hostSpec), "",
"", new Properties(), new Logger(), 5000);
@@ -75,8 +75,7 @@ protected void updateProperties(Properties props) {
public void testDeepInternalsBatchedQueryDecorator() throws Exception {
PgPreparedStatement pstmt = null;
try {
pstmt = (PgPreparedStatement) con
.prepareStatement("INSERT INTO testbatch VALUES (?,?)");
pstmt = (PgPreparedStatement) con.prepareStatement("INSERT INTO testbatch VALUES (?,?)");
pstmt.setInt(1, 1);
pstmt.setInt(2, 2);
@@ -79,7 +79,7 @@ public void testPreparedStatementPreparation() throws Throwable {
Connection conn = con;
conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
try {
Timestamp ts = new Timestamp(2016 - 1900, 1 - 1, 31, 0, 0, 0, 0);
Timestamp ts = new Timestamp(2016 - 1900, 0, 31, 0, 0, 0, 0);
int[] types = new int[]{
Types.NUMERIC,
Types.DATE,
@@ -96,21 +96,20 @@ public void testPreparedStatementPreparation() throws Throwable {
Object[] row3 = new Object[]{1, ts, 0.0, true, null, ts, 0.0, 0.0};
Object[][] tRows = new Object[][]{row0, row1, row2, row3};
List<Object[]> rowList = new ArrayList<Object[]>();
for (int i = 0; i < ROW_INDEXES.length; i++) {
rowList.add(tRows[ROW_INDEXES[i]]);
for (int ROW_INDEX : ROW_INDEXES) {
rowList.add(tRows[ROW_INDEX]);
}
StringBuilder sb = new StringBuilder();
sb.append(
"INSERT INTO BugFreezeTable (Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col8) VALUES (?,?,?,?,?,?,?,?)");
String insert = sb.toString();
PgPreparedStatement pst = (PgPreparedStatement) conn.prepareStatement(insert);
String statementName = null;
String statementName;
int count = 0;
do {
Object[][] rows = rowList.toArray(new Object[0][]);
for (int j = 0; j < rows.length; j++) {
Object[] row = rows[j];
for (Object[] row : rows) {
for (int k = 0; k < row.length; k++) {
Object o = row[k];
int paramIndex = k + 1;
@@ -153,8 +152,7 @@ private String getStatementName(PgPreparedStatement pst) throws Exception {
Field statementNameField =
Class.forName("org.postgresql.core.v3.SimpleQuery").getDeclaredField("statementName");
statementNameField.setAccessible(true);
String statementName = (String) statementNameField.get(query);
return statementName;
return (String) statementNameField.get(query);
}
/**
@@ -66,7 +66,7 @@ public void testHStoreSelectNullValue() throws SQLException {
}
public void testHStoreSend() throws SQLException {
Map<String, Integer> correct = Collections.singletonMap("a", new Integer(1));
Map<String, Integer> correct = Collections.singletonMap("a", 1);
PreparedStatement pstmt = _conn.prepareStatement("SELECT ?::text");
pstmt.setObject(1, correct);
ResultSet rs = pstmt.executeQuery();
@@ -76,7 +76,7 @@ public void testHStoreSend() throws SQLException {
}
public void testHStoreUsingPSSetObject4() throws SQLException {
Map<String, Integer> correct = Collections.singletonMap("a", new Integer(1));
Map<String, Integer> correct = Collections.singletonMap("a", 1);
PreparedStatement pstmt = _conn.prepareStatement("SELECT ?::text");
pstmt.setObject(1, correct, Types.OTHER, -1);
ResultSet rs = pstmt.executeQuery();
@@ -45,9 +45,8 @@
private static Map<HostSpec, Object> hostStatusMap;
static {
Field field;
try {
field = GlobalHostStatusTracker.class.getDeclaredField("hostStatusMap");
Field field = GlobalHostStatusTracker.class.getDeclaredField("hostStatusMap");
field.setAccessible(true);
hostStatusMap = (Map<HostSpec, Object>) field.get(null);
@@ -13,11 +13,11 @@
public class BaseTest4 {
public enum BinaryMode {
REGULAR, FORCE;
REGULAR, FORCE
}
public enum AutoCommit {
YES, NO;
YES, NO
}
protected Connection con;
@@ -68,7 +68,7 @@ public void addRow(Statement statement, String value) throws SQLException {
}
}
enum FailMode {
private enum FailMode {
NO_FAIL_JUST_INSERTS, NO_FAIL_SELECT,
FAIL_VIA_SELECT_PARSE, FAIL_VIA_SELECT_RUNTIME,
FAIL_VIA_DUP_KEY;
@@ -99,7 +99,7 @@ public void injectFailure(Statement statement, BatchType batchType) throws SQLEx
}
}
enum FailPosition {
private enum FailPosition {
NONE, FIRST_ROW, SECOND_ROW, MIDDLE, ALMOST_LAST_ROW, LAST_ROW;
public boolean supports(FailMode mode) {
@@ -134,8 +134,7 @@ public void testBatchWithReWrittenBatchStatementWithFixedParameter()
"INSERT INTO testbatch VALUES (?, '1, (, $1234, a''n?d )' /*xxxx)*/, ?) -- xxx",
// "INSERT /*xxx*/INTO testbatch VALUES (?, '1, (, $1234, a''n?d )' /*xxxx)*/, ?) -- xxx",
};
for (int i = 0; i < odd.length; i++) {
String s = odd[i];
for (String s : odd) {
PreparedStatement pstmt = null;
try {
pstmt = con.prepareStatement(s);
@@ -48,13 +48,12 @@ protected void setUp() throws Exception {
String sql;
Statement st;
/*
* this would have to be executed using the postgres user in order to get access to a C function
*
*/
Connection privilegedCon = TestUtil.openPrivilegedDB();
st = privilegedCon.createStatement();
Statement st = privilegedCon.createStatement();
try {
sql =
"CREATE OR REPLACE FUNCTION lo_manage() RETURNS pg_catalog.trigger AS '$libdir/lo' LANGUAGE C";
@@ -2,7 +2,6 @@
import org.postgresql.test.TestUtil;
import junit.framework.Assert;
import junit.framework.TestCase;
import java.net.SocketTimeoutException;
@@ -33,13 +32,13 @@ public void testTimeout() {
try {
DriverManager.getConnection(UNREACHABLE_URL, props);
} catch (SQLException e) {
Assert.assertTrue("Unexpected " + e.toString(),
assertTrue("Unexpected " + e.toString(),
e.getCause() instanceof SocketTimeoutException);
final long interval = System.currentTimeMillis() - startTime;
final long connectTimeoutMillis = CONNECT_TIMEOUT * 1000;
final long maxDeviation = connectTimeoutMillis / 10;
// check that it was not a default system timeout, an approximate value is used
Assert.assertTrue(Math.abs(interval - connectTimeoutMillis) < maxDeviation);
assertTrue(Math.abs(interval - connectTimeoutMillis) < maxDeviation);
return;
}
fail("SQLException expected");
@@ -28,7 +28,6 @@
protected void setUp() throws Exception {
super.setUp();
con = TestUtil.openDB();
@@ -49,9 +48,8 @@ protected void setUp() throws Exception {
private void feedTable() throws Exception {
PreparedStatement stmt = con.prepareStatement(
TestUtil.insertSQL("pgjdbc_issue366_test_glossary", "text_id, name", "?, ?"));
char ch = ' ';
for (int i = 0; i < 26; i++) {
ch = (char) ('A' + i); // black magic
char ch = (char) ('A' + i); // black magic
insertData(stmt, "VERY_LONG_STRING_TO_REPRODUCE_ISSUE_366_" + ch + ch + ch,
"" + ch + ch + ch);
}
@@ -55,15 +55,13 @@ public CopyTest(String name) {
private byte[] getData(String[] origData) {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(buf);
for (int i = 0; i < origData.length; i++) {
ps.print(origData[i]);
for (String anOrigData : origData) {
ps.print(anOrigData);
}
return buf.toByteArray();
}
protected void setUp() throws Exception {
con = TestUtil.openDB();
TestUtil.createTable(con, "copytest", "stringvalue text, intvalue int, numvalue numeric(5,2)");
@@ -154,7 +152,7 @@ public int read() {
}
}, 3);
} catch (Exception e) {
if (e.toString().indexOf("COPYTEST") == -1) {
if (!e.toString().contains("COPYTEST")) {
fail("should have failed trying to read from our bogus stream.");
}
}
Oops, something went wrong.

0 comments on commit 28c0c22

Please sign in to comment.