01: // Copyright (c) 2002 Cunningham & Cunningham, Inc.
02: // Released under the terms of the GNU General Public License version 2 or later.
03:
04: package fit;
05:
06: import junit.framework.TestCase;
07: import java.util.LinkedList;
08:
09: public class RowFixtureTest extends TestCase {
10:
11: class BusinessObject {
12: private String[] strs;
13:
14: public BusinessObject(String[] strs) {
15: this .strs = strs;
16: }
17:
18: public String[] getStrings() {
19: return strs;
20: }
21: }
22:
23: public RowFixtureTest(String name) {
24: super (name);
25: }
26:
27: public void testMatch() throws Exception {
28:
29: /*
30: Now back to the bug I found: The problem stems from the fact
31: that java doesn't do deep equality for arrays. Little known to
32: me (I forget easily ;-), java arrays are equal only if they
33: are identical. Unfortunately the 2 sort methods returns a map
34: that is directly keyed on the value of the column without
35: considering this little fact. Conclusion there is a missing
36: and a surplus row where there should be one right row.
37: -- Jacques Morel
38: */
39:
40: RowFixture fixture = new TestRowFixture();
41: TypeAdapter arrayAdapter = TypeAdapter.on(fixture,
42: BusinessObject.class.getMethod("getStrings",
43: new Class[0]));
44: fixture.columnBindings = new TypeAdapter[] { arrayAdapter };
45:
46: LinkedList computed = new LinkedList();
47: computed.add(new BusinessObject(new String[] { "1" }));
48: LinkedList expected = new LinkedList();
49: expected.add(new Parse("tr", "", new Parse("td", "1", null,
50: null), null));
51: fixture.match(expected, computed, 0);
52: assertEquals("right", 1, fixture.counts.right);
53: assertEquals("exceptions", 0, fixture.counts.exceptions);
54: assertEquals("missing", 0, fixture.missing.size());
55: assertEquals("surplus", 0, fixture.surplus.size());
56: }
57:
58: private class TestRowFixture extends RowFixture {
59: public Object[] query() throws Exception // get rows to be compared
60: {
61: return new Object[0];
62: }
63:
64: public Class getTargetClass() // get expected type of row
65: {
66: return BusinessObject.class;
67: }
68: }
69: }
|