import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Map;import junit.framework.TestCase; import junit.textui.TestRunner;
public class DBReaderTest extends TestCase {
public static void main(String[] args) { TestRunner.run(DBReaderTest.class); }
public DBReaderTest(String name) { super(name); }
public Statement createStatement() throws SQLException { return (Statement) Delegator.for(Statement.class, this); }
public ResultSet executeQuery(String query) throws SQLException { assertEquals( "SELECT * FROM test", query ); return (ResultSet) Delegator.for(ResultSet.class, this); }
private int i = -1; private String [] names = "Pete", "John", "Rick"?; private String [] aliases = "The King", "The Coward", "The Tester" ?;
public boolean next() { i++; return i < 3; }
public String getString(String column) throws SQLException { if (column.equals("name")) return names[i]; else if (column.equals("alias")) return aliases[i]; else fail(); return null; }
public void testReadMock() throws Exception { Connection c = (Connection) Delegator.for(Connection.class, this);
DBReader r = new DBReader(c); Map results = r.read("test"); assertEquals("The King", results.get("Pete")); assertEquals("The Coward", results.get("John")); assertEquals("The Tester", results.get("Rick")); } }
