|
From: Jeff M. <cus...@us...> - 2002-01-28 18:03:40
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/sql
In directory usw-pr-cvs1:/tmp/cvs-serv17389
Modified Files:
MockConnection.java
Added Files:
MockDriver.java
Log Message:
Added Mock object for java.sql.Driver interface
Added support for counting close calls and throwing close exceptions in
MockConnection
--- NEW FILE: MockDriver.java ---
package com.mockobjects.sql;
import java.sql.*;
import java.util.*;
public class MockDriver implements Driver{
public static MockDriver myDriver = new MockDriver();
private Connection myConnection;
static{
try{
DriverManager.registerDriver(myDriver);
}catch(SQLException e){
e.printStackTrace();
}
}
public void setupConnect(Connection aConnection){
this.myConnection = aConnection;
}
public boolean acceptsURL(String url){
return true;
}
public Connection connect(String url, Properties info){
return myConnection;
}
public int getMajorVersion(){
return 0;
}
public int getMinorVersion(){
return 0;
}
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info){
return null;
}
public boolean jdbcCompliant(){
return false;
}
}
Index: MockConnection.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/sql/MockConnection.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MockConnection.java 2001/09/19 21:38:31 1.4
+++ MockConnection.java 2002/01/28 18:03:35 1.5
@@ -17,6 +17,10 @@
private ExpectationValue myAutoCommit = new ExpectationValue("MockConnection.setAutoCommit");
private Statement myStatement;
+ private boolean myIsClosed;
+ private SQLException myIsClosedException;
+ private SQLException myCloseException;
+
public MockConnection() {
super();
}
@@ -56,7 +60,14 @@
public void clearWarnings() throws SQLException {
}
+ public void setupCloseException(SQLException aCloseException){
+ myCloseException = aCloseException;
+ }
+
public void close() throws SQLException {
+ if(myCloseException!=null){
+ throw myCloseException;
+ }
myCloseCalls.inc();
}
@@ -102,8 +113,19 @@
throw new UnsupportedOperationException();
}
+ public void setupIsClosedException(SQLException aIsClosedException){
+ myIsClosedException = aIsClosedException;
+ }
+
+ public void setupIsClose(boolean aIsClosed){
+ myIsClosed = aIsClosed;
+ }
+
public boolean isClosed() throws SQLException {
- throw new UnsupportedOperationException();
+ if(myIsClosedException!=null){
+ throw myIsClosedException;
+ }
+ return myIsClosed;
}
public boolean isReadOnly() throws SQLException {
|