|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.mockrunner.jdbc.ArrayResultSetFactory
public class ArrayResultSetFactory
A ResultSetFactory
implementation which will produce
MockResultSet
instances based on information given as
String
arrays.
StringValuesTable
and ArrayResultSetFactory
can
provide easy set up of unit test fixtures and assertion of outcomes with the
same data structures, without any need for external sources of test data:
private static final String _SQL_SELECT_ALL_EMPLOYEES = "SELECT * FROM employee"; private StringValuesTable _employeeQueryResults; ArrayResultSetFactory _arrayResultSetFactory; private Employee[] _employees; protected void setUp() throws Exception { super.setUp(); _employeeQueryResults = new StringValuesTable( "employeeQueryResults", new String[] { "id", "lastname", "firstname", }, new String[][] { new String[] {"1", "gibbons", "peter"}, new String[] {"2", "lumbergh", "bill"}, new String[] {"3", "waddams", "milton"}, } ); _employees = new Employee[3] { new Employee( _employeeQueryResults.getItem(1, "id"), _employeeQueryResults.getItem(1, "lastname"), _employeeQueryResults.getItem(1, "firstname"), ), ... }; ... } public void testGetEmployees() throws Exception { PreparedStatementResultSetHandler preparedStatementResultSetHandler = getPreparedStatementResultSetHandler(); _arrayResultSetFactory = new ArrayResultSetFactory(_employeeQueryResults); MockResultSet resultSet = preparedStatementResultSetHandler.createResultSet( _employeeQueryResults.getName(), arrayResultSetFactory); preparedStatementResultSetHandler.prepareResultSet( _SQL_SELECT_ALL_EMPLOYEES, resultSet); // execute query, perhaps calling method on an EmployeeDAO... assertEquals( _employeeQueryResults.getNumberOfRows(), resultsList.size()); for (int i = 0; i < _employees.length; i++) { assertTrue(resultsList.contains(_employees[i])); } MockResultSet mockResultSet = preparedStatementResultSetHandler.getResultSet( SQL_SELECT_ALL_EMPLOYEES); int rows = mockResultSet.getRowCount(); for (int row = 1; row <= rows; row++) { verifyResultSetRow( _employeeQueryResults.getName(), row, _employeeQueryResults.getRow(row)); } verifySQLStatementExecuted(_SQL_SELECT_ALL_EMPLOYEES); verifyAllResultSetsClosed(); verifyAllStatementsClosed(); verifyConnectionClosed(); }
Constructor Summary | |
---|---|
ArrayResultSetFactory(java.lang.String[][] stringMatrix)
Creates a new ArrayResultSetFactory with the given matrix
for data representation. |
|
ArrayResultSetFactory(java.lang.String[] columnNames,
java.lang.String[][] stringMatrix)
Creates a new ArrayResultSetFactory with the given set of
column names and the given matrix for data representation. |
|
ArrayResultSetFactory(StringValuesTable stringValuesTable)
Creates a new ArrayResultSetFactory that will produce
result sets based on information in the given
StringValuesTable . |
Method Summary | |
---|---|
MockResultSet |
create(java.lang.String id)
Returns a MockResultSet with the given ID, containing
values based on the elements given at construction. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ArrayResultSetFactory(StringValuesTable stringValuesTable)
ArrayResultSetFactory
that will produce
result sets based on information in the given
StringValuesTable
.
stringValuesTable
- the StringValuesTable
to use. This argument
cannot be null
.public ArrayResultSetFactory(java.lang.String[][] stringMatrix)
ArrayResultSetFactory
with the given matrix
for data representation.
stringMatrix
- the data representation for the result sets this factory will
produce. This argument cannot be null
, must
not contain any null values, and each array in the matrix must
contain the same number of elements as the first (stringMatrix[0].length == stringMatrix[n].length
for any given valid row number, n
). Further,
this matrix must, at a minimum represent 1
row
and 1
column of items (stringMatrix.length >= 1
,
and stringMatrix[0].length >= 1
).public ArrayResultSetFactory(java.lang.String[] columnNames, java.lang.String[][] stringMatrix)
ArrayResultSetFactory
with the given set of
column names and the given matrix for data representation.
columnNames
- the column names for the result sets this factory will
produce. This argument may be null
if no column
names are desired, but if a non-null
array
reference is given, the array cannot contain any
null
nor duplicate elements, and must have the
same number of elements as there are columns in the given
string matrix (stringMatrix[n]
for any given
valid row number, n
).stringMatrix
- the data representation for the result sets this factory will
produce. This argument cannot be null
, must
not contain any null values, and each array in the matrix must
contain the same number of elements as the first (stringMatrix[0].length == stringMatrix[n].length
for any given valid row number, n
). Further,
this matrix must, at a minimum represent 1
row
and 1
column of items (stringMatrix.length >= 1
,
and stringMatrix[0].length >= 1
).Method Detail |
---|
public MockResultSet create(java.lang.String id)
MockResultSet
with the given ID, containing
values based on the elements given at construction.
create
in interface ResultSetFactory
id
- the ID for the result set. This argument cannot be
null
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |