Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lilgreenbird committed May 1, 2019
1 parent e862cea commit 9033a47
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
7 changes: 6 additions & 1 deletion src/test/java/com/microsoft/sqlserver/jdbc/TimeoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,14 @@ public void testNestedTimeoutShouldKeepTimerThreadRunning() throws SQLException
public void testGetClosedTimer() throws SQLServerException, SQLException {
try (SQLServerConnection conn = getConnection()) {
try {
conn.close();
@SuppressWarnings("unused")
SharedTimer timer = conn.getSharedTimer();
} catch (IllegalStateException e) {
fail(TestResource.getResource("R_expectedFailPassed"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_connectionIsClosed")));
} catch (Exception e) {
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package com.microsoft.sqlserver.jdbc.unit.statement;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.StringReader;
import java.math.BigDecimal;
Expand Down Expand Up @@ -216,9 +216,7 @@ public void testCancelLongResponse() throws Exception {
try {
stmt.closeOnCompletion();
} catch (Exception e) {

throw new SQLException(TestResource.getResource("R_unexpectedException") + ": ", e);

fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

try (ResultSet rs = stmt.executeQuery(
Expand Down Expand Up @@ -690,11 +688,10 @@ class Hammer {
}

void start(final Connection con) {

try {
newStmt = con.createStatement();
} catch (SQLException e) {
fail(id + " " + e.getMessage());
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

final Statement stmt = newStmt;
Expand Down Expand Up @@ -834,9 +831,7 @@ public void testIsCloseOnCompletion() throws Exception {
try {
result = ps.isCloseOnCompletion();
} catch (Exception e) {

throw new SQLException(TestResource.getResource("R_unexpectedException") + ": ", e);

fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

assertEquals(false, result, "isCloseOnCompletion: " + TestResource.getResource("R_incorrectDefault"));
Expand All @@ -852,8 +847,7 @@ public void testCloseOnCompletion() throws Exception {
try {
ps.closeOnCompletion();
} catch (Exception e) {
throw new SQLException(TestResource.getResource("R_unexpectedException") + ": ", e);

fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

try (ResultSet rs = ps.executeQuery()) {
Expand Down Expand Up @@ -887,7 +881,7 @@ public void testIsCloseOnCompletion() throws Exception {
try {
stmt.closeOnCompletion();
} catch (Exception e) {
throw new SQLException(TestResource.getResource("R_unexpectedException") + ": ", e);
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

assertEquals(true, stmt.isCloseOnCompletion(),
Expand All @@ -905,9 +899,7 @@ public void testCloseOnCompletion() throws Exception {
try {
stmt.closeOnCompletion();
} catch (Exception e) {

throw new SQLException(TestResource.getResource("R_unexpectedException") + ": ", e);

fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

try (ResultSet rs = stmt.executeQuery("SELECT 1")) {
Expand All @@ -933,7 +925,7 @@ public void testConsecutiveQueries() throws SQLException {
try {
stmt.closeOnCompletion();
} catch (Exception e) {
throw new SQLException(TestResource.getResource("R_unexpectedException") + ": ", e);
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table1Name), stmt);
Expand Down Expand Up @@ -973,7 +965,7 @@ public void testMaxFetchSize() throws SQLException {
try {
newValue = Integer.MAX_VALUE + 1;
stmt.setMaxFieldSize(newValue);
throw new SQLException("setMaxFieldSize(): max values should not be set");
fail(TestResource.getResource("R_expectedFailPassed"));
} catch (Exception e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_invalidLength")));
}
Expand Down Expand Up @@ -1004,15 +996,15 @@ public void testMaxRows() throws Exception {
try {
newValue = Integer.MAX_VALUE + 1;
stmt.setMaxRows(newValue);
throw new SQLException("setMaxRows(): Long values should not be set");
fail(TestResource.getResource("R_expectedFailPassed"));
} catch (Exception e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_invalidRowcount")));
}

// Set a negative value. If negative is accepted, throw exception
try {
stmt.setMaxRows(-2012);
throw new SQLException("setMaxRows(): Negative value not allowed");
fail(TestResource.getResource("R_expectedFailPassed"));
} catch (Exception e) {
assertTrue(
e.getMessage()
Expand Down Expand Up @@ -1043,7 +1035,7 @@ public void testLargeMaxRows() throws Exception {
try {
newValue = (long) Integer.MAX_VALUE + 1;
stmt.setLargeMaxRows(newValue);
throw new SQLException("setLargeMaxRows(): Long values should not be set");
fail(TestResource.getResource("R_expectedFailPassed"));
} catch (Exception e) {
assertTrue(
e.getMessage().contains(
Expand All @@ -1054,7 +1046,7 @@ public void testLargeMaxRows() throws Exception {
// Set a negative value. If negative is accepted, throw exception
try {
stmt.setLargeMaxRows(-2012L);
throw new SQLException("setLargeMaxRows(): Negative value not allowed");
fail(TestResource.getResource("R_expectedFailPassed"));
} catch (Exception e) {
assertTrue(
e.getMessage()
Expand Down Expand Up @@ -1525,7 +1517,7 @@ public void testRowError() throws Exception {
try {
cstmt.closeOnCompletion();
} catch (Exception e) {
throw new SQLException(TestResource.getResource("R_unexpectedException"));
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

try (ResultSet rs = cstmt.executeQuery()) {
Expand Down Expand Up @@ -2010,7 +2002,7 @@ public void testActiveResultSet() throws Exception {
try {
stmt.closeOnCompletion();
} catch (Exception e) {
throw new SQLException(TestResource.getResource("R_unexpectedException"));
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

try (SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery("SELECT 1")) {
Expand Down Expand Up @@ -2040,7 +2032,7 @@ public void testClosedResultSet() throws Exception {
try {
stmt.closeOnCompletion();
} catch (Exception e) {
throw new SQLException(TestResource.getResource("R_unexpectedException"));
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

try (SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery("SELECT 1")) {
Expand Down Expand Up @@ -2120,7 +2112,7 @@ public void setup() throws Exception {
+ TestUtils.escapeSingleQuotes((triggerName)) + "') drop trigger "
+ AbstractSQLGenerator.escapeIdentifier(triggerName));
} catch (SQLException e) {
throw new SQLException(e);
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}
stmt.executeUpdate(
"CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 INT )");
Expand Down Expand Up @@ -2307,7 +2299,7 @@ public void testUpdateCountAfterRaiseError() throws Exception {
try {
pstmt.closeOnCompletion();
} catch (Exception e) {
throw new SQLException(TestResource.getResource("R_unexpectedException"));
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

boolean result = pstmt.execute();
Expand Down Expand Up @@ -2449,7 +2441,7 @@ public void terminate() throws Exception {
try {
TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt);
} catch (SQLException e) {
fail(e.getMessage());
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}
}
}
Expand All @@ -2472,7 +2464,7 @@ public void setup() throws Exception {
try {
stmt.closeOnCompletion();
} catch (Exception e) {
throw new SQLException(TestResource.getResource("R_unexpectedException"), e);
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}
stmt.executeUpdate(
"CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 INT )");
Expand Down Expand Up @@ -2521,7 +2513,7 @@ public void terminate() throws Exception {
try {
TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt);
} catch (SQLException e) {
fail(e.getMessage());
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}
}
}
Expand Down

0 comments on commit 9033a47

Please sign in to comment.