assertj-swing
assertj-swing copied to clipboard
JListFixture and JListItemFixture assume Jlist's contain Strings. That's wrong. That contain Objects.
Issue by Steve Buroff from Tue, 15 Dec 2009 07:30:20 -0600 Originally opened as http://jira.codehaus.org/browse/FEST-276
A JList can contain any kind of Object, not just a string. The default ListCellRenderer
will display the value returned by the object's toString() value. However, the list's
contents are still objects. In addition, by writing one's own ListCellRenderer you
can display the objects without using their toString(). Fest really needs to
support this. If it already does in some way please let me know.
I think I am probably not the only developer who puts Objexts in a JList and displays
them with a custom ListCellRenderer. For me this is a show
stopper since the application I'm testing has several lists like that.
One other question. Should JListFixture have a way to add an element to the JList?
votes (original issue): 0 watches (original issue): 0
Comment by hermit69 from Tue, 15 Dec 2009 08:21:48 -0600
I just noticed that JComboBoxFixture has the same problem. For example,
JComboBoxFixture.selectItem(String) should take an Object, not a String.
Comment by alexruiz from Tue, 15 Dec 2009 17:38:44 -0600
Hi Steve,
The String that the method takes represents the String representation of an Object in the JList. This is on purpose. One of the purposes of functional testing with FEST is to simulate user input. When selecting an item in a JList, the user doesn't care about the type of the Object in the JList, he/she just wants to select an item by reading its text.
Comment by hermit69 from Wed, 16 Dec 2009 07:52:05 -0600
I disagree. First of all, the user might well not see a String. How about a
list or combo box with a custom cell renderer?
More important, whatever the user sees, when I want to get an item from a
list or combo box to check that it is correct, I need to get the object.
You code for extracting a "specified by index" or "selected" item from
the list bombs because the list doesn't contain a string. In one case it
contains a subclass of JPanel and in one case an enum. In both cases there
is a custom renderer or a custom model.
Since I can't get the selected item out of the list when it doesn't contain
a string I definitely think this is a bug!
If you still aren't convinced, here is one of my scenarios that I can't
test.
1. I display a dialog with many text fields, radio buttons, etc. My
Fest code fills all of the fields and clicks "OK" on the dialog.
This is working except for the combo box and JList in the dialog
which I can't select from because of this bug.
2. The program under test constructs an object of one of the program's
classes (not a component) written to represent the data from all
the fields and inserts the object into a JList that has been created with
a special cell renderer. The object is supposed to be inserted in sorted
order.
3. I want to write test code that finds the object in the JList, checks
that it has been constructed correctly, and that it is in the
correct order in the list.
Right now I can't do all of 1 or any of 3. Unless you can tell me how to
do it I think it's a bug (or, if you prefer, a design error). If I can't
test the above scenario I can't use Fest.
With regard to your answer:
1. " When selecting an item in a JList, the user doesn't care about the
type of the Object in the JList, he/she just wants to select an item
by reading its text."
As I pointed out below, this is simply not true. In several of my
JLists the user sees a JPanel with various labels, fields, lists, etc.
2. "the user doesn't care about the type of the Object in the list".
The user doesn't care about the object but the tester does!. I need
to get the JPanel for the selected list element (and for each element)
in order to check that it was constructed correctly.
Steve
Comment by hermit69 from Mon, 28 Dec 2009 06:53:55 -0600
One other point I should have made - being able to directly manipulate
containers can be very useful is setting up for a test. Suppose I have
an application that has a JList. I need to create 10 entries before I can
test a particular function. I probably can populate the list in the same
way a user would. However, it would be much faster and easier to have
the fixed data in the test program and use it to directly populate the
JList. After that I could use the user interface via Fest to test a
particular user function on the list. I would, of course, still need to get
the actual objects out of the JList to check that the results were
correct. The same applies to JComboBox, JTable, JTree, etc.
Steve
Comment by alexruiz from Mon, 4 Jan 2010 21:26:00 -0600
Now I understand Steve's point. There are times that there isn't a String representation of a value in a JList, JComboBox and JTable. The scope of this task is pretty big, since it not only involves JListFixture, but also JComboBoxFixture and JTableFixture (to keep consistency in the API.)
It is important to note that this change needs to be made not only when selecting an item, but also when obtaining the current selection.
I already started to work on this issue, and I hope I'll have enough time to finish it before the 1.2a4 release (mid-January.) The worst-case scenario is to have this issue fixed for 1.2b1.
For the record, I'm not planning to delay the 1.2a4 release. We have 30 issues resolved so far, which is a good indication that there are enough features/bug fixes that need to be pushed to our users.