1 6 21 22 package org.springframework.jdbc; 23 24 import java.sql.Connection ; 25 26 import javax.sql.DataSource ; 27 28 import junit.framework.TestCase; 29 import org.easymock.MockControl; 30 31 34 public abstract class AbstractJdbcTests extends TestCase { 35 36 protected MockControl ctrlDataSource; 37 protected DataSource mockDataSource; 38 protected MockControl ctrlConnection; 39 protected Connection mockConnection; 40 41 46 private boolean shouldVerify; 47 48 protected void setUp() throws Exception { 49 this.shouldVerify = false; 50 super.setUp(); 51 52 ctrlConnection = MockControl.createControl(Connection .class); 53 mockConnection = (Connection ) ctrlConnection.getMock(); 54 mockConnection.getMetaData(); 55 ctrlConnection.setDefaultReturnValue(null); 56 mockConnection.close(); 57 ctrlConnection.setDefaultVoidCallable(); 58 59 ctrlDataSource = MockControl.createControl(DataSource .class); 60 mockDataSource = (DataSource ) ctrlDataSource.getMock(); 61 mockDataSource.getConnection(); 62 ctrlDataSource.setDefaultReturnValue(mockConnection); 63 } 64 65 protected void replay() { 66 ctrlDataSource.replay(); 67 ctrlConnection.replay(); 68 this.shouldVerify = true; 69 } 70 71 protected void tearDown() throws Exception { 72 super.tearDown(); 73 74 if (shouldVerify()) { 76 ctrlDataSource.verify(); 77 ctrlConnection.verify(); 78 } 79 } 80 81 protected boolean shouldVerify() { 82 return this.shouldVerify; 83 } 84 85 } 86 | Popular Tags |