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@776 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -308,68 +308,67 @@ public class MockCallableStatement extends MockPreparedStatement implements Call
|
||||
|
||||
@Override
|
||||
public URL getURL(int parameterIndex) throws SQLException {
|
||||
|
||||
return null;
|
||||
return (URL) getObject(parameterIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setURL(String parameterName, URL val) throws SQLException {
|
||||
|
||||
public void setURL(String parameterName, URL x) throws SQLException {
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNull(String parameterName, int sqlType) throws SQLException {
|
||||
|
||||
setObject(parameterName, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBoolean(String parameterName, boolean x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setByte(String parameterName, byte x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShort(String parameterName, short x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInt(String parameterName, int x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLong(String parameterName, long x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFloat(String parameterName, float x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDouble(String parameterName, double x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setString(String parameterName, String x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBytes(String parameterName, byte[] x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -379,62 +378,62 @@ public class MockCallableStatement extends MockPreparedStatement implements Call
|
||||
|
||||
@Override
|
||||
public void setTime(String parameterName, Time x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setObject(String parameterName, Object x) throws SQLException {
|
||||
|
||||
setObject(Integer.parseInt(parameterName), x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
|
||||
|
||||
public void setCharacterStream(String parameterName, Reader x, int length) throws SQLException {
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
|
||||
|
||||
setObject(parameterName, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -539,14 +538,12 @@ public class MockCallableStatement extends MockPreparedStatement implements Call
|
||||
|
||||
@Override
|
||||
public NClob getNClob(int parameterIndex) throws SQLException {
|
||||
|
||||
return null;
|
||||
return (NClob) getObject(parameterIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NClob getNClob(String parameterName) throws SQLException {
|
||||
|
||||
return null;
|
||||
return (NClob) getObject(parameterName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -562,104 +559,97 @@ public class MockCallableStatement extends MockPreparedStatement implements Call
|
||||
|
||||
@Override
|
||||
public SQLXML getSQLXML(String parameterName) throws SQLException {
|
||||
|
||||
return null;
|
||||
return (SQLXML) getObject(parameterName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNString(int parameterIndex) throws SQLException {
|
||||
|
||||
return null;
|
||||
return (String) getObject(parameterIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNString(String parameterName) throws SQLException {
|
||||
|
||||
return null;
|
||||
return (String) getObject(parameterName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader getNCharacterStream(int parameterIndex) throws SQLException {
|
||||
|
||||
return null;
|
||||
return (Reader) getObject(parameterIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader getNCharacterStream(String parameterName) throws SQLException {
|
||||
|
||||
return null;
|
||||
return (Reader) getObject(parameterName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader getCharacterStream(int parameterIndex) throws SQLException {
|
||||
|
||||
return null;
|
||||
return (Reader) getObject(parameterIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader getCharacterStream(String parameterName) throws SQLException {
|
||||
|
||||
return null;
|
||||
return (Reader) getObject(parameterName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlob(String parameterName, Blob x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClob(String parameterName, Clob x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBinaryStream(String parameterName, InputStream x, long length) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException {
|
||||
|
||||
public void setCharacterStream(String parameterName, Reader x, long length) throws SQLException {
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAsciiStream(String parameterName, InputStream x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBinaryStream(String parameterName, InputStream x) throws SQLException {
|
||||
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCharacterStream(String parameterName, Reader reader) throws SQLException {
|
||||
|
||||
public void setCharacterStream(String parameterName, Reader x) throws SQLException {
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNCharacterStream(String parameterName, Reader value) throws SQLException {
|
||||
|
||||
public void setNCharacterStream(String parameterName, Reader x) throws SQLException {
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClob(String parameterName, Reader reader) throws SQLException {
|
||||
|
||||
public void setClob(String parameterName, Reader x) throws SQLException {
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlob(String parameterName, InputStream inputStream) throws SQLException {
|
||||
|
||||
public void setBlob(String parameterName, InputStream x) throws SQLException {
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNClob(String parameterName, Reader reader) throws SQLException {
|
||||
|
||||
public void setNClob(String parameterName, Reader x) throws SQLException {
|
||||
setObject(parameterName, x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.alibaba.druid.bvt.pool.basic;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
@@ -28,10 +29,10 @@ public class PoolableCallableStatementTest extends TestCase {
|
||||
};
|
||||
|
||||
Assert.assertEquals(0, raw.getParameters().size());
|
||||
raw.registerOutParameter(1, Types.INTEGER);
|
||||
stmt.registerOutParameter(1, Types.INTEGER);
|
||||
Assert.assertEquals(1, raw.getParameters().size());
|
||||
|
||||
raw.registerOutParameter(2, Types.DECIMAL, 10);
|
||||
stmt.registerOutParameter(2, Types.DECIMAL, 10);
|
||||
Assert.assertEquals(2, raw.getParameters().size());
|
||||
}
|
||||
|
||||
@@ -241,7 +242,7 @@ public class PoolableCallableStatementTest extends TestCase {
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -403,7 +404,7 @@ public class PoolableCallableStatementTest extends TestCase {
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -415,4 +416,134 @@ public class PoolableCallableStatementTest extends TestCase {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void test_getNClob() throws Exception {
|
||||
|
||||
stmt.getNClob(1);
|
||||
stmt.getNClob("1");
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getNClob("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getNClob("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_getNString() throws Exception {
|
||||
|
||||
stmt.getNString(1);
|
||||
stmt.getNString("1");
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getNString("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getNString("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_getNCharacterStream() throws Exception {
|
||||
|
||||
stmt.getNCharacterStream(1);
|
||||
stmt.getNCharacterStream("1");
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getNCharacterStream("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getNCharacterStream("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_getCharacterStream() throws Exception {
|
||||
|
||||
stmt.getCharacterStream(1);
|
||||
stmt.getCharacterStream("1");
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getCharacterStream("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getCharacterStream("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_updateCharacterStream_2() throws Exception {
|
||||
|
||||
stmt.setCharacterStream(1, (Reader) null, 1L);
|
||||
stmt.setCharacterStream("1", (Reader) null, 1L);
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.setCharacterStream("0", (Reader) null, 1L);
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.setCharacterStream(0, (Reader) null, 1L);
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.alibaba.druid.bvt.pool.basic;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Date;
|
||||
import java.sql.SQLException;
|
||||
@@ -33,6 +34,11 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
};
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
stmt.clearParameters();
|
||||
Assert.assertEquals(0, raw.getParameters().size());
|
||||
}
|
||||
|
||||
public void test_basic() throws Exception {
|
||||
Assert.assertEquals(raw, stmt.getRawPreparedStatement());
|
||||
Assert.assertEquals(raw, stmt.getRawStatement());
|
||||
@@ -101,12 +107,12 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setInt() throws Exception {
|
||||
stmt.setInt(1, Integer.MAX_VALUE);
|
||||
|
||||
|
||||
Assert.assertEquals(new Integer(Integer.MAX_VALUE), raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -117,12 +123,12 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setLong() throws Exception {
|
||||
stmt.setLong(1, Long.MAX_VALUE);
|
||||
|
||||
|
||||
Assert.assertEquals(new Long(Long.MAX_VALUE), raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -133,12 +139,12 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setFloat() throws Exception {
|
||||
stmt.setFloat(1, Float.MAX_VALUE);
|
||||
|
||||
|
||||
Assert.assertEquals(new Float(Float.MAX_VALUE), raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -149,12 +155,12 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setDouble() throws Exception {
|
||||
stmt.setDouble(1, Double.MAX_VALUE);
|
||||
|
||||
|
||||
Assert.assertEquals(new Double(Double.MAX_VALUE), raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -165,12 +171,12 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setBigDecimal() throws Exception {
|
||||
stmt.setBigDecimal(1, BigDecimal.TEN);
|
||||
|
||||
|
||||
Assert.assertEquals(BigDecimal.TEN, raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -181,12 +187,12 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setString() throws Exception {
|
||||
stmt.setString(1, "中国");
|
||||
|
||||
|
||||
Assert.assertEquals("中国", raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -197,13 +203,13 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setBytes() throws Exception {
|
||||
byte[] bytes = "中国".getBytes();
|
||||
stmt.setBytes(1, bytes);
|
||||
|
||||
|
||||
Assert.assertEquals(true, Arrays.equals(bytes, (byte[]) raw.getParameters().get(0)));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -214,13 +220,13 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setDate() throws Exception {
|
||||
Date value = new Date(System.currentTimeMillis());
|
||||
stmt.setDate(1, value);
|
||||
|
||||
|
||||
Assert.assertEquals(value, raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -231,13 +237,13 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setTimestamp() throws Exception {
|
||||
Timestamp value = new Timestamp(System.currentTimeMillis());
|
||||
stmt.setTimestamp(1, value);
|
||||
|
||||
|
||||
Assert.assertEquals(value, raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -248,13 +254,13 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setAsciiStream() throws Exception {
|
||||
InputStream value = null;
|
||||
stmt.setAsciiStream(1, value);
|
||||
|
||||
|
||||
Assert.assertEquals(value, raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -265,14 +271,14 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void test_setUnicodeStream() throws Exception {
|
||||
InputStream value = null;
|
||||
stmt.setUnicodeStream(1, value, 0);
|
||||
|
||||
|
||||
Assert.assertEquals(value, raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -283,14 +289,14 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void test_setBinaryStream() throws Exception {
|
||||
InputStream value = null;
|
||||
stmt.setBinaryStream(1, value, 0);
|
||||
|
||||
|
||||
Assert.assertEquals(value, raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -301,4 +307,20 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_updateCharacterStream_2() throws Exception {
|
||||
|
||||
stmt.setCharacterStream(1, (Reader) null, 1L);
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.setCharacterStream(0, (Reader) null, 1L);
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user