Skip to content
Permalink
Browse files

refactor: migrate to Junit4 (#682)

migrate to Junit4 in some tests

#205
  • Loading branch information
AlexElin authored and davecramer committed Nov 9, 2016
1 parent 64b6750 commit f4a067cc5d32dde2698a062d6f9855d50fa3127d
Showing with 624 additions and 383 deletions.
  1. +49 −41 pgjdbc/src/test/java/org/postgresql/core/ParserTest.java
  2. +8 −7 pgjdbc/src/test/java/org/postgresql/test/jdbc2/ANTTest.java
  3. +21 −9 pgjdbc/src/test/java/org/postgresql/test/jdbc2/ColumnSanitiserDisabledTest.java
  4. +19 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc2/ColumnSanitiserEnabledTest.java
  5. +24 −15 pgjdbc/src/test/java/org/postgresql/test/jdbc2/ConnectionTest.java
  6. +25 −13 pgjdbc/src/test/java/org/postgresql/test/jdbc2/DatabaseMetaDataPropertiesTest.java
  7. +57 −13 pgjdbc/src/test/java/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java
  8. +14 −9 pgjdbc/src/test/java/org/postgresql/test/jdbc2/DateTest.java
  9. +20 −16 pgjdbc/src/test/java/org/postgresql/test/jdbc2/DriverTest.java
  10. +9 −10 pgjdbc/src/test/java/org/postgresql/test/jdbc2/EncodingTest.java
  11. +36 −23 pgjdbc/src/test/java/org/postgresql/test/jdbc2/IntervalTest.java
  12. +15 −15 pgjdbc/src/test/java/org/postgresql/test/jdbc2/Jdbc2TestSuite.java
  13. +19 −16 pgjdbc/src/test/java/org/postgresql/test/jdbc2/PGTimestampTest.java
  14. +12 −12 pgjdbc/src/test/java/org/postgresql/test/jdbc2/SearchPathLookupTest.java
  15. +15 −9 pgjdbc/src/test/java/org/postgresql/test/jdbc2/TimeTest.java
  16. +19 −9 pgjdbc/src/test/java/org/postgresql/test/jdbc2/TimestampTest.java
  17. +32 −25 pgjdbc/src/test/java/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java
  18. +18 −15 pgjdbc/src/test/java/org/postgresql/test/jdbc2/optional/CaseOptimiserDataSourceTest.java
  19. +44 −23 pgjdbc/src/test/java/org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java
  20. +14 −12 pgjdbc/src/test/java/org/postgresql/test/jdbc2/optional/OptionalTestSuite.java
  21. +16 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java
  22. +1 −6 pgjdbc/src/test/java/org/postgresql/test/jdbc2/optional/SimpleDataSourceTest.java
  23. +1 −7 pgjdbc/src/test/java/org/postgresql/test/jdbc2/optional/SimpleDataSourceWithUrlTest.java
  24. +2 −0 pgjdbc/src/test/java/org/postgresql/test/jdbc4/ArrayTest.java
  25. +2 −0 pgjdbc/src/test/java/org/postgresql/test/jdbc4/JsonbTest.java
  26. +13 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc4/jdbc41/AbortTest.java
  27. +15 −9 pgjdbc/src/test/java/org/postgresql/test/jdbc4/jdbc41/CloseOnCompletionTest.java
  28. +54 −16 pgjdbc/src/test/java/org/postgresql/test/jdbc4/jdbc41/GetObjectTest.java
  29. +16 −15 pgjdbc/src/test/java/org/postgresql/test/jdbc4/jdbc41/Jdbc41TestSuite.java
  30. +19 −10 pgjdbc/src/test/java/org/postgresql/test/jdbc4/jdbc41/SchemaTest.java
  31. +15 −4 pgjdbc/src/test/java/org/postgresql/test/util/LruCacheTest.java
@@ -5,124 +5,132 @@

package org.postgresql.core;

import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.Assert;
import org.junit.Test;

/**
* Test cases for the Parser.
* @author Jeremy Whiting jwhiting@redhat.com
*/
public class ParserTest extends TestCase {
public class ParserTest {

/**
* Test to make sure delete command is detected by parser and detected via
* api. Mix up the case of the command to check detection continues to work.
*/
@Test
public void testDeleteCommandParsing() {
char[] command = new char[6];
"DELETE".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse upper case command.", Parser.parseDeleteKeyword(command, 0));
assertTrue("Failed to correctly parse upper case command.", Parser.parseDeleteKeyword(command, 0));
"DelEtE".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseDeleteKeyword(command, 0));
assertTrue("Failed to correctly parse mixed case command.", Parser.parseDeleteKeyword(command, 0));
"deleteE".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseDeleteKeyword(command, 0));
assertTrue("Failed to correctly parse mixed case command.", Parser.parseDeleteKeyword(command, 0));
"delete".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse lower case command.", Parser.parseDeleteKeyword(command, 0));
assertTrue("Failed to correctly parse lower case command.", Parser.parseDeleteKeyword(command, 0));
"Delete".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseDeleteKeyword(command, 0));
assertTrue("Failed to correctly parse mixed case command.", Parser.parseDeleteKeyword(command, 0));
}

