content.txt
2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Here's the fixture code for all of the examples given for the various list-based fixtures. You'll need to understand about fixture code for ''DoFixture'' in ''flow'' first.
Notice that ''ParamRowFixture'' avoids the need to write a subclass for ''!-RowFixture-!'' when it's used with ''DoFixture''.
''ArrayFixture'', ''SetFixture'' and ''SubsetFixture'' can all take the following collections as arguments to their constructors:
* ''Object[]''
* ''java.util.Collection''
* ''java.util.Iterator''
* ''java.util.Map[]'', in which case each element of the collection is a ''Map'' instead of an ''Object''. This is handy with dynamic collections, such as provided by ''!-javax.swing.TableModel-!''.
These three fixtures also treat a header label as referring to either an instance variable or a property (through a getter method) when an element is an ''Object'' (ie, not a ''Map''). All header labels are converted to a Java identifier using [[''extended camel casing''][.FitLibraryUserGuide.ExtendedCamelCase]].
These fixtures can also be used "stand-alone" (ie, not in ''flow'', where the first table is interpreted by a ''!-DoFixture-!''). In that case it's necessary to subclass them, as with ''!-RowFixture-!''.
----{{{public class StartListing extends fitlibrary.DoFixture {
private int[] ints;
public void listIs(int[] ints) {
this.ints = ints;
}
public Fixture orderedList() {
return new ArrayFixture(itemList());
}
public Fixture rowList() {
return new ItemRowFixture();
}
public Fixture set() {
return new SetFixture(itemList());
}
public Fixture subset() {
return new SubsetFixture(itemList());
}
public Fixture paramRowList() {
return new ParamRowFixture(itemArray(),Item.class);
}
private List itemList() {
return Arrays.asList(itemArray());
}
private Object[] itemArray() {
Object[] result = new Object[ints.length];
for (int i = 0; i < ints.length; i++)
result[i] = new Item(ints[i]);
return result;
}
public static class Item {
public int item;
public Item(int item) {
this.item = item;
}
}
public class ItemRowFixture extends fit.RowFixture {
public Object[] query() throws Exception {
return itemArray();
}
public Class getTargetClass() {
return Item.class;
}
}
}
}}}----
With [[''auto-wrapping''][.FitLibraryUserGuide.DoFixture.FixtureDetails]] in DoFixture, the method ''orderedList()'' could be written as:
----{{{ public List orderedList() {
return itemList();
}
}}}----
---- * ''Copyright (c) 2004, 2005 Rick Mugridge, Rimu Research.''
* ''Released under the terms of the GNU General Public License version 2 or later.''