1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jwebunit.html;
20
21 import org.junit.Assert;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26
27
28
29
30
31
32 public class Row {
33
34 private List<Cell> cells = new ArrayList<Cell>();
35
36 public Row() {
37 }
38
39
40
41
42
43
44
45
46
47 public Row(Object[] rowCells) {
48 appendCells(rowCells);
49 }
50
51 public void appendCells(Object[] rowCells) {
52 for (int i = 0; i < rowCells.length; i++) {
53 Object column = rowCells[i];
54 if (column instanceof Cell) {
55 this.cells.add((Cell) column);
56 } else {
57 this.cells.add(new Cell(column.toString()));
58 }
59 }
60 }
61
62 public void appendCell(Cell cell) {
63 cells.add(cell);
64 }
65
66 public void appendCell(String cellText) {
67 cells.add(new Cell(cellText));
68 }
69
70 public List<Cell> getCells() {
71 return cells;
72 }
73
74 public int getCellCount() {
75 return cells.size();
76 }
77
78 public boolean hasText(String text) {
79 for (int i = 0; i < getCellCount(); i++) {
80 Cell c = (Cell) getCells().get(i);
81 if (c.equals(text))
82 return true;
83 }
84 return false;
85 }
86
87 public boolean hasMatch(String regexp) {
88 for (int i = 0; i < getCellCount(); i++) {
89 Cell c = (Cell) getCells().get(i);
90 if (c.match(regexp))
91 return true;
92 }
93 return false;
94 }
95
96 public void assertEquals(Row r) {
97 Assert.assertTrue("Cell count are not equal",
98 this.getCells().size() == r.getCells().size());
99 for (int i = 0; i < this.getCells().size(); i++) {
100 ((Cell) this.getCells().get(i)).assertEquals((Cell) r.getCells()
101 .get(i));
102 }
103 }
104
105 public void assertMatch(Row r) {
106 Assert.assertTrue("Cell count are not equal",
107 this.getCells().size() == r.getCells().size());
108 for (int i = 0; i < this.getCells().size(); i++) {
109 ((Cell) this.getCells().get(i)).assertMatch((Cell) r.getCells()
110 .get(i));
111 }
112 }
113 }