/**
* Test UPDATE command parsing.
*/
@Test
public void testUpdateCommandParsing() {
char[] command = new char[6];
"UPDATE".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse upper case command.", Parser.parseUpdateKeyword(command, 0));
assertTrue("Failed to correctly parse upper case command.", Parser.parseUpdateKeyword(command, 0));
"UpDateE".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseUpdateKeyword(command, 0));
assertTrue("Failed to correctly parse mixed case command.", Parser.parseUpdateKeyword(command, 0));
"updatE".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseUpdateKeyword(command, 0));
assertTrue("Failed to correctly parse mixed case command.", Parser.parseUpdateKeyword(command, 0));
"Update".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseUpdateKeyword(command, 0));
assertTrue("Failed to correctly parse mixed case command.", Parser.parseUpdateKeyword(command, 0));
"update".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse lower case command.", Parser.parseUpdateKeyword(command, 0));
assertTrue("Failed to correctly parse lower case command.", Parser.parseUpdateKeyword(command, 0));
}

/**
* Test MOVE command parsing.
*/
@Test
public void testMoveCommandParsing() {
char[] command = new char[4];
"MOVE".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse upper case command.", Parser.parseMoveKeyword(command, 0));
assertTrue("Failed to correctly parse upper case command.", Parser.parseMoveKeyword(command, 0));
"mOVe".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseMoveKeyword(command, 0));
assertTrue("Failed to correctly parse mixed case command.", Parser.parseMoveKeyword(command, 0));
"movE".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseMoveKeyword(command, 0));
assertTrue("Failed to correctly parse mixed case command.", Parser.parseMoveKeyword(command, 0));
"Move".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseMoveKeyword(command, 0));
assertTrue("Failed to correctly parse mixed case command.", Parser.parseMoveKeyword(command, 0));
"move".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse lower case command.", Parser.parseMoveKeyword(command, 0));
assertTrue("Failed to correctly parse lower case command.", Parser.parseMoveKeyword(command, 0));
}

/**
* Test WITH command parsing.
*/
@Test
public void testWithCommandParsing() {
char[] command = new char[4];
"WITH".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse upper case command.", Parser.parseWithKeyword(command, 0));
assertTrue("Failed to correctly parse upper case command.", Parser.parseWithKeyword(command, 0));
"wITh".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseWithKeyword(command, 0));
assertTrue("Failed to correctly parse mixed case command.", Parser.parseWithKeyword(command, 0));
"witH".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseWithKeyword(command, 0));
assertTrue("Failed to correctly parse mixed case command.", Parser.parseWithKeyword(command, 0));
"With".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseWithKeyword(command, 0));
assertTrue("Failed to correctly parse mixed case command.", Parser.parseWithKeyword(command, 0));
"with".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse lower case command.", Parser.parseWithKeyword(command, 0));
assertTrue("Failed to correctly parse lower case command.", Parser.parseWithKeyword(command, 0));
}

/**
* Test SELECT command parsing.
*/
@Test
public void testSelectCommandParsing() {
char[] command = new char[6];
"SELECT".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse upper case command.", Parser.parseSelectKeyword(command, 0));
assertTrue("Failed to correctly parse upper case command.", Parser.parseSelectKeyword(command, 0));
"sELect".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseSelectKeyword(command, 0));
assertTrue("Failed to correctly parse mixed case command.", Parser.parseSelectKeyword(command, 0));
"selecT".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseSelectKeyword(command, 0));
assertTrue("Failed to correctly parse mixed case command.", Parser.parseSelectKeyword(command, 0));
"Select".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseSelectKeyword(command, 0));
assertTrue("Failed to correctly parse mixed case command.", Parser.parseSelectKeyword(command, 0));
"select".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse lower case command.", Parser.parseSelectKeyword(command, 0));
assertTrue("Failed to correctly parse lower case command.", Parser.parseSelectKeyword(command, 0));
}

