01: // Modified or written by Object Mentor, Inc. for inclusion with FitNesse.
02: // Copyright (c) 2002 Cunningham & Cunningham, Inc.
03: // Released under the terms of the GNU General Public License version 2 or later.
04: package fit;
05:
06: import junit.framework.TestCase;
07: import java.lang.reflect.*;
08:
09: public class ColumnFixtureTest extends TestCase {
10: private TestFixture fixture;
11:
12: static class TestFixture extends ColumnFixture {
13: public int method() {
14: return 86;
15: }
16:
17: public int field;
18: public String stringField;
19:
20: public String stringMethod() {
21: return null;
22: }
23: }
24:
25: protected void setUp() throws Exception {
26: fixture = new TestFixture();
27: }
28:
29: public void testBindColumnToMethod() throws Exception {
30: String[] methodSpecifiers = new String[] { "method()",
31: "method?", "method!", "string method()",
32: "string method?", "string method!" };
33: String[] resultingMethodName = new String[] { "method",
34: "method", "method", "stringMethod", "stringMethod",
35: "stringMethod" };
36: for (int i = 0; i < methodSpecifiers.length; i++) {
37: Parse table = new Parse("<table><tr><td>"
38: + methodSpecifiers[i] + "</td></tr></table>");
39: Parse tableHead = table.parts.parts;
40: fixture.bind(tableHead);
41: assertNotNull(methodSpecifiers[i] + " no binding found.",
42: fixture.columnBindings[0]);
43: Method method = fixture.columnBindings[0].adapter.method;
44: assertNotNull(methodSpecifiers[i] + "no method found.",
45: method);
46: assertEquals(resultingMethodName[i], method.getName());
47: }
48: }
49:
50: public void testBindColumnToField() throws Exception {
51: Parse table = new Parse(
52: "<table><tr><td>field</td></tr></table>");
53: Parse tableHead = table.parts.parts;
54: fixture.bind(tableHead);
55: assertNotNull(fixture.columnBindings[0]);
56: Field field = fixture.columnBindings[0].adapter.field;
57: assertNotNull(field);
58: assertEquals("field", field.getName());
59: }
60:
61: public void testGracefulColumnNames() throws Exception {
62: Parse table = new Parse(
63: "<table><tr><td>string field</td></tr></table>");
64: Parse tableHead = table.parts.parts;
65: fixture.bind(tableHead);
66: assertNotNull(fixture.columnBindings[0]);
67: Field field = fixture.columnBindings[0].adapter.field;
68: assertNotNull(field);
69: assertEquals("stringField", field.getName());
70: }
71:
72: public void testBindColumnToFieldSymbol() throws Exception {
73: Fixture.setSymbol("Symbol", "42");
74: Parse table = new Parse(
75: "<table><tr><td>field=</td></tr><tr><td>Symbol</td></tr></table>");
76: Parse rows = table.parts;
77: fixture.doRows(rows);
78: Binding binding = fixture.columnBindings[0];
79: assertNotNull(binding);
80: assertEquals(Binding.RecallBinding.class, binding.getClass());
81: Field field = binding.adapter.field;
82: assertNotNull(field);
83: assertEquals("field", field.getName());
84: assertEquals(42, fixture.field);
85: }
86:
87: public void testBindColumnToMethodSymbol() throws Exception {
88: Parse table = new Parse(
89: "<table><tr><td>=method?</td></tr><tr><td>MethodSymbol</td></tr></table>");
90: Parse rows = table.parts;
91: fixture.doRows(rows);
92: Binding binding = fixture.columnBindings[0];
93: assertNotNull(binding);
94: assertEquals(Binding.SaveBinding.class, binding.getClass());
95: Method method = binding.adapter.method;
96: assertEquals("method", method.getName());
97: assertEquals("86", Fixture.getSymbol("MethodSymbol"));
98: }
99: }
|