C:\devel\mocks\src\com\ociweb\jnb\ex3\MockConnectionFactory.java

1    package com.ociweb.jnb.ex3; 
2     
3    public class MockConnectionFactory implements ConnectionFactory { 
4     
5        public boolean createConnectionCalled; 
6        public java.sql.Connection createConnectionReturn; 
7        public Throwable createConnectionException; 
8        public String createConnectionDatabaseDriver; 
9        public String createConnectionDatabaseURL; 
10       public String createConnectionUsername; 
11       public String createConnectionPassword; 
12       public java.sql.Connection createConnection(String databaseDriver, String databaseURL, String username, String password) throws java.sql.SQLException { 
13           createConnectionCalled = true; 
14           this.createConnectionDatabaseDriver = databaseDriver; 
15           this.createConnectionDatabaseURL = databaseURL; 
16           this.createConnectionUsername = username; 
17           this.createConnectionPassword = password; 
18           if (createConnectionException != null) { 
19               if (createConnectionException instanceof java.sql.SQLException) 
20                   throw (java.sql.SQLException) createConnectionException; 
21               if (createConnectionException instanceof RuntimeException) 
22                   throw (RuntimeException) createConnectionException; 
23               if (createConnectionException instanceof Error) 
24                   throw (Error) createConnectionException; 
25               throw new RuntimeException(); 
26           } 
27           return this.createConnectionReturn; 
28       } 
29    
30   }