@Test
public void testEscapeProcessing() throws Exception {
Assert.assertEquals("DATE '1999-01-09'", Parser.replaceProcessing("{d '1999-01-09'}", true, false));
Assert.assertEquals("DATE '1999-01-09'", Parser.replaceProcessing("{D '1999-01-09'}", true, false));
Assert.assertEquals("TIME '20:00:03'", Parser.replaceProcessing("{t '20:00:03'}", true, false));
Assert.assertEquals("TIME '20:00:03'", Parser.replaceProcessing("{T '20:00:03'}", true, false));
Assert.assertEquals("TIMESTAMP '1999-01-09 20:11:11.123455'", Parser.replaceProcessing("{ts '1999-01-09 20:11:11.123455'}", true, false));
Assert.assertEquals("TIMESTAMP '1999-01-09 20:11:11.123455'", Parser.replaceProcessing("{Ts '1999-01-09 20:11:11.123455'}", true, false));
assertEquals("DATE '1999-01-09'", Parser.replaceProcessing("{d '1999-01-09'}", true, false));
assertEquals("DATE '1999-01-09'", Parser.replaceProcessing("{D '1999-01-09'}", true, false));
assertEquals("TIME '20:00:03'", Parser.replaceProcessing("{t '20:00:03'}", true, false));
assertEquals("TIME '20:00:03'", Parser.replaceProcessing("{T '20:00:03'}", true, false));
assertEquals("TIMESTAMP '1999-01-09 20:11:11.123455'", Parser.replaceProcessing("{ts '1999-01-09 20:11:11.123455'}", true, false));
assertEquals("TIMESTAMP '1999-01-09 20:11:11.123455'", Parser.replaceProcessing("{Ts '1999-01-09 20:11:11.123455'}", true, false));

Assert.assertEquals("user", Parser.replaceProcessing("{fn user()}", true, false));
Assert.assertEquals("cos(1)", Parser.replaceProcessing("{fn cos(1)}", true, false));
Assert.assertEquals("extract(week from DATE '2005-01-24')", Parser.replaceProcessing("{fn week({d '2005-01-24'})}", true, false));
assertEquals("user", Parser.replaceProcessing("{fn user()}", true, false));
assertEquals("cos(1)", Parser.replaceProcessing("{fn cos(1)}", true, false));
assertEquals("extract(week from DATE '2005-01-24')", Parser.replaceProcessing("{fn week({d '2005-01-24'})}", true, false));

Assert.assertEquals("\"T1\" LEFT OUTER JOIN t2 ON \"T1\".id = t2.id",
assertEquals("\"T1\" LEFT OUTER JOIN t2 ON \"T1\".id = t2.id",
Parser.replaceProcessing("{oj \"T1\" LEFT OUTER JOIN t2 ON \"T1\".id = t2.id}", true, false));

Assert.assertEquals("ESCAPE '_'", Parser.replaceProcessing("{escape '_'}", true, false));
assertEquals("ESCAPE '_'", Parser.replaceProcessing("{escape '_'}", true, false));

// nothing should be changed in that case, no valid escape code
Assert.assertEquals("{obj : 1}", Parser.replaceProcessing("{obj : 1}", true, false));
assertEquals("{obj : 1}", Parser.replaceProcessing("{obj : 1}", true, false));
}

@Test
public void testUnterminatedEscape() throws Exception {
Assert.assertEquals("{oj ", Parser.replaceProcessing("{oj ", true, false));
assertEquals("{oj ", Parser.replaceProcessing("{oj ", true, false));
}
}
@@ -5,16 +5,17 @@

package org.postgresql.test.jdbc2;

import junit.framework.TestCase;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;

