01: /******************************************************************************
02: * jWebUnit project (http://jwebunit.sourceforge.net) *
03: * Distributed open-source, see full license under LICENCE.txt *
04: ******************************************************************************/package net.sourceforge.jwebunit.html;
05:
06: import java.util.ArrayList;
07:
08: import junit.framework.Assert;
09:
10: /**
11: * Represents a row of an html table.
12: *
13: * @author Jim Weaver
14: * @author Julien Henry
15: */
16: public class Row {
17:
18: private ArrayList cells = new ArrayList();;
19:
20: public Row() {
21: }
22:
23: /**
24: * Construct a row from an array of objects which specify the cells of the row. If an object in the array is an
25: * {@link net.sourceforge.jwebunit.html.Cell}, it is directly added to the cells of the row, otherwise an
26: * {@link net.sourceforge.jwebunit.html.Cell} is created from the toString() value of the object and an assumed
27: * colspan of 1.
28: *
29: * @param rowCells objects representing the row's cells.
30: */
31: public Row(Object[] rowCells) {
32: appendCells(rowCells);
33: }
34:
35: public void appendCells(Object[] rowCells) {
36: for (int i = 0; i < rowCells.length; i++) {
37: Object column = rowCells[i];
38: if (column instanceof Cell) {
39: this .cells.add((Cell) column);
40: } else {
41: this .cells.add(new Cell(column.toString()));
42: }
43: }
44: }
45:
46: public void appendCell(Cell cell) {
47: cells.add(cell);
48: }
49:
50: public void appendCell(String cellText) {
51: cells.add(new Cell(cellText));
52: }
53:
54: public ArrayList getCells() {
55: return cells;
56: }
57:
58: public int getCellCount() {
59: return cells.size();
60: }
61:
62: public boolean hasText(String text) {
63: for (int i = 0; i < getCellCount(); i++) {
64: Cell c = (Cell) getCells().get(i);
65: if (c.equals(text))
66: return true;
67: }
68: return false;
69: }
70:
71: public boolean hasMatch(String regexp) {
72: for (int i = 0; i < getCellCount(); i++) {
73: Cell c = (Cell) getCells().get(i);
74: if (c.match(regexp))
75: return true;
76: }
77: return false;
78: }
79:
80: public void assertEquals(Row r) {
81: Assert.assertTrue("Cell count are not equal", this .getCells()
82: .size() == r.getCells().size());
83: for (int i = 0; i < this .getCells().size(); i++) {
84: ((Cell) this .getCells().get(i)).assertEquals((Cell) r
85: .getCells().get(i));
86: }
87: }
88:
89: public void assertMatch(Row r) {
90: Assert.assertTrue("Cell count are not equal", this .getCells()
91: .size() == r.getCells().size());
92: for (int i = 0; i < this .getCells().size(); i++) {
93: ((Cell) this .getCells().get(i)).assertMatch((Cell) r
94: .getCells().get(i));
95: }
96: }
97: }
|