postgresql-jdbc.git / summary / log / commit / refs
commit 9bf0eaca2f67fa3fce86c9071f7c1124e6bf76b0
Author: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
Date: Tue Jan 02 10:00:21 2024 +0000
refactor: cleanup excessive init... added by junit4->junit5 parameterized test converter
.../core/CommandCompleteParserNegativeTest.java | 7 -------
.../org/postgresql/core/CommandCompleteParserTest.java | 11 -----------
.../test/java/org/postgresql/core/OidToStringTest.java | 9 ---------
.../test/java/org/postgresql/core/OidValueOfTest.java | 9 ---------
.../java/org/postgresql/core/ReturningParserTest.java | 15 +--------------
.../java/org/postgresql/core/UTF8EncodingTest.java | 10 ----------
.../org/postgresql/test/jdbc3/SqlCommandParseTest.java | 9 ---------
.../test/jdbc4/ConnectionValidTimeoutTest.java | 18 ++----------------
.../postgresql/test/ssl/CommonNameVerifierTest.java | 12 ------------
.../postgresql/test/ssl/LibPQFactoryHostNameTest.java | 12 ------------
.../test/util/PGPropertyMaxResultBufferParserTest.java | 11 -----------
.../postgresql/test/util/ServerVersionParseTest.java | 12 ------------
12 files changed, 3 insertions(+), 132 deletions(-)
diff --git a/pgjdbc/src/test/java/org/postgresql/core/CommandCompleteParserNegativeTest.java b/pgjdbc/src/test/java/org/postgresql/core/CommandCompleteParserNegativeTest.java
index 66cc7882..60c6ce6d 100644
--- a/pgjdbc/src/test/java/org/postgresql/core/CommandCompleteParserNegativeTest.java
+++ b/pgjdbc/src/test/java/org/postgresql/core/CommandCompleteParserNegativeTest.java
@@ -14,8 +14,6 @@ import org.junit.jupiter.params.provider.MethodSource;
import java.util.Arrays;
public class CommandCompleteParserNegativeTest {
- public String input;
-
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{"SELECT 0_0 42"},
@@ -27,7 +25,6 @@ public class CommandCompleteParserNegativeTest {
@MethodSource("data")
@ParameterizedTest(name = "input={0}")
public void run(String input) throws PSQLException {
- initCommandCompleteParserNegativeTest(input);
CommandCompleteParser parser = new CommandCompleteParser();
try {
parser.parse(input);
@@ -43,8 +40,4 @@ public class CommandCompleteParserNegativeTest {
// NumerFormatException is expected
}
}
-
- public void initCommandCompleteParserNegativeTest(String input) {
- this.input = input;
- }
}
diff --git a/pgjdbc/src/test/java/org/postgresql/core/CommandCompleteParserTest.java b/pgjdbc/src/test/java/org/postgresql/core/CommandCompleteParserTest.java
index f37bbf99..5aaec9b8 100644
--- a/pgjdbc/src/test/java/org/postgresql/core/CommandCompleteParserTest.java
+++ b/pgjdbc/src/test/java/org/postgresql/core/CommandCompleteParserTest.java
@@ -14,10 +14,6 @@ import org.junit.jupiter.params.provider.MethodSource;
import java.util.Arrays;
public class CommandCompleteParserTest {
- public String input;
- public long oid;
- public long rows;
-
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{"SELECT 0", 0, 0},
@@ -43,17 +39,10 @@ public class CommandCompleteParserTest {
@MethodSource("data")
@ParameterizedTest(name = "input={0}, oid={1}, rows={2}")
public void run(String input, long oid, long rows) throws PSQLException {
- initCommandCompleteParserTest(input, oid, rows);
CommandCompleteParser expected = new CommandCompleteParser();
CommandCompleteParser actual = new CommandCompleteParser();
expected.set(oid, rows);
actual.parse(input);
Assertions.assertEquals(expected, actual, input);
}
-
- public void initCommandCompleteParserTest(String input, long oid, long rows) {
- this.input = input;
- this.oid = oid;
- this.rows = rows;
- }
}
diff --git a/pgjdbc/src/test/java/org/postgresql/core/OidToStringTest.java b/pgjdbc/src/test/java/org/postgresql/core/OidToStringTest.java
index e08fac9d..d3e219ea 100644
--- a/pgjdbc/src/test/java/org/postgresql/core/OidToStringTest.java
+++ b/pgjdbc/src/test/java/org/postgresql/core/OidToStringTest.java
@@ -14,9 +14,6 @@ import org.junit.jupiter.params.provider.MethodSource;
import java.util.Arrays;
public class OidToStringTest {
- public int value;
- public String expected;
-
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{142, "XML"},
@@ -28,12 +25,6 @@ public class OidToStringTest {
@MethodSource("data")
@ParameterizedTest(name = "expected={1}, value={0}")
public void run(int value, String expected) throws PSQLException {
- initOidToStringTest(value, expected);
Assertions.assertEquals(expected, Oid.toString(value));
}
-
- public void initOidToStringTest(int value, String expected) {
- this.value = value;
- this.expected = expected;
- }
}
diff --git a/pgjdbc/src/test/java/org/postgresql/core/OidValueOfTest.java b/pgjdbc/src/test/java/org/postgresql/core/OidValueOfTest.java
index 15e11d45..287e3808 100644
--- a/pgjdbc/src/test/java/org/postgresql/core/OidValueOfTest.java
+++ b/pgjdbc/src/test/java/org/postgresql/core/OidValueOfTest.java
@@ -14,9 +14,6 @@ import org.junit.jupiter.params.provider.MethodSource;
import java.util.Arrays;
public class OidValueOfTest {
- public int expected;
- public String value;
-
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{25, "TEXT"},
@@ -29,12 +26,6 @@ public class OidValueOfTest {
@MethodSource("data")
@ParameterizedTest(name = "expected={0}, value={1}")
public void run(int expected, String value) throws PSQLException {
- initOidValueOfTest(expected, value);
Assertions.assertEquals(expected, Oid.valueOf(value));
}
-
- public void initOidValueOfTest(int expected, String value) {
- this.expected = expected;
- this.value = value;
- }
}
diff --git a/pgjdbc/src/test/java/org/postgresql/core/ReturningParserTest.java b/pgjdbc/src/test/java/org/postgresql/core/ReturningParserTest.java
index 669125c4..11d40491 100644
--- a/pgjdbc/src/test/java/org/postgresql/core/ReturningParserTest.java
+++ b/pgjdbc/src/test/java/org/postgresql/core/ReturningParserTest.java
@@ -15,18 +15,6 @@ import java.util.Collection;
import java.util.List;
public class ReturningParserTest {
- private String columnName;
- private String returning;
- private String prefix;
- private String suffix;
-
- public void initReturningParserTest(String columnName, String returning, String prefix, String suffix) {
- this.columnName = columnName;
- this.returning = returning;
- this.prefix = prefix;
- this.suffix = suffix;
- }
-
public static Iterable<Object[]> data() {
Collection<Object[]> ids = new ArrayList<>();
@@ -47,14 +35,13 @@ public class ReturningParserTest {
@MethodSource("data")
@ParameterizedTest(name = "columnName={2} {0} {3}, returning={2} {1} {3}")
public void test(String columnName, String returning, String prefix, String suffix) throws SQLException {
- initReturningParserTest(columnName, returning, prefix, suffix);
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, true);
boolean returningKeywordPresent = qry.get(0).command.isReturningKeywordPresent();
- boolean expectedReturning = "returning".equalsIgnoreCase(this.returning)
+ boolean expectedReturning = "returning".equalsIgnoreCase(returning)
&& (prefix.isEmpty() || !Character.isJavaIdentifierStart(prefix.charAt(0)))
&& (suffix.isEmpty() || !Character.isJavaIdentifierPart(suffix.charAt(0)));
if (expectedReturning != returningKeywordPresent) {
diff --git a/pgjdbc/src/test/java/org/postgresql/core/UTF8EncodingTest.java b/pgjdbc/src/test/java/org/postgresql/core/UTF8EncodingTest.java
index 3f810efb..c907859c 100644
--- a/pgjdbc/src/test/java/org/postgresql/core/UTF8EncodingTest.java
+++ b/pgjdbc/src/test/java/org/postgresql/core/UTF8EncodingTest.java
@@ -17,9 +17,6 @@ import java.util.List;
public class UTF8EncodingTest {
private static final int STEP = 8 * 1024;
- public Encoding encoding;
- public String string;
- public String shortString;
public static Iterable<Object[]> data() {
final StringBuilder reallyLongString = new StringBuilder(1024 * 1024);
@@ -83,14 +80,7 @@ public class UTF8EncodingTest {
@MethodSource("data")
@ParameterizedTest(name = "string={2}, encoding={0}")
public void test(Encoding encoding, String string, String shortString) throws Exception {
- initUTF8EncodingTest(encoding, string, shortString);
final byte[] encoded = encoding.encode(string);
assertEquals(string, encoding.decode(encoded));
}
-
- public void initUTF8EncodingTest(Encoding encoding, String string, String shortString) {
- this.encoding = encoding;
- this.string = string;
- this.shortString = shortString;
- }
}
diff --git a/pgjdbc/src/test/java/org/postgresql/test/jdbc3/SqlCommandParseTest.java b/pgjdbc/src/test/java/org/postgresql/test/jdbc3/SqlCommandParseTest.java
index acdd7afc..28140888 100644
--- a/pgjdbc/src/test/java/org/postgresql/test/jdbc3/SqlCommandParseTest.java
+++ b/pgjdbc/src/test/java/org/postgresql/test/jdbc3/SqlCommandParseTest.java
@@ -20,9 +20,6 @@ import java.util.Arrays;
import java.util.List;
public class SqlCommandParseTest {
- public SqlCommandType type;
- public String sql;
-
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{SqlCommandType.INSERT, "insert/**/ into table(select) values(1)"},
@@ -43,15 +40,9 @@ public class SqlCommandParseTest {
@MethodSource("data")
@ParameterizedTest(name = "expected={0}, sql={1}")
public void run(SqlCommandType type, String sql) throws SQLException {
- initSqlCommandParseTest(type, sql);
List<NativeQuery> queries;
queries = Parser.parseJdbcSql(sql, true, true, false, true, true);
NativeQuery query = queries.get(0);
assertEquals(type, query.command.getType(), sql);
}
-
- public void initSqlCommandParseTest(SqlCommandType type, String sql) {
- this.type = type;
- this.sql = sql;
- }
}
diff --git a/pgjdbc/src/test/java/org/postgresql/test/jdbc4/ConnectionValidTimeoutTest.java b/pgjdbc/src/test/java/org/postgresql/test/jdbc4/ConnectionValidTimeoutTest.java
index 535b079f..e9fd9e77 100644
--- a/pgjdbc/src/test/java/org/postgresql/test/jdbc4/ConnectionValidTimeoutTest.java
+++ b/pgjdbc/src/test/java/org/postgresql/test/jdbc4/ConnectionValidTimeoutTest.java
@@ -12,25 +12,17 @@ import org.postgresql.test.TestUtil;
import org.postgresql.test.util.StrangeProxyServer;
import org.postgresql.test.util.rules.annotation.HaveMinimalServerVersion;
-import org.junit.Rule;
+import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
-import org.junit.rules.Timeout;
import java.sql.Connection;
import java.util.Arrays;
import java.util.Properties;
-import java.util.concurrent.TimeUnit;
@HaveMinimalServerVersion("9.4")
public class ConnectionValidTimeoutTest {
- @Rule
- public Timeout timeout = new Timeout(30, TimeUnit.SECONDS);
- public int networkTimeoutMillis;
- public int validationTimeoutSeconds;
- public int expectedMaxValidationTimeMillis;
-
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{500, 1, 600},
@@ -42,8 +34,8 @@ public class ConnectionValidTimeoutTest {
@MethodSource("data")
@ParameterizedTest(name = "networkTimeoutMillis={0}, validationTimeoutSeconds={1}, expectedMaxValidationTimeMillis={2}")
+ @Timeout(value = 30)
public void isValidRespectsSmallerTimeout(int networkTimeoutMillis, int validationTimeoutSeconds, int expectedMaxValidationTimeMillis) throws Exception {
- initConnectionValidTimeoutTest(networkTimeoutMillis, validationTimeoutSeconds, expectedMaxValidationTimeMillis);
try (StrangeProxyServer proxyServer = new StrangeProxyServer(TestUtil.getServer(), TestUtil.getPort())) {
final Properties props = new Properties();
props.setProperty(TestUtil.SERVER_HOST_PORT_PROP, String.format("%s:%s", "localhost", proxyServer.getServerPort()));
@@ -74,10 +66,4 @@ public class ConnectionValidTimeoutTest {
}
}
}
-
- public void initConnectionValidTimeoutTest(int networkTimeoutMillis, int validationTimeoutSeconds, int expectedMaxValidationTimeMillis) {
- this.networkTimeoutMillis = networkTimeoutMillis;
- this.validationTimeoutSeconds = validationTimeoutSeconds;
- this.expectedMaxValidationTimeMillis = expectedMaxValidationTimeMillis;
- }
}
diff --git a/pgjdbc/src/test/java/org/postgresql/test/ssl/CommonNameVerifierTest.java b/pgjdbc/src/test/java/org/postgresql/test/ssl/CommonNameVerifierTest.java
index 4f39c761..ae8ac5aa 100644
--- a/pgjdbc/src/test/java/org/postgresql/test/ssl/CommonNameVerifierTest.java
+++ b/pgjdbc/src/test/java/org/postgresql/test/ssl/CommonNameVerifierTest.java
@@ -14,17 +14,6 @@ import org.junit.jupiter.params.provider.MethodSource;
import java.util.Arrays;
public class CommonNameVerifierTest {
-
- private String a;
- private String b;
- private int expected;
-
- public void initCommonNameVerifierTest(String a, String b, int expected) {
- this.a = a;
- this.b = b;
- this.expected = expected;
- }
-
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{"com", "host.com", -1},
@@ -40,7 +29,6 @@ public class CommonNameVerifierTest {
@MethodSource("data")
@ParameterizedTest(name = "a={0}, b={1}")
public void comparePatterns(String a, String b, int expected) throws Exception {
- initCommonNameVerifierTest(a, b, expected);
Assertions.assertEquals(expected, PGjdbcHostnameVerifier.HOSTNAME_PATTERN_COMPARATOR.compare(a, b), a + " vs " + b);
Assertions.assertEquals(-expected, PGjdbcHostnameVerifier.HOSTNAME_PATTERN_COMPARATOR.compare(b, a), b + " vs " + a);
diff --git a/pgjdbc/src/test/java/org/postgresql/test/ssl/LibPQFactoryHostNameTest.java b/pgjdbc/src/test/java/org/postgresql/test/ssl/LibPQFactoryHostNameTest.java
index 7b300d56..aebb7f23 100644
--- a/pgjdbc/src/test/java/org/postgresql/test/ssl/LibPQFactoryHostNameTest.java
+++ b/pgjdbc/src/test/java/org/postgresql/test/ssl/LibPQFactoryHostNameTest.java
@@ -15,17 +15,6 @@ import org.junit.jupiter.params.provider.MethodSource;
import java.util.Arrays;
public class LibPQFactoryHostNameTest {
-
- private String hostname;
- private String pattern;
- private boolean expected;
-
- public void initLibPQFactoryHostNameTest(String hostname, String pattern, boolean expected) {
- this.hostname = hostname;
- this.pattern = pattern;
- this.expected = expected;
- }
-
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{"host.com", "pattern.com", false},
@@ -52,7 +41,6 @@ public class LibPQFactoryHostNameTest {
@MethodSource("data")
@ParameterizedTest(name = "host={0}, pattern={1}")
public void checkPattern(String hostname, String pattern, boolean expected) throws Exception {
- initLibPQFactoryHostNameTest(hostname, pattern, expected);
Assertions.assertEquals(expected, LibPQFactory.verifyHostName(hostname, pattern), hostname + ", pattern: " + pattern);
Assertions.assertEquals(expected, PGjdbcHostnameVerifier.INSTANCE.verifyHostName(hostname, pattern), hostname + ", pattern: " + pattern);
diff --git a/pgjdbc/src/test/java/org/postgresql/test/util/PGPropertyMaxResultBufferParserTest.java b/pgjdbc/src/test/java/org/postgresql/test/util/PGPropertyMaxResultBufferParserTest.java
index da486f4f..5727413b 100644
--- a/pgjdbc/src/test/java/org/postgresql/test/util/PGPropertyMaxResultBufferParserTest.java
+++ b/pgjdbc/src/test/java/org/postgresql/test/util/PGPropertyMaxResultBufferParserTest.java
@@ -20,9 +20,6 @@ import java.util.Arrays;
import java.util.Collection;
public class PGPropertyMaxResultBufferParserTest {
- public String valueToParse;
- public long expectedResult;
-
public static Collection<Object[]> data() {
Object[][] data = new Object[][]{
{"100", 100L},
@@ -46,7 +43,6 @@ public class PGPropertyMaxResultBufferParserTest {
@MethodSource("data")
@ParameterizedTest(name = "{index}: Test with valueToParse={0}, expectedResult={1}")
public void getMaxResultBufferValue(String valueToParse, long expectedResult) {
- initPGPropertyMaxResultBufferParserTest(valueToParse, expectedResult);
Assertions.assertDoesNotThrow(() -> {
long result = PGPropertyMaxResultBufferParser.parseProperty(valueToParse);
Assertions.assertEquals(expectedResult, result);
@@ -56,16 +52,9 @@ public class PGPropertyMaxResultBufferParserTest {
@MethodSource("data")
@ParameterizedTest(name = "{index}: Test with valueToParse={0}, expectedResult={1}")
public void getMaxResultBufferValueException(String valueToParse, long expectedResult) throws PSQLException {
- initPGPropertyMaxResultBufferParserTest(valueToParse, expectedResult);
assertThrows(PSQLException.class, () -> {
long result = PGPropertyMaxResultBufferParser.parseProperty("abc");
fail();
});
}
-
- public void initPGPropertyMaxResultBufferParserTest(String valueToParse, long expectedResult) {
- this.valueToParse = valueToParse;
- this.expectedResult = expectedResult;
- }
-
}
diff --git a/pgjdbc/src/test/java/org/postgresql/test/util/ServerVersionParseTest.java b/pgjdbc/src/test/java/org/postgresql/test/util/ServerVersionParseTest.java
index acc5c66f..5a45f526 100644
--- a/pgjdbc/src/test/java/org/postgresql/test/util/ServerVersionParseTest.java
+++ b/pgjdbc/src/test/java/org/postgresql/test/util/ServerVersionParseTest.java
@@ -15,17 +15,6 @@ import org.junit.jupiter.params.provider.MethodSource;
import java.util.Arrays;
public class ServerVersionParseTest {
-
- private String versionString;
- private int versionNum;
- private String rejectReason;
-
- public void initServerVersionParseTest(String versionString, int versionNum, String rejectReason) {
- this.versionString = versionString;
- this.versionNum = versionNum;
- this.rejectReason = rejectReason;
- }
-
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
/* 4 part version tests */
@@ -81,7 +70,6 @@ public class ServerVersionParseTest {
@MethodSource("data")
@ParameterizedTest(name = "str = {0}, expected = {1}")
public void run(String versionString, int versionNum, String rejectReason) {
- initServerVersionParseTest(versionString, versionNum, rejectReason);
try {
Version version = ServerVersion.from(versionString);
if (rejectReason == null) {
[parent: 62979127d26c]