diff --git a/test/jdk/java/sql/driverModuleTests/DriverManagerModuleTests.java b/test/jdk/java/sql/driverModuleTests/DriverManagerModuleTests.java index aad39cdb1dd..330893499d7 100644 --- a/test/jdk/java/sql/driverModuleTests/DriverManagerModuleTests.java +++ b/test/jdk/java/sql/driverModuleTests/DriverManagerModuleTests.java @@ -25,40 +25,43 @@ import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; import java.sql.SQLException; -import static org.testng.Assert.*; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; /* * @test * @library /java/sql/modules * @build luckydogdriver/* mystubdriver/* - * @run testng/othervm DriverManagerModuleTests + * @run junit/othervm DriverManagerModuleTests * @summary Tests that a JDBC Driver that is a module can be loaded * via the service-provider loading mechanism. */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class DriverManagerModuleTests { private final String LUCKYDOGDRIVER_URL = "jdbc:tennis:myDB"; private static final String STUBDRIVERURL = "jdbc:stub:myDB"; private static final String CONNECTION_CLASS_NAME = "com.luckydogtennis.StubConnection"; - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { } - @AfterClass + @AfterAll public static void tearDownClass() throws Exception { } - @BeforeMethod + @BeforeEach public void setUpMethod() throws Exception { } - @AfterMethod + @AfterEach public void tearDownMethod() throws Exception { } diff --git a/test/jdk/java/sql/testng/test/sql/BatchUpdateExceptionTests.java b/test/jdk/java/sql/testng/test/sql/BatchUpdateExceptionTests.java index 2b1111b7526..15875384084 100644 --- a/test/jdk/java/sql/testng/test/sql/BatchUpdateExceptionTests.java +++ b/test/jdk/java/sql/testng/test/sql/BatchUpdateExceptionTests.java @@ -28,11 +28,15 @@ import java.io.ObjectInputStream; import java.sql.BatchUpdateException; import java.sql.SQLException; import java.util.Arrays; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.SerializedBatchUpdateException; import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class BatchUpdateExceptionTests extends BaseTest { private final int[] uc = {1, 2, 3}; diff --git a/test/jdk/java/sql/testng/test/sql/CallableStatementTests.java b/test/jdk/java/sql/testng/test/sql/CallableStatementTests.java index 7a4fe15ecac..ba14ccef96c 100644 --- a/test/jdk/java/sql/testng/test/sql/CallableStatementTests.java +++ b/test/jdk/java/sql/testng/test/sql/CallableStatementTests.java @@ -22,26 +22,31 @@ */ package test.sql; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import util.BaseTest; import util.StubConnection; import java.sql.CallableStatement; import java.sql.SQLException; -import static org.testng.Assert.assertEquals; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class CallableStatementTests extends BaseTest { private CallableStatement cstmt; - @BeforeMethod + @BeforeEach public void setUpMethod() throws Exception { cstmt = new StubConnection().prepareCall("{call SuperHero_Proc(?)}"); } - @AfterMethod + @AfterEach public void tearDownMethod() throws Exception { cstmt.close(); } @@ -50,80 +55,94 @@ public class CallableStatementTests extends BaseTest { * Verify that enquoteLiteral creates a valid literal and converts every * single quote to two single quotes */ - @Test(dataProvider = "validEnquotedLiteralValues") + @ParameterizedTest + @MethodSource("validEnquotedLiteralValues") public void test00(String s, String expected) throws SQLException { - assertEquals(cstmt.enquoteLiteral(s), expected); + assertEquals(expected, cstmt.enquoteLiteral(s)); } /* * Validate a NullPointerException is thrown if the string passed to * enquoteLiteral is null */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test01() throws SQLException { - cstmt.enquoteLiteral(null); + Assertions.assertThrows(NullPointerException.class, () -> { + cstmt.enquoteLiteral(null); + }); } /* * Validate that enquoteIdentifier returns the expected value */ - @Test(dataProvider = "validIdentifierValues") + @ParameterizedTest + @MethodSource("validEnquotedIdentifierValues") public void test02(String s, boolean alwaysQuote, String expected) throws SQLException { - assertEquals(cstmt.enquoteIdentifier(s, alwaysQuote), expected); + assertEquals(expected, cstmt.enquoteIdentifier(s, alwaysQuote)); } /* * Validate that a SQLException is thrown for values that are not valid * for a SQL identifier */ - @Test(dataProvider = "invalidIdentifierValues", - expectedExceptions = SQLException.class) + @ParameterizedTest + @MethodSource("invalidEnquotedIdentifierValues") public void test03(String s, boolean alwaysQuote) throws SQLException { - cstmt.enquoteIdentifier(s, alwaysQuote); + Assertions.assertThrows(SQLException.class, () -> { + cstmt.enquoteIdentifier(s, alwaysQuote); + }); } /* * Validate a NullPointerException is thrown is the string passed to * enquoteIdentiifer is null */ - @Test(dataProvider = "trueFalse", - expectedExceptions = NullPointerException.class) + @ParameterizedTest + @MethodSource("trueFalse") public void test04(boolean alwaysQuote) throws SQLException { - cstmt.enquoteIdentifier(null, alwaysQuote); + Assertions.assertThrows(NullPointerException.class, () -> { + cstmt.enquoteIdentifier(null, alwaysQuote); + }); } /* * Validate that isSimpleIdentifier returns the expected value */ - @Test(dataProvider = "simpleIdentifierValues") + @ParameterizedTest + @MethodSource("simpleIdentifierValues") public void test05(String s, boolean expected) throws SQLException { - assertEquals(cstmt.isSimpleIdentifier(s), expected); + assertEquals(expected, cstmt.isSimpleIdentifier(s)); } /* * Validate a NullPointerException is thrown if the string passed to * isSimpleIdentifier is null */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test06() throws SQLException { - cstmt.isSimpleIdentifier(null); + Assertions.assertThrows(NullPointerException.class, () -> { + cstmt.isSimpleIdentifier(null); + }); } /* * Verify that enquoteLiteral creates a valid literal and converts every * single quote to two single quotes */ - @Test(dataProvider = "validEnquotedNCharLiteralValues") + @ParameterizedTest + @MethodSource("validEnquotedNCharLiteralValues") public void test07(String s, String expected) throws SQLException { - assertEquals(cstmt.enquoteNCharLiteral(s), expected); + assertEquals(expected, cstmt.enquoteNCharLiteral(s)); } /* * Validate a NullPointerException is thrown if the string passed to * enquoteNCharLiteral is null */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test08() throws SQLException { - cstmt.enquoteNCharLiteral(null); + Assertions.assertThrows(NullPointerException.class, () -> { + cstmt.enquoteNCharLiteral(null); + }); } } diff --git a/test/jdk/java/sql/testng/test/sql/ConnectionTests.java b/test/jdk/java/sql/testng/test/sql/ConnectionTests.java index f40c2784e4a..c42885ec5eb 100644 --- a/test/jdk/java/sql/testng/test/sql/ConnectionTests.java +++ b/test/jdk/java/sql/testng/test/sql/ConnectionTests.java @@ -22,20 +22,25 @@ */ package test.sql; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import util.BaseTest; import util.StubConnection; import java.sql.SQLException; -import static org.testng.Assert.*; +import org.junit.jupiter.api.Assertions; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class ConnectionTests extends BaseTest { protected StubConnection conn; - @BeforeMethod + @BeforeEach public void setUpMethod() throws Exception { conn = new StubConnection(); } @@ -44,80 +49,94 @@ public class ConnectionTests extends BaseTest { * Verify that enquoteLiteral creates a valid literal and converts every * single quote to two single quotes */ - @Test(dataProvider = "validEnquotedLiteralValues") + @ParameterizedTest + @MethodSource("validEnquotedLiteralValues") public void test00(String s, String expected) throws SQLException { - assertEquals(conn.enquoteLiteral(s), expected); + assertEquals(expected, conn.enquoteLiteral(s)); } /* * Validate a NullPointerException is thrown if the string passed to * enquoteLiteral is null */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test01() throws SQLException { - conn.enquoteLiteral(null); + Assertions.assertThrows(NullPointerException.class, () -> { + conn.enquoteLiteral(null); + }); } /* * Validate that enquoteIdentifier returns the expected value */ - @Test(dataProvider = "validIdentifierValues") + @ParameterizedTest + @MethodSource("validEnquotedIdentifierValues") public void test02(String s, boolean alwaysQuote, String expected) throws SQLException { - assertEquals(conn.enquoteIdentifier(s, alwaysQuote), expected); + assertEquals(expected, conn.enquoteIdentifier(s, alwaysQuote)); } /* * Validate that a SQLException is thrown for values that are not valid * for a SQL identifier */ - @Test(dataProvider = "invalidIdentifierValues", - expectedExceptions = SQLException.class) + @ParameterizedTest + @MethodSource("invalidEnquotedIdentifierValues") public void test03(String s, boolean alwaysQuote) throws SQLException { - conn.enquoteIdentifier(s, alwaysQuote); + Assertions.assertThrows(SQLException.class, () -> { + conn.enquoteIdentifier(s, alwaysQuote); + }); } /* * Validate a NullPointerException is thrown is the string passed to * enquoteIdentiifer is null */ - @Test(dataProvider = "trueFalse", - expectedExceptions = NullPointerException.class) + @ParameterizedTest + @MethodSource("trueFalse") public void test04(boolean alwaysQuote) throws SQLException { - conn.enquoteIdentifier(null, alwaysQuote); + Assertions.assertThrows(NullPointerException.class, () -> { + conn.enquoteIdentifier(null, alwaysQuote); + }); } /* * Validate that isSimpleIdentifier returns the expected value */ - @Test(dataProvider = "simpleIdentifierValues") + @ParameterizedTest + @MethodSource("simpleIdentifierValues") public void test05(String s, boolean expected) throws SQLException { - assertEquals(conn.isSimpleIdentifier(s), expected); + assertEquals(expected, conn.isSimpleIdentifier(s)); } /* * Validate a NullPointerException is thrown if the string passed to * isSimpleIdentifier is null */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test06() throws SQLException { - conn.isSimpleIdentifier(null); + Assertions.assertThrows(NullPointerException.class, () -> { + conn.isSimpleIdentifier(null); + }); } /* * Verify that enquoteLiteral creates a valid literal and converts every * single quote to two single quotes */ - @Test(dataProvider = "validEnquotedNCharLiteralValues") + @ParameterizedTest + @MethodSource("validEnquotedNCharLiteralValues") public void test07(String s, String expected) throws SQLException { - assertEquals(conn.enquoteNCharLiteral(s), expected); + assertEquals(expected, conn.enquoteNCharLiteral(s)); } /* * Validate a NullPointerException is thrown if the string passed to * enquoteNCharLiteral is null */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test08() throws SQLException { - conn.enquoteNCharLiteral(null); + Assertions.assertThrows(NullPointerException.class, () -> { + conn.enquoteNCharLiteral(null); + }); } } diff --git a/test/jdk/java/sql/testng/test/sql/DataTruncationTests.java b/test/jdk/java/sql/testng/test/sql/DataTruncationTests.java index fbf7eebe90a..560837cd403 100644 --- a/test/jdk/java/sql/testng/test/sql/DataTruncationTests.java +++ b/test/jdk/java/sql/testng/test/sql/DataTruncationTests.java @@ -24,10 +24,14 @@ package test.sql; import java.sql.DataTruncation; import java.sql.SQLException; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class DataTruncationTests extends BaseTest { private final String READ_TRUNCATION = "01004"; diff --git a/test/jdk/java/sql/testng/test/sql/DateTests.java b/test/jdk/java/sql/testng/test/sql/DateTests.java index ae6c276c4f6..fe37aee21bb 100644 --- a/test/jdk/java/sql/testng/test/sql/DateTests.java +++ b/test/jdk/java/sql/testng/test/sql/DateTests.java @@ -25,27 +25,36 @@ package test.sql; import java.sql.Date; import java.time.Instant; import java.time.LocalDate; -import static org.testng.Assert.*; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.Assertions; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class DateTests extends BaseTest { /* * Validate an IllegalArgumentException is thrown for an invalid Date string */ - @Test(dataProvider = "invalidDateValues", - expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("invalidDateValues") public void test(String d) throws Exception { - Date.valueOf(d); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Date.valueOf(d); + }); } /* * Test that a date created from a date string is equal to the value * returned from toString() */ - @Test(dataProvider = "validDateValues") + @ParameterizedTest + @MethodSource("validDateValues") public void test00(String d, String expectedD) { Date d1 = Date.valueOf(d); Date d2 = Date.valueOf(expectedD); @@ -207,20 +216,24 @@ public class DateTests extends BaseTest { /* * Validate an NPE occurs when a null LocalDate is passed to valueOf */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test15() throws Exception { - LocalDate ld = null; - Date.valueOf(ld); + Assertions.assertThrows(NullPointerException.class, () -> { + LocalDate ld = null; + Date.valueOf(ld); + }); } /* * Validate an UnsupportedOperationException occurs when toInstant() is * called */ - @Test(expectedExceptions = UnsupportedOperationException.class) + @Test public void test16() throws Exception { - Date d = Date.valueOf("1961-08-30"); - Instant instant = d.toInstant(); + Assertions.assertThrows(UnsupportedOperationException.class, () -> { + Date d = Date.valueOf("1961-08-30"); + Instant instant = d.toInstant(); + }); } /* @@ -271,55 +284,67 @@ public class DateTests extends BaseTest { /* * Validate an IllegalArgumentException is thrown for calling getHours */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test21() throws Exception { - Date d = Date.valueOf("1961-08-30"); - d.getHours(); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Date d = Date.valueOf("1961-08-30"); + d.getHours(); + }); } /* * Validate an IllegalArgumentException is thrown for calling getMinutes */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test22() throws Exception { - Date d = Date.valueOf("1961-08-30"); - d.getMinutes(); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Date d = Date.valueOf("1961-08-30"); + d.getMinutes(); + }); } /* * Validate an IllegalArgumentException is thrown for calling getSeconds */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test23() throws Exception { - Date d = Date.valueOf("1961-08-30"); - d.getSeconds(); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Date d = Date.valueOf("1961-08-30"); + d.getSeconds(); + }); } /* * Validate an IllegalArgumentException is thrown for calling setHours */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test24() throws Exception { - Date d = Date.valueOf("1961-08-30"); - d.setHours(8); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Date d = Date.valueOf("1961-08-30"); + d.setHours(8); + }); } /* * Validate an IllegalArgumentException is thrown for calling setMinutes */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test25() throws Exception { - Date d = Date.valueOf("1961-08-30"); - d.setMinutes(0); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Date d = Date.valueOf("1961-08-30"); + d.setMinutes(0); + }); } /* * Validate an IllegalArgumentException is thrown for calling setSeconds */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test26() throws Exception { - Date d = Date.valueOf("1961-08-30"); - d.setSeconds(0); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Date d = Date.valueOf("1961-08-30"); + d.setSeconds(0); + }); } /* @@ -327,7 +352,6 @@ public class DateTests extends BaseTest { * to validate that an IllegalArgumentException will be thrown from the * valueOf method */ - @DataProvider(name = "invalidDateValues") private Object[][] invalidDateValues() { return new Object[][]{ {"20009-11-01"}, @@ -360,7 +384,6 @@ public class DateTests extends BaseTest { * to validate that an IllegalArgumentException will not be thrown from the * valueOf method and the corect value from toString() is returned */ - @DataProvider(name = "validDateValues") private Object[][] validDateValues() { return new Object[][]{ {"2009-08-30", "2009-08-30"}, diff --git a/test/jdk/java/sql/testng/test/sql/DriverManagerTests.java b/test/jdk/java/sql/testng/test/sql/DriverManagerTests.java index 6b6e8386835..3c00f546816 100644 --- a/test/jdk/java/sql/testng/test/sql/DriverManagerTests.java +++ b/test/jdk/java/sql/testng/test/sql/DriverManagerTests.java @@ -39,14 +39,18 @@ import java.util.Collections; import java.util.Properties; import java.util.stream.Collectors; -import static org.testng.Assert.*; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.StubDriver; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class DriverManagerTests { private final String StubDriverURL = "jdbc:tennis:boy"; @@ -58,20 +62,20 @@ public class DriverManagerTests { public DriverManagerTests() { } - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { } - @AfterClass + @AfterAll public static void tearDownClass() throws Exception { } - @BeforeMethod + @BeforeEach public void setUpMethod() throws Exception { removeAllDrivers(); } - @AfterMethod + @AfterEach public void tearDownMethod() throws Exception { } @@ -113,7 +117,7 @@ public class DriverManagerTests { int[] vals = {-1, 0, 5}; for (int val : vals) { DriverManager.setLoginTimeout(val); - assertEquals(val, DriverManager.getLoginTimeout()); + assertEquals(DriverManager.getLoginTimeout(), val); } } @@ -121,20 +125,24 @@ public class DriverManagerTests { * Validate that NullPointerException is thrown when null is passed to * registerDriver */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test1() throws Exception { - Driver d = null; - DriverManager.registerDriver(d); + Assertions.assertThrows(NullPointerException.class, () -> { + Driver d = null; + DriverManager.registerDriver(d); + }); } /** * Validate that NullPointerException is thrown when null is passed to * registerDriver */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test2() throws Exception { - Driver d = null; - DriverManager.registerDriver(d, null); + Assertions.assertThrows(NullPointerException.class, () -> { + Driver d = null; + DriverManager.registerDriver(d, null); + }); } /** @@ -150,68 +158,84 @@ public class DriverManagerTests { * Validate that SQLException is thrown when there is no Driver to service * the URL */ - @Test(expectedExceptions = SQLException.class) + @Test public void test4() throws Exception { - DriverManager.getConnection(InvalidURL); + Assertions.assertThrows(SQLException.class, () -> { + DriverManager.getConnection(InvalidURL); + }); } /** * Validate that SQLException is thrown when there is no Driver to service * the URL */ - @Test(expectedExceptions = SQLException.class) + @Test public void test5() throws Exception { - DriverManager.getConnection(InvalidURL, new Properties()); + Assertions.assertThrows(SQLException.class, () -> { + DriverManager.getConnection(InvalidURL, new Properties()); + }); } /** * Validate that SQLException is thrown when there is no Driver to service * the URL */ - @Test(expectedExceptions = SQLException.class) + @Test public void test6() throws Exception { - DriverManager.getConnection(InvalidURL, "LuckyDog", "tennisanyone"); + Assertions.assertThrows(SQLException.class, () -> { + DriverManager.getConnection(InvalidURL, "LuckyDog", "tennisanyone"); + }); } /** * Validate that SQLException is thrown when null is passed for the URL */ - @Test(expectedExceptions = SQLException.class) + @Test public void test7() throws Exception { - DriverManager.getConnection(null); + Assertions.assertThrows(SQLException.class, () -> { + DriverManager.getConnection(null); + }); } /** * Validate that SQLException is thrown when null is passed for the URL */ - @Test(expectedExceptions = SQLException.class) + @Test public void test8() throws Exception { - DriverManager.getConnection(null, new Properties()); + Assertions.assertThrows(SQLException.class, () -> { + DriverManager.getConnection(null, new Properties()); + }); } /** * Validate that SQLException is thrown when null is passed for the URL */ - @Test(expectedExceptions = SQLException.class) + @Test public void test9() throws Exception { - DriverManager.getConnection(null, "LuckyDog", "tennisanyone"); + Assertions.assertThrows(SQLException.class, () -> { + DriverManager.getConnection(null, "LuckyDog", "tennisanyone"); + }); } /** * Validate that SQLException is thrown when there is no Driver to service * the URL */ - @Test(expectedExceptions = SQLException.class) + @Test public void test10() throws Exception { - DriverManager.getDriver(InvalidURL); + Assertions.assertThrows(SQLException.class, () -> { + DriverManager.getDriver(InvalidURL); + }); } /** * Validate that SQLException is thrown when null is passed for the URL */ - @Test(expectedExceptions = SQLException.class) + @Test public void test11() throws Exception { - DriverManager.getDriver(null); + Assertions.assertThrows(SQLException.class, () -> { + DriverManager.getDriver(null); + }); } /** @@ -229,10 +253,12 @@ public class DriverManagerTests { * Validate that SQLException is thrown when the URL is not valid for any of * the registered drivers */ - @Test(expectedExceptions = SQLException.class) + @Test public void test13() throws Exception { - DriverManager.registerDriver(new StubDriver()); - DriverManager.getDriver(InvalidURL); + Assertions.assertThrows(SQLException.class, () -> { + DriverManager.registerDriver(new StubDriver()); + DriverManager.getDriver(InvalidURL); + }); } /** @@ -370,9 +396,9 @@ public class DriverManagerTests { } Collection expectedDrivers = Collections.list(DriverManager.getDrivers()); - assertEquals(expectedDrivers.size(), n); + assertEquals(n, expectedDrivers.size()); Collection drivers = DriverManager.drivers().collect(Collectors.toList()); - assertEquals(drivers, expectedDrivers); + assertEquals(expectedDrivers, drivers); } } diff --git a/test/jdk/java/sql/testng/test/sql/PreparedStatementTests.java b/test/jdk/java/sql/testng/test/sql/PreparedStatementTests.java index 7813038361d..722222b4084 100644 --- a/test/jdk/java/sql/testng/test/sql/PreparedStatementTests.java +++ b/test/jdk/java/sql/testng/test/sql/PreparedStatementTests.java @@ -22,27 +22,32 @@ */ package test.sql; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import util.BaseTest; import util.StubConnection; import java.sql.PreparedStatement; import java.sql.SQLException; -import static org.testng.Assert.assertEquals; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class PreparedStatementTests extends BaseTest { private PreparedStatement pstmt; - @BeforeMethod + @BeforeEach public void setUpMethod() throws Exception { pstmt = new StubConnection().prepareStatement("Select * from foo were bar = ?"); } - @AfterMethod + @AfterEach public void tearDownMethod() throws Exception { pstmt.close(); } @@ -51,80 +56,94 @@ public class PreparedStatementTests extends BaseTest { * Verify that enquoteLiteral creates a valid literal and converts every * single quote to two single quotes */ - @Test(dataProvider = "validEnquotedLiteralValues") + @ParameterizedTest + @MethodSource("validEnquotedLiteralValues") public void test00(String s, String expected) throws SQLException { - assertEquals(pstmt.enquoteLiteral(s), expected); + assertEquals(expected, pstmt.enquoteLiteral(s)); } /* * Validate a NullPointerException is thrown if the string passed to * enquoteLiteral is null */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test01() throws SQLException { - pstmt.enquoteLiteral(null); + Assertions.assertThrows(NullPointerException.class, () -> { + pstmt.enquoteLiteral(null); + }); } /* * Validate that enquoteIdentifier returns the expected value */ - @Test(dataProvider = "validIdentifierValues") + @ParameterizedTest + @MethodSource("validEnquotedIdentifierValues") public void test02(String s, boolean alwaysQuote, String expected) throws SQLException { - assertEquals(pstmt.enquoteIdentifier(s, alwaysQuote), expected); + assertEquals(expected, pstmt.enquoteIdentifier(s, alwaysQuote)); } /* * Validate that a SQLException is thrown for values that are not valid * for a SQL identifier */ - @Test(dataProvider = "invalidIdentifierValues", - expectedExceptions = SQLException.class) + @ParameterizedTest + @MethodSource("invalidEnquotedIdentifierValues") public void test03(String s, boolean alwaysQuote) throws SQLException { - pstmt.enquoteIdentifier(s, alwaysQuote); + Assertions.assertThrows(SQLException.class, () -> { + pstmt.enquoteIdentifier(s, alwaysQuote); + }); } /* * Validate a NullPointerException is thrown is the string passed to * enquoteIdentiifer is null */ - @Test(dataProvider = "trueFalse", - expectedExceptions = NullPointerException.class) + @ParameterizedTest + @MethodSource("trueFalse") public void test04(boolean alwaysQuote) throws SQLException { - pstmt.enquoteIdentifier(null, alwaysQuote); + Assertions.assertThrows(NullPointerException.class, () -> { + pstmt.enquoteIdentifier(null, alwaysQuote); + }); } /* * Validate that isSimpleIdentifier returns the expected value */ - @Test(dataProvider = "simpleIdentifierValues") + @ParameterizedTest + @MethodSource("simpleIdentifierValues") public void test05(String s, boolean expected) throws SQLException { - assertEquals(pstmt.isSimpleIdentifier(s), expected); + assertEquals(expected, pstmt.isSimpleIdentifier(s)); } /* * Validate a NullPointerException is thrown if the string passed to * isSimpleIdentifier is null */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test06() throws SQLException { - pstmt.isSimpleIdentifier(null); + Assertions.assertThrows(NullPointerException.class, () -> { + pstmt.isSimpleIdentifier(null); + }); } /* * Verify that enquoteLiteral creates a valid literal and converts every * single quote to two single quotes */ - @Test(dataProvider = "validEnquotedNCharLiteralValues") + @ParameterizedTest + @MethodSource("validEnquotedNCharLiteralValues") public void test07(String s, String expected) throws SQLException { - assertEquals(pstmt.enquoteNCharLiteral(s), expected); + assertEquals(expected, pstmt.enquoteNCharLiteral(s)); } /* * Validate a NullPointerException is thrown if the string passed to * enquoteNCharLiteral is null */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test08() throws SQLException { - pstmt.enquoteNCharLiteral(null); + Assertions.assertThrows(NullPointerException.class, () -> { + pstmt.enquoteNCharLiteral(null); + }); } } diff --git a/test/jdk/java/sql/testng/test/sql/SQLClientInfoExceptionTests.java b/test/jdk/java/sql/testng/test/sql/SQLClientInfoExceptionTests.java index 84230b86758..5a1a851b2b4 100644 --- a/test/jdk/java/sql/testng/test/sql/SQLClientInfoExceptionTests.java +++ b/test/jdk/java/sql/testng/test/sql/SQLClientInfoExceptionTests.java @@ -26,10 +26,14 @@ import java.sql.ClientInfoStatus; import java.sql.SQLClientInfoException; import java.sql.SQLException; import java.util.HashMap; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class SQLClientInfoExceptionTests extends BaseTest { private final HashMap map = new HashMap<>(); diff --git a/test/jdk/java/sql/testng/test/sql/SQLDataExceptionTests.java b/test/jdk/java/sql/testng/test/sql/SQLDataExceptionTests.java index 8a5f8d1a2c1..9e79e19eca4 100644 --- a/test/jdk/java/sql/testng/test/sql/SQLDataExceptionTests.java +++ b/test/jdk/java/sql/testng/test/sql/SQLDataExceptionTests.java @@ -25,10 +25,14 @@ package test.sql; import java.sql.SQLDataException; import java.sql.SQLException; import java.sql.SQLNonTransientException; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class SQLDataExceptionTests extends BaseTest { /** diff --git a/test/jdk/java/sql/testng/test/sql/SQLExceptionTests.java b/test/jdk/java/sql/testng/test/sql/SQLExceptionTests.java index e3643ef119c..bb75fac9a3a 100644 --- a/test/jdk/java/sql/testng/test/sql/SQLExceptionTests.java +++ b/test/jdk/java/sql/testng/test/sql/SQLExceptionTests.java @@ -23,10 +23,14 @@ package test.sql; import java.sql.SQLException; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class SQLExceptionTests extends BaseTest { /** diff --git a/test/jdk/java/sql/testng/test/sql/SQLFeatureNotSupportedExceptionTests.java b/test/jdk/java/sql/testng/test/sql/SQLFeatureNotSupportedExceptionTests.java index 5b95894412c..0a7f6b3b9fa 100644 --- a/test/jdk/java/sql/testng/test/sql/SQLFeatureNotSupportedExceptionTests.java +++ b/test/jdk/java/sql/testng/test/sql/SQLFeatureNotSupportedExceptionTests.java @@ -25,10 +25,14 @@ package test.sql; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; import java.sql.SQLNonTransientException; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class SQLFeatureNotSupportedExceptionTests extends BaseTest { /** diff --git a/test/jdk/java/sql/testng/test/sql/SQLIntegrityConstraintViolationExceptionTests.java b/test/jdk/java/sql/testng/test/sql/SQLIntegrityConstraintViolationExceptionTests.java index 082e0af15c8..edddff2c488 100644 --- a/test/jdk/java/sql/testng/test/sql/SQLIntegrityConstraintViolationExceptionTests.java +++ b/test/jdk/java/sql/testng/test/sql/SQLIntegrityConstraintViolationExceptionTests.java @@ -25,10 +25,14 @@ package test.sql; import java.sql.SQLException; import java.sql.SQLIntegrityConstraintViolationException; import java.sql.SQLNonTransientException; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class SQLIntegrityConstraintViolationExceptionTests extends BaseTest { /** diff --git a/test/jdk/java/sql/testng/test/sql/SQLInvalidAuthorizationSpecExceptionTests.java b/test/jdk/java/sql/testng/test/sql/SQLInvalidAuthorizationSpecExceptionTests.java index 6e4eaa567ee..24ce2e81635 100644 --- a/test/jdk/java/sql/testng/test/sql/SQLInvalidAuthorizationSpecExceptionTests.java +++ b/test/jdk/java/sql/testng/test/sql/SQLInvalidAuthorizationSpecExceptionTests.java @@ -25,10 +25,14 @@ package test.sql; import java.sql.SQLException; import java.sql.SQLInvalidAuthorizationSpecException; import java.sql.SQLNonTransientException; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class SQLInvalidAuthorizationSpecExceptionTests extends BaseTest { /** diff --git a/test/jdk/java/sql/testng/test/sql/SQLNonTransientConnectionExceptionTests.java b/test/jdk/java/sql/testng/test/sql/SQLNonTransientConnectionExceptionTests.java index dbd8b685844..5eb30187ff1 100644 --- a/test/jdk/java/sql/testng/test/sql/SQLNonTransientConnectionExceptionTests.java +++ b/test/jdk/java/sql/testng/test/sql/SQLNonTransientConnectionExceptionTests.java @@ -25,10 +25,14 @@ package test.sql; import java.sql.SQLException; import java.sql.SQLNonTransientConnectionException; import java.sql.SQLNonTransientException; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class SQLNonTransientConnectionExceptionTests extends BaseTest { /** diff --git a/test/jdk/java/sql/testng/test/sql/SQLNonTransientExceptionTests.java b/test/jdk/java/sql/testng/test/sql/SQLNonTransientExceptionTests.java index 061ffe20840..3df0dda8895 100644 --- a/test/jdk/java/sql/testng/test/sql/SQLNonTransientExceptionTests.java +++ b/test/jdk/java/sql/testng/test/sql/SQLNonTransientExceptionTests.java @@ -24,10 +24,14 @@ package test.sql; import java.sql.SQLException; import java.sql.SQLNonTransientException; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class SQLNonTransientExceptionTests extends BaseTest { /** diff --git a/test/jdk/java/sql/testng/test/sql/SQLRecoverableExceptionTests.java b/test/jdk/java/sql/testng/test/sql/SQLRecoverableExceptionTests.java index d23a131dbcd..7a44478c14f 100644 --- a/test/jdk/java/sql/testng/test/sql/SQLRecoverableExceptionTests.java +++ b/test/jdk/java/sql/testng/test/sql/SQLRecoverableExceptionTests.java @@ -24,10 +24,14 @@ package test.sql; import java.sql.SQLException; import java.sql.SQLRecoverableException; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class SQLRecoverableExceptionTests extends BaseTest { /** diff --git a/test/jdk/java/sql/testng/test/sql/SQLSyntaxErrorExceptionTests.java b/test/jdk/java/sql/testng/test/sql/SQLSyntaxErrorExceptionTests.java index 863213cfcb8..231ad5bca76 100644 --- a/test/jdk/java/sql/testng/test/sql/SQLSyntaxErrorExceptionTests.java +++ b/test/jdk/java/sql/testng/test/sql/SQLSyntaxErrorExceptionTests.java @@ -25,10 +25,14 @@ package test.sql; import java.sql.SQLException; import java.sql.SQLNonTransientException; import java.sql.SQLSyntaxErrorException; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class SQLSyntaxErrorExceptionTests extends BaseTest { /** diff --git a/test/jdk/java/sql/testng/test/sql/SQLTimeoutExceptionTests.java b/test/jdk/java/sql/testng/test/sql/SQLTimeoutExceptionTests.java index dfe341545e4..00c30399a29 100644 --- a/test/jdk/java/sql/testng/test/sql/SQLTimeoutExceptionTests.java +++ b/test/jdk/java/sql/testng/test/sql/SQLTimeoutExceptionTests.java @@ -25,10 +25,14 @@ package test.sql; import java.sql.SQLException; import java.sql.SQLTimeoutException; import java.sql.SQLTransientException; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class SQLTimeoutExceptionTests extends BaseTest { /** diff --git a/test/jdk/java/sql/testng/test/sql/SQLTransactionRollbackExceptionTests.java b/test/jdk/java/sql/testng/test/sql/SQLTransactionRollbackExceptionTests.java index 8453ebe1364..fdbb440f0cb 100644 --- a/test/jdk/java/sql/testng/test/sql/SQLTransactionRollbackExceptionTests.java +++ b/test/jdk/java/sql/testng/test/sql/SQLTransactionRollbackExceptionTests.java @@ -25,10 +25,14 @@ package test.sql; import java.sql.SQLException; import java.sql.SQLTransactionRollbackException; import java.sql.SQLTransientException; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class SQLTransactionRollbackExceptionTests extends BaseTest { /** diff --git a/test/jdk/java/sql/testng/test/sql/SQLTransientConnectionExceptionTests.java b/test/jdk/java/sql/testng/test/sql/SQLTransientConnectionExceptionTests.java index 7999253b1fa..1d3efec44d2 100644 --- a/test/jdk/java/sql/testng/test/sql/SQLTransientConnectionExceptionTests.java +++ b/test/jdk/java/sql/testng/test/sql/SQLTransientConnectionExceptionTests.java @@ -25,10 +25,14 @@ package test.sql; import java.sql.SQLException; import java.sql.SQLTransientConnectionException; import java.sql.SQLTransientException; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class SQLTransientConnectionExceptionTests extends BaseTest { /** diff --git a/test/jdk/java/sql/testng/test/sql/SQLTransientExceptionTests.java b/test/jdk/java/sql/testng/test/sql/SQLTransientExceptionTests.java index d86f86b8fc6..faac9dac9e3 100644 --- a/test/jdk/java/sql/testng/test/sql/SQLTransientExceptionTests.java +++ b/test/jdk/java/sql/testng/test/sql/SQLTransientExceptionTests.java @@ -24,10 +24,14 @@ package test.sql; import java.sql.SQLException; import java.sql.SQLTransientException; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class SQLTransientExceptionTests extends BaseTest { /** diff --git a/test/jdk/java/sql/testng/test/sql/SQLWarningTests.java b/test/jdk/java/sql/testng/test/sql/SQLWarningTests.java index 2856742dc5c..f06ae4522d7 100644 --- a/test/jdk/java/sql/testng/test/sql/SQLWarningTests.java +++ b/test/jdk/java/sql/testng/test/sql/SQLWarningTests.java @@ -24,10 +24,14 @@ package test.sql; import java.sql.SQLException; import java.sql.SQLWarning; -import static org.testng.Assert.*; -import org.testng.annotations.Test; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class SQLWarningTests extends BaseTest { private final String[] warnings = {"Warning 1", "cause 1", "Warning 2", diff --git a/test/jdk/java/sql/testng/test/sql/StatementTests.java b/test/jdk/java/sql/testng/test/sql/StatementTests.java index f2bfe712eb5..9f061bf20f3 100644 --- a/test/jdk/java/sql/testng/test/sql/StatementTests.java +++ b/test/jdk/java/sql/testng/test/sql/StatementTests.java @@ -25,22 +25,29 @@ package test.sql; import java.sql.SQLException; import java.sql.Statement; -import static org.testng.Assert.assertEquals; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -import org.testng.annotations.*; import util.BaseTest; import util.StubConnection; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class StatementTests extends BaseTest { private Statement stmt; - @BeforeMethod + @BeforeEach public void setUpMethod() throws Exception { stmt = new StubConnection().createStatement(); } - @AfterMethod + @AfterEach public void tearDownMethod() throws Exception { stmt.close(); } @@ -48,80 +55,94 @@ public class StatementTests extends BaseTest { * Verify that enquoteLiteral creates a valid literal and converts every * single quote to two single quotes */ - @Test(dataProvider = "validEnquotedLiteralValues") + @ParameterizedTest + @MethodSource("validEnquotedLiteralValues") public void test00(String s, String expected) throws SQLException { - assertEquals(stmt.enquoteLiteral(s), expected); + assertEquals(expected, stmt.enquoteLiteral(s)); } /* * Validate a NullPointerException is thrown if the string passed to * enquoteLiteral is null */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test01() throws SQLException { - stmt.enquoteLiteral(null); + Assertions.assertThrows(NullPointerException.class, () -> { + stmt.enquoteLiteral(null); + }); } /* * Validate that enquoteIdentifier returns the expected value */ - @Test(dataProvider = "validIdentifierValues") + @ParameterizedTest + @MethodSource("validEnquotedIdentifierValues") public void test02(String s, boolean alwaysQuote, String expected) throws SQLException { - assertEquals(stmt.enquoteIdentifier(s, alwaysQuote), expected); + assertEquals(expected, stmt.enquoteIdentifier(s, alwaysQuote)); } /* * Validate that a SQLException is thrown for values that are not valid * for a SQL identifier */ - @Test(dataProvider = "invalidIdentifierValues", - expectedExceptions = SQLException.class) + @ParameterizedTest + @MethodSource("invalidEnquotedIdentifierValues") public void test03(String s, boolean alwaysQuote) throws SQLException { - stmt.enquoteIdentifier(s, alwaysQuote); + Assertions.assertThrows(SQLException.class, () -> { + stmt.enquoteIdentifier(s, alwaysQuote); + }); } /* * Validate a NullPointerException is thrown is the string passed to * enquoteIdentiifer is null */ - @Test(dataProvider = "trueFalse", - expectedExceptions = NullPointerException.class) + @ParameterizedTest + @MethodSource("trueFalse") public void test04(boolean alwaysQuote) throws SQLException { - stmt.enquoteIdentifier(null, alwaysQuote); + Assertions.assertThrows(NullPointerException.class, () -> { + stmt.enquoteIdentifier(null, alwaysQuote); + }); } /* * Validate that isSimpleIdentifier returns the expected value */ - @Test(dataProvider = "simpleIdentifierValues") + @ParameterizedTest + @MethodSource("simpleIdentifierValues") public void test05(String s, boolean expected) throws SQLException { - assertEquals(stmt.isSimpleIdentifier(s), expected); + assertEquals(expected, stmt.isSimpleIdentifier(s)); } /* * Validate a NullPointerException is thrown if the string passed to * isSimpleIdentifier is null */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test06() throws SQLException { - stmt.isSimpleIdentifier(null); + Assertions.assertThrows(NullPointerException.class, () -> { + stmt.isSimpleIdentifier(null); + }); } /* * Verify that enquoteLiteral creates a valid literal and converts every * single quote to two single quotes */ - @Test(dataProvider = "validEnquotedNCharLiteralValues") + @ParameterizedTest + @MethodSource("validEnquotedNCharLiteralValues") public void test07(String s, String expected) throws SQLException { - assertEquals(stmt.enquoteNCharLiteral(s), expected); + assertEquals(expected, stmt.enquoteNCharLiteral(s)); } /* * Validate a NullPointerException is thrown if the string passed to * enquoteNCharLiteral is null */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test08() throws SQLException { - stmt.enquoteNCharLiteral(null); + Assertions.assertThrows(NullPointerException.class, () -> { + stmt.enquoteNCharLiteral(null); + }); } } diff --git a/test/jdk/java/sql/testng/test/sql/TimeTests.java b/test/jdk/java/sql/testng/test/sql/TimeTests.java index 7b99679754b..ff1d1495779 100644 --- a/test/jdk/java/sql/testng/test/sql/TimeTests.java +++ b/test/jdk/java/sql/testng/test/sql/TimeTests.java @@ -24,83 +24,105 @@ package test.sql; import java.sql.Time; import java.time.LocalTime; -import static org.testng.Assert.*; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.Assertions; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TimeTests extends BaseTest { /* * Validate an IllegalArgumentException is thrown for calling getYear */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test01() { - Time t = Time.valueOf("08:30:59"); - t.getYear(); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Time t = Time.valueOf("08:30:59"); + t.getYear(); + }); } /* * Validate an IllegalArgumentException is thrown for calling getMonth */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test02() { - Time t = Time.valueOf("08:30:59"); - t.getMonth(); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Time t = Time.valueOf("08:30:59"); + t.getMonth(); + }); } /* * Validate an IllegalArgumentException is thrown for calling getDay */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test03() { - Time t = Time.valueOf("08:30:59"); - t.getDay(); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Time t = Time.valueOf("08:30:59"); + t.getDay(); + }); } /** * Validate an IllegalArgumentException is thrown for calling getDate */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test04() { - Time t = Time.valueOf("08:30:59"); - t.getDate(); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Time t = Time.valueOf("08:30:59"); + t.getDate(); + }); } /* * Validate an IllegalArgumentException is thrown for calling setYear */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test05() { - Time t = Time.valueOf("08:30:59"); - t.setYear(8); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Time t = Time.valueOf("08:30:59"); + t.setYear(8); + }); } /* * Validate an IllegalArgumentException is thrown for calling setMonth */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test06() { - Time t = Time.valueOf("08:30:59"); - t.setMonth(8); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Time t = Time.valueOf("08:30:59"); + t.setMonth(8); + }); } /* * Validate an IllegalArgumentException is thrown for calling setDate */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test07() { - Time t = Time.valueOf("08:30:59"); - t.setDate(30); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Time t = Time.valueOf("08:30:59"); + t.setDate(30); + }); } /* * Validate an IllegalArgumentException is thrown for calling getDate */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test08() { - Time t = Time.valueOf("08:30:59"); - t.getDate(); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Time t = Time.valueOf("08:30:59"); + t.getDate(); + }); } /* @@ -128,20 +150,24 @@ public class TimeTests extends BaseTest { /* * Validate an NPE occurs when a null LocalDate is passed to valueOf */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test11() throws Exception { - LocalTime ld = null; - Time.valueOf(ld); + Assertions.assertThrows(NullPointerException.class, () -> { + LocalTime ld = null; + Time.valueOf(ld); + }); } /* * Validate an UnsupportedOperationException occurs when toInstant() is * called */ - @Test(expectedExceptions = UnsupportedOperationException.class) + @Test public void test12() throws Exception { - Time t = new Time(System.currentTimeMillis()); - t.toInstant(); + Assertions.assertThrows(UnsupportedOperationException.class, () -> { + Time t = new Time(System.currentTimeMillis()); + t.toInstant(); + }); } /* @@ -149,7 +175,8 @@ public class TimeTests extends BaseTest { * toString() of the other and that the correct value is returned from * toString() */ - @Test(dataProvider = "validTimeValues") + @ParameterizedTest + @MethodSource("validTimeValues") public void test13(String time, String expected) { Time t1 = Time.valueOf(time); Time t2 = Time.valueOf(t1.toString()); @@ -182,10 +209,12 @@ public class TimeTests extends BaseTest { /* * Validate an IllegalArgumentException is thrown for an invalid Time string */ - @Test(dataProvider = "invalidTimeValues", - expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("invalidTimeValues") public void test16(String time) throws Exception { - Time.valueOf(time); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Time.valueOf(time); + }); } /* @@ -299,7 +328,6 @@ public class TimeTests extends BaseTest { * to validate that an IllegalArgumentException will be thrown from the * valueOf method */ - @DataProvider(name = "invalidTimeValues") private Object[][] invalidTimeValues() { return new Object[][]{ {"2009-11-01 10:50:01"}, @@ -330,7 +358,6 @@ public class TimeTests extends BaseTest { * valueOf method. It also contains the expected return value from * toString() */ - @DataProvider(name = "validTimeValues") private Object[][] validTimeValues() { return new Object[][]{ {"10:50:01", "10:50:01"}, diff --git a/test/jdk/java/sql/testng/test/sql/TimestampTests.java b/test/jdk/java/sql/testng/test/sql/TimestampTests.java index 6baea9fa26f..337d84656dc 100644 --- a/test/jdk/java/sql/testng/test/sql/TimestampTests.java +++ b/test/jdk/java/sql/testng/test/sql/TimestampTests.java @@ -30,13 +30,19 @@ import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Calendar; import java.util.TimeZone; -import static org.testng.Assert.*; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + import util.BaseTest; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TimestampTests extends BaseTest { private static TimeZone defaultTimeZone = null; @@ -45,7 +51,7 @@ public class TimestampTests extends BaseTest { * Need to set and use a custom TimeZone which does not * observe daylight savings time for this test. */ - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { defaultTimeZone = TimeZone.getDefault(); TimeZone tzone = TimeZone.getTimeZone("GMT+01"); @@ -56,7 +62,7 @@ public class TimestampTests extends BaseTest { /* * Conservatively reset the default time zone after test. */ - @AfterClass + @AfterAll public static void tearDownClass() throws Exception { TimeZone.setDefault(defaultTimeZone); } @@ -64,10 +70,12 @@ public class TimestampTests extends BaseTest { /* * Validate an IllegalArgumentException is thrown for an invalid Timestamp */ - @Test(dataProvider = "invalidTimestampValues", - expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("invalidTimestampValues") public void test(String ts) throws Exception { - Timestamp.valueOf(ts); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Timestamp.valueOf(ts); + }); } /* @@ -80,7 +88,7 @@ public class TimestampTests extends BaseTest { String ExpectedTS = "2009-01-01 10:50:0"; Timestamp ts = Timestamp.valueOf(testTS); Timestamp ts2 = Timestamp.valueOf(ExpectedTS); - assertEquals(ts, ts2, "Error ts1 != ts2"); + assertEquals(ts2, ts, "Error ts1 != ts2"); } /* @@ -91,7 +99,7 @@ public class TimestampTests extends BaseTest { String testTS = "2009-01-01 10:50:0"; Timestamp ts = Timestamp.valueOf(testTS); Timestamp ts2 = Timestamp.valueOf(testTS); - assertEquals(ts, ts2, "Error ts1 != ts2"); + assertEquals(ts2, ts, "Error ts1 != ts2"); } /* @@ -104,7 +112,7 @@ public class TimestampTests extends BaseTest { String ExpectedTS = "2009-01-01 10:50:0"; Timestamp ts = Timestamp.valueOf(testTS); Timestamp ts2 = Timestamp.valueOf(ExpectedTS); - assertEquals(ts, ts2, "Error ts1 != ts2"); + assertEquals(ts2, ts, "Error ts1 != ts2"); } /* @@ -117,7 +125,7 @@ public class TimestampTests extends BaseTest { String ExpectedTS = "2009-01-01 10:50:0"; Timestamp ts = Timestamp.valueOf(testTS); Timestamp ts2 = Timestamp.valueOf(ExpectedTS); - assertEquals(ts, ts2, "Error ts1 != ts2"); + assertEquals(ts2, ts, "Error ts1 != ts2"); } /* @@ -130,7 +138,7 @@ public class TimestampTests extends BaseTest { String ExpectedTS = "2009-01-01 10:50:0"; Timestamp ts = Timestamp.valueOf(testTS); Timestamp ts2 = Timestamp.valueOf(ExpectedTS); - assertEquals(ts, ts2, "Error ts1 != ts2"); + assertEquals(ts2, ts, "Error ts1 != ts2"); } /* @@ -142,7 +150,7 @@ public class TimestampTests extends BaseTest { String ExpectedTS = "2005-01-01 10:20:50.00"; Timestamp ts = Timestamp.valueOf(testTS); Timestamp ts2 = Timestamp.valueOf(ExpectedTS); - assertEquals(ts, ts2, "Error ts1 != ts2"); + assertEquals(ts2, ts, "Error ts1 != ts2"); } /* @@ -219,7 +227,8 @@ public class TimestampTests extends BaseTest { * Validate that two Timestamps are equal when one is created from the * toString() of the other */ - @Test(dataProvider = "validTimestampValues") + @ParameterizedTest + @MethodSource("validTimestampValues") public void test13(String ts, String expectedTS) { Timestamp ts1 = Timestamp.valueOf(ts); Timestamp ts2 = Timestamp.valueOf(ts1.toString()); @@ -263,10 +272,12 @@ public class TimestampTests extends BaseTest { * Validate that a NullPointerException is thrown if a null is passed to * the before method */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test17() throws Exception { - Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.745634"); - ts1.before(null); + Assertions.assertThrows(NullPointerException.class, () -> { + Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.745634"); + ts1.before(null); + }); } /* @@ -316,10 +327,12 @@ public class TimestampTests extends BaseTest { * Validate that a NullPointerException is thrown if a null is passed to the * after method */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test22() throws Exception { - Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08"); - ts1.after(null); + Assertions.assertThrows(NullPointerException.class, () -> { + Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08"); + ts1.after(null); + }); } /* @@ -476,21 +489,25 @@ public class TimestampTests extends BaseTest { /* * Validate an IllegalArgumentException is thrown for an invalid nanos value */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test38() throws Exception { - Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00"); - ts1.setNanos(-1); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00"); + ts1.setNanos(-1); + }); } /* * Validate an IllegalArgumentException is thrown for an invalid nanos value */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test39() throws Exception { - int nanos = 999999999; - Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00"); - ts1.setNanos(nanos + 1); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + int nanos = 999999999; + Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00"); + ts1.setNanos(nanos + 1); + }); } /* @@ -541,10 +558,12 @@ public class TimestampTests extends BaseTest { /* * Validate an NPE occurs when a null LocalDateTime is passed to valueOF */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test44() throws Exception { - LocalDateTime ldt = null; - Timestamp.valueOf(ldt); + Assertions.assertThrows(NullPointerException.class, () -> { + LocalDateTime ldt = null; + Timestamp.valueOf(ldt); + }); } /* @@ -572,10 +591,12 @@ public class TimestampTests extends BaseTest { /* * Validate an NPE occurs when a null instant is passed to from */ - @Test(expectedExceptions = NullPointerException.class) + @Test public void test47() throws Exception { - Instant instant = null; - Timestamp.from(instant); + Assertions.assertThrows(NullPointerException.class, () -> { + Instant instant = null; + Timestamp.from(instant); + }); } // Added SQE tests @@ -628,7 +649,8 @@ public class TimestampTests extends BaseTest { * Validate that two Timestamps are equal when one is created from the * toString() of the other */ - @Test(dataProvider = "validateNanos") + @ParameterizedTest + @MethodSource("validateNanos") public void test51(String ts, int nanos) { Timestamp ts1 = Timestamp.valueOf(ts); Timestamp ts2 = Timestamp.valueOf(ts1.toString()); @@ -636,35 +658,36 @@ public class TimestampTests extends BaseTest { "Error with Nanos"); } - @Test(dataProvider = "validTimestampLongValues") + @ParameterizedTest + @MethodSource("validTimestampLongValues") public void test52(long value, String ts) { Timestamp ts1 = new Timestamp(value); - assertEquals(ts1.toString(), ts, "ts1.toString() != ts"); + assertEquals(ts, ts1.toString(), "ts1.toString() != ts"); } @Test public void test53() { // The latest Instant that can be converted to a Timestamp. Instant instant1 = Instant.ofEpochSecond(Long.MAX_VALUE / 1000, 999_999_999); - assertEquals(Timestamp.from(instant1).toInstant(), instant1); + assertEquals(instant1, Timestamp.from(instant1).toInstant()); // One nanosecond more, and converting it gets an overflow. Instant instant2 = instant1.plusNanos(1); - expectThrows(IllegalArgumentException.class, () -> Timestamp.from(instant2)); + assertThrows(IllegalArgumentException.class, () -> Timestamp.from(instant2)); // The earliest Instant that can be converted to a Timestamp. Instant instant3 = Instant.ofEpochSecond(Long.MIN_VALUE / 1000, 0); - assertEquals(Timestamp.from(instant3).toInstant(), instant3); + assertEquals(instant3, Timestamp.from(instant3).toInstant()); // One nanosecond less, and converting it gets an overflow. Instant instant4 = instant3.minusNanos(1); - expectThrows(IllegalArgumentException.class, () -> Timestamp.from(instant4)); + assertThrows(IllegalArgumentException.class, () -> Timestamp.from(instant4)); // The latest possible Instant will certainly overflow. - expectThrows(IllegalArgumentException.class, () -> Timestamp.from(Instant.MAX)); + assertThrows(IllegalArgumentException.class, () -> Timestamp.from(Instant.MAX)); // The earliest possible Instant will certainly overflow. - expectThrows(IllegalArgumentException.class, () -> Timestamp.from(Instant.MIN)); + assertThrows(IllegalArgumentException.class, () -> Timestamp.from(Instant.MIN)); } /* @@ -683,7 +706,7 @@ public class TimestampTests extends BaseTest { assertTrue(ts1.equals(ts2)); // As the Timestamp values, including the nanos are the same, the hashCode's // should be equal - assertEquals(ts1.hashCode(), ts2.hashCode()); + assertEquals(ts2.hashCode(), ts1.hashCode()); } /* @@ -702,7 +725,7 @@ public class TimestampTests extends BaseTest { assertTrue(ts2.equals(ts2)); assertFalse(ts1.equals(ts2)); // As the nanos differ, the hashCode values should differ - assertNotEquals(ts1.hashCode(), ts2.hashCode()); + assertNotEquals(ts2.hashCode(), ts1.hashCode()); } /* @@ -710,7 +733,6 @@ public class TimestampTests extends BaseTest { * to validate that an IllegalArgumentException will be thrown from the * valueOf method */ - @DataProvider(name = "invalidTimestampValues") private Object[][] invalidTimestampValues() { return new Object[][]{ {"2009-11-01-01 10:50:01"}, @@ -744,7 +766,6 @@ public class TimestampTests extends BaseTest { * to validate that an IllegalArgumentException will not be thrown from the * valueOf method and the corect value from toString() is returned */ - @DataProvider(name = "validTimestampValues") private Object[][] validTimestampValues() { return new Object[][]{ {"1961-08-30 00:00:00", "1961-08-30 00:00:00.0"}, @@ -773,7 +794,6 @@ public class TimestampTests extends BaseTest { }; } - @DataProvider(name = "validTimestampLongValues") private Object[][] validTimestampLongValues() { return new Object[][]{ {1L, "1970-01-01 01:00:00.001"}, @@ -812,7 +832,6 @@ public class TimestampTests extends BaseTest { * validate that the correct Nanos value is generated from the specified * Timestamp */ - @DataProvider(name = "validateNanos") private Object[][] validateNanos() { return new Object[][]{ {"1961-08-30 00:00:00", 0}, diff --git a/test/jdk/java/sql/testng/test/sql/othervm/DriverManagerInitTests.java b/test/jdk/java/sql/testng/test/sql/othervm/DriverManagerInitTests.java index d2570993533..b3e272a8f4a 100644 --- a/test/jdk/java/sql/testng/test/sql/othervm/DriverManagerInitTests.java +++ b/test/jdk/java/sql/testng/test/sql/othervm/DriverManagerInitTests.java @@ -33,8 +33,8 @@ import java.util.Enumeration; import java.util.logging.Level; import java.util.logging.Logger; -import static org.testng.Assert.*; -import org.testng.annotations.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class DriverManagerInitTests { diff --git a/test/jdk/java/sql/testng/util/BaseTest.java b/test/jdk/java/sql/testng/util/BaseTest.java index 8751183726d..183da493ce5 100644 --- a/test/jdk/java/sql/testng/util/BaseTest.java +++ b/test/jdk/java/sql/testng/util/BaseTest.java @@ -30,8 +30,9 @@ import java.io.ObjectOutputStream; import java.sql.JDBCType; import java.sql.SQLException; -import org.testng.annotations.DataProvider; +import org.junit.jupiter.api.TestInstance; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class BaseTest { protected final String reason = "reason"; @@ -77,7 +78,6 @@ public class BaseTest { * DataProvider used to specify the value to set and check for * methods using boolean values */ - @DataProvider(name = "trueFalse") protected Object[][] trueFalse() { return new Object[][]{ {true}, @@ -88,7 +88,6 @@ public class BaseTest { /* * DataProvider used to specify the standard JDBC Types */ - @DataProvider(name = "jdbcTypes") protected Object[][] jdbcTypes() { Object[][] o = new Object[JDBCType.values().length][1]; int pos = 0; @@ -103,7 +102,6 @@ public class BaseTest { * that enquoteLiteral converts a string to a literal and every instance of * a single quote will be converted into two single quotes in the literal. */ - @DataProvider(name = "validEnquotedLiteralValues") protected Object[][] validEnquotedLiteralValues() { return new Object[][]{ {"Hello", "'Hello'"}, @@ -119,7 +117,6 @@ public class BaseTest { * that enqouteIdentifier returns a simple SQL Identifier or a * quoted identifier */ - @DataProvider(name = "validIdentifierValues") protected Object[][] validEnquotedIdentifierValues() { return new Object[][]{ {"b", false, "b"}, @@ -142,7 +139,6 @@ public class BaseTest { * DataProvider used to provide strings are invalid for enquoteIdentifier * resulting in a SQLException being thrown */ - @DataProvider(name = "invalidIdentifierValues") protected Object[][] invalidEnquotedIdentifierValues() { return new Object[][]{ {"Hel\"lo", false}, @@ -157,7 +153,6 @@ public class BaseTest { * that isSimpleIdentifier returns the correct value based on the * identifier specified. */ - @DataProvider(name = "simpleIdentifierValues") protected Object[][] simpleIdentifierValues() { return new Object[][]{ {"b", true}, @@ -181,7 +176,6 @@ public class BaseTest { * literal and every instance of * a single quote will be converted into two single quotes in the literal. */ - @DataProvider(name = "validEnquotedNCharLiteralValues") protected Object[][] validEnquotedNCharLiteralValues() { return new Object[][]{ {"Hello", "N'Hello'"},