View Javadoc
1   /*
2    *
3    * The DbUnit Database Testing Framework
4    * Copyright (C)2002-2004, DbUnit.org
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2.1 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   *
20   */
21  package org.dbunit.dataset;
22  
23  import com.mockobjects.Verifiable;
24  
25  import java.util.ArrayList;
26  import java.util.Iterator;
27  import java.util.List;
28  
29  /**
30   * @author Manuel Laflamme
31   * @since Apr 12, 2003
32   * @version $Revision$
33   */
34  public class MockDataSet extends AbstractDataSet implements Verifiable
35  {
36      private final List _tableList = new ArrayList();
37  
38      public void addTable(ITable table)
39      {
40          _tableList.add(table);
41      }
42  
43      public void addEmptyTable(String tableName)
44      {
45          _tableList.add(new DefaultTable(tableName));
46      }
47  
48      ////////////////////////////////////////////////////////////////////////////
49      // AbstractDataSet class
50  
51      protected ITableIterator createIterator(boolean reversed)
52              throws DataSetException
53      {
54          ITable[] tables = (ITable[])_tableList.toArray(new ITable[0]);
55          return new DefaultTableIterator(tables, reversed);
56      }
57  
58      ///////////////////////////////////////////////////////////////////////////
59      // Verifiable interface
60  
61      public void verify()
62      {
63          for (Iterator it = _tableList.iterator(); it.hasNext();)
64          {
65              ITable table = (ITable)it.next();
66              if (table instanceof Verifiable)
67              {
68                  ((Verifiable)table).verify();
69              }
70          }
71      }
72  }