public class ANTTest extends TestCase {
public ANTTest(String name) {
super(name);
}
import org.junit.Test;

public class ANTTest {

/*
* This tests the acceptsURL() method with a couple of good and badly formed jdbc urls
*/
@Test
public void testANT() {
String url = System.getProperty("database");
String usr = System.getProperty("username");
@@ -24,7 +25,7 @@ public void testANT() {
assertNotNull(usr);
assertNotNull(psw);

assertTrue(!url.equals(""));
assertTrue(!usr.equals(""));
assertFalse(url.isEmpty());
assertFalse(usr.isEmpty());
}
}
@@ -5,10 +5,15 @@

package org.postgresql.test.jdbc2;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.postgresql.core.BaseConnection;
import org.postgresql.test.TestUtil;

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

import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -20,14 +25,11 @@
* This test suite will check the behaviour of the findColumnIndex method. This is testing the
* behaviour when sanitiser is disabled.
*/
public class ColumnSanitiserDisabledTest extends TestCase {
public class ColumnSanitiserDisabledTest {
private Connection conn;

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

protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
Properties props = new Properties();
props.setProperty("disableColumnSanitiser", Boolean.TRUE.toString());
conn = TestUtil.openDB(props);
@@ -46,7 +48,8 @@ protected void setUp() throws Exception {
data.close();
}

protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
TestUtil.dropTable(conn, "allmixedup");
TestUtil.closeDB(conn);
System.setProperty("disableColumnSanitiser", "false");
@@ -57,45 +60,54 @@ protected void tearDown() throws Exception {
* application supplied column names.
*/

@Test
public void testTableColumnLowerNowFindFindLowerCaseColumn() throws SQLException {
findColumn("id", true);
}

@Test
public void testTableColumnLowerNowFindFindUpperCaseColumn() throws SQLException {
findColumn("ID", true);
}

@Test
public void testTableColumnLowerNowFindFindMixedCaseColumn() throws SQLException {
findColumn("Id", false);
}

@Test
public void testTableColumnUpperNowFindFindLowerCaseColumn() throws SQLException {
findColumn("description", true);
}

@Test
public void testTableColumnUpperNowFindFindUpperCaseColumn() throws SQLException {
findColumn("DESCRIPTION", true);
}

@Test
public void testTableColumnUpperNowFindFindMixedCaseColumn() throws SQLException {
findColumn("Description", false);
}

@Test
public void testTableColumnMixedNowFindLowerCaseColumn() throws SQLException {
findColumn("foo", false);
}

@Test
public void testTableColumnMixedNowFindFindUpperCaseColumn() throws SQLException {
findColumn("FOO", false);
}

@Test
public void testTableColumnMixedNowFindFindMixedCaseColumn() throws SQLException {
findColumn("fOo", true);
}

private void findColumn(String label, boolean failOnNotFound) throws SQLException {
PreparedStatement query = conn.prepareStatement("select * from allmixedup");
if (0 == TestUtil.findColumn(query, label) && failOnNotFound) {
if ((TestUtil.findColumn(query, label) == 0) && failOnNotFound) {
fail(String.format("Expected to find the column with the label [%1$s].", label));
}
query.close();
@@ -5,10 +5,15 @@

package org.postgresql.test.jdbc2;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.postgresql.core.BaseConnection;
import org.postgresql.test.TestUtil;

import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -20,14 +25,11 @@
* This test suite will check the behaviour of the findColumnIndex method. The tests will check the
* behaviour of the method when the sanitiser is enabled. Default behaviour of the driver.
*/
public class ColumnSanitiserEnabledTest extends TestCase {
public class ColumnSanitiserEnabledTest {
private Connection conn;

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

protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
Properties props = new Properties();
props.setProperty("disableColumnSanitiser", Boolean.FALSE.toString());
conn = TestUtil.openDB(props);
@@ -52,45 +54,54 @@ protected void tearDown() throws Exception {
* application supplied column names.
*/

@Test
public void testTableColumnLowerNowFindFindLowerCaseColumn() throws SQLException {
findColumn("id", true);
}

@Test
public void testTableColumnLowerNowFindFindUpperCaseColumn() throws SQLException {
findColumn("ID", true);
}

@Test
public void testTableColumnLowerNowFindFindMixedCaseColumn() throws SQLException {
findColumn("Id", true);
}

@Test
public void testTableColumnUpperNowFindFindLowerCaseColumn() throws SQLException {
findColumn("description", true);
}

@Test
public void testTableColumnUpperNowFindFindUpperCaseColumn() throws SQLException {
findColumn("DESCRIPTION", true);
}

@Test
public void testTableColumnUpperNowFindFindMixedCaseColumn() throws SQLException {
findColumn("Description", true);
}

@Test
public void testTableColumnMixedNowFindLowerCaseColumn() throws SQLException {
findColumn("foo", true);
}

@Test
public void testTableColumnMixedNowFindFindUpperCaseColumn() throws SQLException {
findColumn("FOO", true);
}

@Test
public void testTableColumnMixedNowFindFindMixedCaseColumn() throws SQLException {
findColumn("fOo", true);
}

private void findColumn(String label, boolean failOnNotFound) throws SQLException {
PreparedStatement query = conn.prepareStatement("select * from allmixedup");
if (0 == TestUtil.findColumn(query, label) && failOnNotFound) {
if ((TestUtil.findColumn(query, label) == 0) && failOnNotFound) {
fail(String.format("Expected to find the column with the label [%1$s].", label));
}
query.close();

0 comments on commit f4a067c

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