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.apache.regexp.RE;
22 import org.apache.regexp.RESyntaxException;
23 import org.junit.Assert;
24
25
26
27
28
29
30
31 public class Cell {
32
33 private int colspan;
34
35 private int rowspan;
36
37 private String value;
38
39
40
41
42
43
44 public Cell(String value) {
45 this(value, 1, 1);
46 }
47
48
49
50
51
52
53
54
55 public Cell(String value, int colspan, int rowspan) {
56 this.value = value;
57 this.colspan = colspan;
58 this.rowspan = rowspan;
59 }
60
61
62
63
64 public int getColspan() {
65 return colspan;
66 }
67
68
69
70
71 public int getRowspan() {
72 return rowspan;
73 }
74
75
76
77
78 public final String getValue() {
79 return value;
80 }
81
82
83
84
85
86
87 public void assertEquals(Cell c) {
88 Assert.assertTrue(c.getValue() + " do not equal " + this.getValue(),
89 this.getValue().equals(c.getValue()));
90 Assert.assertTrue("Expected colspan was " + c.getColspan()
91 + " but was " + this.getColspan(), this.getColspan() == c
92 .getColspan());
93 Assert.assertTrue("Expected rowspan was " + c.getRowspan()
94 + " but was " + this.getRowspan(), this.getRowspan() == c
95 .getRowspan());
96 }
97
98
99
100
101
102
103 public void assertMatch(Cell c) {
104 RE re = getRE(c.getValue());
105 Assert.assertTrue(c.getValue() + " do not match " + this.getValue(), re
106 .match(this.getValue()));
107 Assert.assertTrue("Expected colspan was " + c.getColspan()
108 + " but was " + this.getColspan(), this.getColspan() == c
109 .getColspan());
110 Assert.assertTrue("Expected rowspan was " + c.getRowspan()
111 + " but was " + this.getRowspan(), this.getRowspan() == c
112 .getRowspan());
113 }
114
115
116
117
118
119
120
121 public boolean equals(String text) {
122 return this.getValue().equals(text);
123 }
124
125
126
127
128
129
130
131 public boolean match(String regexp) {
132 RE re = getRE(regexp);
133 return re.match(this.getValue());
134 }
135
136
137
138
139
140
141
142 private RE getRE(String regexp) {
143 RE re = null;
144 try {
145 re = new RE(regexp, RE.MATCH_SINGLELINE);
146 } catch (RESyntaxException e) {
147 Assert.fail(e.toString());
148 }
149 return re;
150 }
151 }