mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
完善mock和测试
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@786 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -739,41 +739,58 @@ public class MockResultSet implements ResultSet {
|
||||
|
||||
@Override
|
||||
public void insertRow() throws SQLException {
|
||||
|
||||
if (closed) {
|
||||
throw new SQLException("resultSet closed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRow() throws SQLException {
|
||||
|
||||
if (closed) {
|
||||
throw new SQLException("resultSet closed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRow() throws SQLException {
|
||||
|
||||
if (closed) {
|
||||
throw new SQLException("resultSet closed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshRow() throws SQLException {
|
||||
|
||||
if (closed) {
|
||||
throw new SQLException("resultSet closed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelRowUpdates() throws SQLException {
|
||||
|
||||
if (closed) {
|
||||
throw new SQLException("resultSet closed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveToInsertRow() throws SQLException {
|
||||
|
||||
if (closed) {
|
||||
throw new SQLException("resultSet closed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveToCurrentRow() throws SQLException {
|
||||
|
||||
if (closed) {
|
||||
throw new SQLException("resultSet closed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement getStatement() throws SQLException {
|
||||
if (closed) {
|
||||
throw new SQLException("resultSet closed");
|
||||
}
|
||||
return statement;
|
||||
}
|
||||
|
||||
@@ -909,14 +926,12 @@ public class MockResultSet implements ResultSet {
|
||||
|
||||
@Override
|
||||
public RowId getRowId(int columnIndex) throws SQLException {
|
||||
|
||||
return null;
|
||||
return (RowId) getObject(columnIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RowId getRowId(String columnLabel) throws SQLException {
|
||||
|
||||
return null;
|
||||
return (RowId) getObject(columnLabel);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -931,14 +946,16 @@ public class MockResultSet implements ResultSet {
|
||||
|
||||
@Override
|
||||
public int getHoldability() throws SQLException {
|
||||
|
||||
if (closed) {
|
||||
throw new SQLException("resultSet closed");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() throws SQLException {
|
||||
|
||||
return false;
|
||||
return closed;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1073,12 +1073,8 @@ public final class PoolableResultSet extends PoolableWrapper implements ResultSe
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement getStatement() throws SQLException {
|
||||
try {
|
||||
return stmt;
|
||||
} catch (Throwable t) {
|
||||
throw checkException(t);
|
||||
}
|
||||
public Statement getStatement() {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1467,6 +1467,32 @@ public class ResultSetTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
public void test_getRowId() throws Exception {
|
||||
resultSet.next();
|
||||
|
||||
resultSet.getRowId(1);
|
||||
resultSet.getRowId("1");
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
resultSet.getRowId(0);
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
resultSet.getRowId("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_getTimestamp() throws Exception {
|
||||
resultSet.next();
|
||||
|
||||
@@ -10,8 +10,8 @@ import com.alibaba.druid.mock.MockResultSet;
|
||||
import com.alibaba.druid.pool.PoolableResultSet;
|
||||
import com.alibaba.druid.pool.PoolableStatement;
|
||||
|
||||
|
||||
public class ResultSetTest2 extends TestCase {
|
||||
|
||||
private PoolableStatement stmt;
|
||||
private MockResultSet raw;
|
||||
private PoolableResultSet resultSet;
|
||||
@@ -32,11 +32,11 @@ public class ResultSetTest2 extends TestCase {
|
||||
raw.getRows().add(new Object[] { null });
|
||||
resultSet = new PoolableResultSet(stmt, raw);
|
||||
}
|
||||
|
||||
|
||||
public void test_rowDeleted() throws Exception {
|
||||
resultSet.rowDeleted();
|
||||
raw.close();
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -47,11 +47,11 @@ public class ResultSetTest2 extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_rowInserted() throws Exception {
|
||||
resultSet.rowInserted();
|
||||
raw.close();
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -62,11 +62,11 @@ public class ResultSetTest2 extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_rowUpdated() throws Exception {
|
||||
resultSet.rowInserted();
|
||||
raw.close();
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -77,11 +77,11 @@ public class ResultSetTest2 extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_getConcurrency() throws Exception {
|
||||
resultSet.getConcurrency();
|
||||
raw.close();
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -92,11 +92,11 @@ public class ResultSetTest2 extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_getType() throws Exception {
|
||||
resultSet.getType();
|
||||
raw.close();
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -107,12 +107,12 @@ public class ResultSetTest2 extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_FetchSize() throws Exception {
|
||||
resultSet.setFetchSize(10);
|
||||
Assert.assertEquals(10, resultSet.getFetchSize());
|
||||
raw.close();
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -122,6 +122,112 @@ public class ResultSetTest2 extends TestCase {
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
resultSet.setFetchSize(10);
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_getHoldability() throws Exception {
|
||||
resultSet.getHoldability();
|
||||
|
||||
raw.close();
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
resultSet.getHoldability();
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_getStatement() throws Exception {
|
||||
resultSet.getStatement();
|
||||
|
||||
raw.close();
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
raw.getStatement();
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_moveToCurrentRow() throws Exception {
|
||||
resultSet.moveToCurrentRow();
|
||||
|
||||
raw.close();
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
resultSet.moveToCurrentRow();
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_moveToInsertRow() throws Exception {
|
||||
resultSet.moveToInsertRow();
|
||||
|
||||
raw.close();
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
resultSet.moveToInsertRow();
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_cancelRowUpdates() throws Exception {
|
||||
resultSet.cancelRowUpdates();
|
||||
|
||||
raw.close();
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
resultSet.cancelRowUpdates();
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_refreshRow() throws Exception {
|
||||
resultSet.refreshRow();
|
||||
|
||||
raw.close();
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
resultSet.refreshRow();
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user