Skip to content
Permalink
Browse files

test: migrate tests to JUnit 4

fixes #738
fixes #205
  • Loading branch information
AlexElin authored and vlsi committed Jul 23, 2017
1 parent c1d743f commit 5b65e2f45b1cb130b4380b31ff6c0c73210d9fe0
Showing with 358 additions and 450 deletions.
  1. +1 −0 pgjdbc/src/main/java/org/postgresql/util/PSQLState.java
  2. +20 −25 pgjdbc/src/test/java/org/postgresql/core/v3/V3ParameterListTests.java
  3. +13 −7 pgjdbc/src/test/java/org/postgresql/jdbc/DeepBatchedInsertStatementTest.java
  4. +0 −21 pgjdbc/src/test/java/org/postgresql/test/CursorFetchBinaryTest.java
  5. +18 −16 pgjdbc/src/test/java/org/postgresql/test/README.md
  6. +16 −0 pgjdbc/src/test/java/org/postgresql/test/TestUtil.java
  7. +0 −57 pgjdbc/src/test/java/org/postgresql/test/jdbc2/BaseTest.java
  8. +45 −11 pgjdbc/src/test/java/org/postgresql/test/jdbc2/CursorFetchTest.java
  9. +4 −7 pgjdbc/src/test/java/org/postgresql/test/jdbc2/Jdbc2TestSuite.java
  10. +0 −22 pgjdbc/src/test/java/org/postgresql/test/jdbc2/UpsertBinaryTest.java
  11. +31 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc2/UpsertTest.java
  12. +5 −22 pgjdbc/src/test/java/org/postgresql/test/jdbc3/Jdbc3CallableStatementTest.java
  13. +16 −30 pgjdbc/src/test/java/org/postgresql/test/jdbc3/Jdbc3TestSuite.java
  14. +90 −82 pgjdbc/src/test/java/org/postgresql/test/jdbc3/StringTypeParameterTest.java
  15. +21 −35 pgjdbc/src/test/java/org/postgresql/test/jdbc4/ClientInfoTest.java
  16. +24 −30 pgjdbc/src/test/java/org/postgresql/test/jdbc4/IsValidTest.java
  17. +7 −22 pgjdbc/src/test/java/org/postgresql/test/jdbc4/jdbc41/AbortTest.java
  18. +0 −21 pgjdbc/src/test/java/org/postgresql/test/jdbc42/GetObject310BinaryTest.java
  19. +34 −6 pgjdbc/src/test/java/org/postgresql/test/jdbc42/GetObject310Test.java
  20. +0 −1 pgjdbc/src/test/java/org/postgresql/test/jdbc42/Jdbc42TestSuite.java
  21. +10 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc42/PreparedStatementTest.java
  22. +3 −19 pgjdbc/src/test/java/org/postgresql/test/jdbc42/SimpleJdbc42Test.java
@@ -80,6 +80,7 @@
DATA_TYPE_MISMATCH("42821"),
UNDEFINED_FUNCTION("42883"),
INVALID_NAME("42602"),
DATATYPE_MISMATCH("42804"),
CANNOT_COERCE("42846"),

OUT_OF_MEMORY("53200"),
@@ -5,9 +5,10 @@

package org.postgresql.core.v3;

import org.postgresql.test.jdbc2.BaseTest;
import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import java.sql.SQLException;

