1 21 22 package org.dbunit.operation; 23 24 import com.mockobjects.ExpectationCounter; 25 import com.mockobjects.Verifiable; 26 import org.dbunit.DatabaseUnitException; 27 import org.dbunit.database.IDatabaseConnection; 28 import org.dbunit.dataset.IDataSet; 29 30 import java.sql.SQLException ; 31 32 37 public class MockDatabaseOperation extends DatabaseOperation implements Verifiable 38 { 39 private ExpectationCounter _executeCalls = 40 new ExpectationCounter("MockDatabaseOperation.execute"); 41 private Exception _executeException = null; 42 43 public void setExpectedExecuteCalls(int callsCount) 44 { 45 _executeCalls.setExpected(callsCount); 46 } 47 48 public void setupThrowExceptionOnExecute(Exception exception) 49 { 50 _executeException = exception; 51 } 52 53 54 57 public void verify() 58 { 59 _executeCalls.verify(); 60 } 61 62 65 public void execute(IDatabaseConnection connection, IDataSet dataSet) 66 throws DatabaseUnitException, SQLException 67 { 68 _executeCalls.inc(); 69 70 if (_executeException instanceof SQLException ) 71 { 72 throw (SQLException )_executeException; 73 } 74 else if (_executeException instanceof DatabaseUnitException) 75 { 76 throw (DatabaseUnitException)_executeException; 77 } 78 else if (_executeException instanceof RuntimeException ) 79 { 80 throw (RuntimeException )_executeException; 81 } 82 } 83 } 84 85 86 | Popular Tags |