01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.fixtures;
04:
05: import fit.*;
06: import fit.exception.FitFailureException;
07:
08: public abstract class TableFixture extends Fixture {
09: protected Parse firstRow;
10:
11: public void doRows(Parse rows) {
12: firstRow = rows;
13: if (rows == null)
14: throw new FitFailureException(
15: "There are no rows in this table");
16: doStaticTable(rows.size());
17: }
18:
19: protected abstract void doStaticTable(int rows);
20:
21: protected Parse getCell(int row, int column) {
22: return firstRow.at(row, column);
23: }
24:
25: protected String getText(int row, int column) {
26: return getCell(row, column).text();
27: }
28:
29: protected boolean blank(int row, int column) {
30: return getText(row, column).equals("");
31: }
32:
33: protected void wrong(int row, int column) {
34: wrong(getCell(row, column));
35: }
36:
37: protected void right(int row, int column) {
38: right(getCell(row, column));
39: }
40:
41: protected void wrong(int row, int column, String actual) {
42: wrong(getCell(row, column), actual);
43: }
44:
45: protected void ignore(int row, int column) {
46: ignore(getCell(row, column));
47: }
48:
49: protected int getInt(int row, int column) {
50: int i = 0;
51: String text = getText(row, column);
52: if (text.equals("")) {
53: ignore(row, column);
54: return 0;
55: }
56: try {
57: i = Integer.parseInt(text);
58: } catch (NumberFormatException e) {
59: wrong(row, column);
60: }
61: return i;
62: }
63: }
|