@@ -17,7 +18,23 @@
* @author Jeremy Whiting jwhiting@redhat.com
*
*/
public class V3ParameterListTests extends BaseTest {
public class V3ParameterListTests {
private TypeTransferModeRegistry transferModeRegistry;

@Before
public void setUp() throws Exception {
transferModeRegistry = new TypeTransferModeRegistry() {
@Override
public boolean useBinaryForSend(int oid) {
return false;
}

@Override
public boolean useBinaryForReceive(int oid) {
return false;
}
};
}

/**
* Test to check the merging of two collections of parameters. All elements
@@ -26,6 +43,7 @@
* @throws SQLException
* raised exception if setting parameter fails.
*/
@Test
public void testMergeOfParameterLists() throws SQLException {
SimpleParameterList s1SPL = new SimpleParameterList(8, transferModeRegistry);
s1SPL.setIntParameter(1, 1);
@@ -44,27 +62,4 @@ public void testMergeOfParameterLists() throws SQLException {
"Expected string representation of values does not match outcome.",
"<[1 ,2 ,3 ,4 ,5 ,6 ,7 ,8]>", s1SPL.toString());
}

public V3ParameterListTests(String test) {
super(test);
}

private TypeTransferModeRegistry transferModeRegistry;

@Override
@Before
protected void setUp() throws Exception {
transferModeRegistry =
new TypeTransferModeRegistry() {
@Override
public boolean useBinaryForSend(int oid) {
return false;
}

@Override
public boolean useBinaryForReceive(int oid) {
return false;
}
};
}
}
@@ -5,14 +5,18 @@

package org.postgresql.jdbc;

import static org.junit.Assert.assertEquals;

import org.postgresql.PGProperty;
import org.postgresql.core.ParameterList;
import org.postgresql.core.Query;
import org.postgresql.core.v3.BatchedQuery;
import org.postgresql.test.TestUtil;
import org.postgresql.test.jdbc2.BaseTest;
import org.postgresql.test.jdbc2.BaseTest4;
import org.postgresql.test.jdbc2.BatchExecuteTest;

import org.junit.Test;

import java.lang.reflect.Method;
import java.sql.Date;
import java.sql.SQLException;
@@ -25,16 +29,14 @@
* execution. Rather than rely on testing at the jdbc api layer.
* on.
*/
public class DeepBatchedInsertStatementTest extends BaseTest {
public DeepBatchedInsertStatementTest(String name) {
super(name);
}
public class DeepBatchedInsertStatementTest extends BaseTest4 {

/*
* Set up the fixture for this testcase: a connection to a database with a
* table for this test.
*/
protected void setUp() throws Exception {
@Override
public void setUp() throws Exception {
super.setUp();
Statement stmt = con.createStatement();

@@ -56,7 +58,8 @@ protected void setUp() throws Exception {
}

// Tear down the fixture for this test case.
protected void tearDown() throws SQLException {
@Override
public void tearDown() throws SQLException {
TestUtil.dropTable(con, "testbatch");
TestUtil.dropTable(con, "testunspecified");
super.tearDown();
@@ -68,6 +71,7 @@ protected void updateProperties(Properties props) {
forceBinary(props);
}

@Test
public void testDeepInternalsBatchedQueryDecorator() throws Exception {
PgPreparedStatement pstmt = null;
try {
@@ -200,6 +204,7 @@ public void testDeepInternalsBatchedQueryDecorator() throws Exception {
/**
*
*/
@Test
public void testUnspecifiedParameterType() throws Exception {
PgPreparedStatement pstmt = null;
try {
@@ -233,6 +238,7 @@ public void testUnspecifiedParameterType() throws Exception {
* Test to check the statement can provide the necessary number of prepared
* type fields. This is after running with a batch size of 1.
*/
@Test
public void testVaryingTypeCounts() throws SQLException {
PgPreparedStatement pstmt = null;
try {

This file was deleted.

@@ -123,20 +123,16 @@ The recommended pattern for creating and dropping tables can be
found in the example in section 7 below.

Please note that JUnit provides several convenience methods to
check for conditions. See the TestCase class in the Javadoc
check for conditions. See the Assert class in the Javadoc
documentation of JUnit, which is installed on your system. For
example, you can compare two integers using
TestCase.assertEquals(int expected, int actual). This method
Assert.assertEquals(int expected, int actual). This method
will print both values in case of a failure.

To simply report a failure use TestCase.fail().
To simply report a failure use Assert.fail().

The JUnit FAQ explains how to test for a thrown exception.

Avoid the use of the deprecated TestCase.assert(), since it
collides with the new assert keyword in the Java 2 platform
version 1.4.

As a rule, the test suite should succeed. Any errors or failures
- which may be caused by bugs in the JDBC driver, the backend or
the test suite - should be fixed ASAP. Don't let a test fail
@@ -155,23 +151,26 @@ behaviour or the intended implementation of a feature?
----------------------
package org.postgresql.test.jdbc2;

import static org.junit.Assert.assertNotNull;

import org.postgresql.test.TestUtil;
import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.sql.*;

/*
* Test case for ...
*/
public class FooTest extends TestCase {
public class FooTest {

private Connection con;
private Statement stmt;

public FooTest(String name) {
super(name);
}

protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
con = TestUtil.openDB();
stmt = con.createStatement();

@@ -194,7 +193,8 @@ public class FooTest extends TestCase {
// the use of transactions.
}

protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
con.setAutoCommit(true);
if (stmt != null) {
stmt.executeUpdate("DROP TABLE testfoo");
@@ -205,8 +205,9 @@ public class FooTest extends TestCase {
}
}

@Test
public void testFoo() {
// Use the assert methods in junit.framework.TestCase
// Use the assert methods in import org.junit.Assert
// for the actual tests

// Just some silly examples
@@ -216,6 +217,7 @@ public class FooTest extends TestCase {
}
}

@Test
public void testBar() {
// Another test.
}
@@ -614,13 +614,19 @@ public static String fix(int v, int l) {
}

public static String escapeString(Connection con, String value) throws SQLException {
if (con == null) {
throw new NullPointerException("Connection is null");
}
if (con instanceof PgConnection) {
return ((PgConnection) con).escapeString(value);
}
return value;
}

public static boolean getStandardConformingStrings(Connection con) {
if (con == null) {
throw new NullPointerException("Connection is null");
}
if (con instanceof PgConnection) {
return ((PgConnection) con).getStandardConformingStrings();
}
@@ -633,6 +639,9 @@ public static boolean getStandardConformingStrings(Connection con) {
* connection.
*/
public static boolean haveMinimumServerVersion(Connection con, int version) throws SQLException {
if (con == null) {
throw new NullPointerException("Connection is null");
}
if (con instanceof PgConnection) {
return ((PgConnection) con).haveMinimumServerVersion(version);
}
@@ -641,6 +650,9 @@ public static boolean haveMinimumServerVersion(Connection con, int version) thro

public static boolean haveMinimumServerVersion(Connection con, Version version)
throws SQLException {
if (con == null) {
throw new NullPointerException("Connection is null");
}
if (con instanceof PgConnection) {
return ((PgConnection) con).haveMinimumServerVersion(version);
}
@@ -652,7 +664,11 @@ public static boolean haveMinimumJVMVersion(String version) {
return (jvm.compareTo(version) >= 0);
}

@Deprecated
public static boolean isProtocolVersion(Connection con, int version) {
if (con == null) {
throw new NullPointerException("Connection is null");
}
if (con instanceof PgConnection) {
return (version == ((PgConnection) con).getProtocolVersion());

This file was deleted.

0 comments on commit 5b65e2f

Please sign in to comment.
You can’t perform that action at this time.