benjamin84 / fest

Automatically exported from code.google.com/p/fest
0 stars 0 forks source link

Unable to use JListFixture when CellRenderer.getListCellRendererComponent does not return a JLabel #124

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
I am attempting to use FEST-Swing 1.0a1 to verify functionality of a
GUI which contains a JList.  The JList uses a custom cell renderer
which extends JCheckbox (this is the problem) and implements
ListCellRenderer.  It also uses a custom list selection model which
extends DefaultListSelectionModel.

When I attempt to requireSelected(...) with either 1 or multiple
String parameters, the assertion fails.  The JListFixture.valueAt(int)
method returns null regardless of the actual values or selection(s).

I have verified that the values of the Object array backing the JList
have meaningful toString() names.
RobotFixture.printer().printComponents(System.out) shows:

javax.swing.JList[name='layerList', selectedValues=[StubFileName],
contents=[StubFileName, StubFileName2, StubFileName3],
selectionMode=MULTIPLE_INTERVAL_SELECTION, enabled=true, visible=true,
showing=true]

What is the expected output? What do you see instead?
expected: layerListFixture.valueAt(0) => StubFileName (for this example)
actual: layerListFixture.valueAt(0) => null (for any selection when using
the ListCellRenderers described above)

What version of the product are you using? On what operating system?
Fest 1.0a1 on RedHat Enterprise Linux 3

Please provide any additional information below.
The root of the issue seems to be
org.fest.swing.driver.CellRendererComponents line #32,
which returns null if the CellRenderer component is not a JLabel.
This does not make sense to me since the primary attribute of a
CellRenderer is that it implements ListCellRenderer and is a Component
(or at least can return a Component).

Perhaps it would make more sense if JListFixture simply had a method
which could return the array of selected Objects, and let the test
case deal with the assertion, rather than requiring that the match be
based on the (renderer component's) getText() value?  Alternatively, I
would like to be able to verify selection by index.  Testing the
selection(s) by comparing against the JList Objects' toString() result
is not particularly useful for me.

Original issue reported on code.google.com by woody.fo...@gmail.com on 8 Apr 2008 at 7:44

GoogleCodeExporter commented 9 years ago

Original comment by Alex.Rui...@gmail.com on 8 Apr 2008 at 9:14

GoogleCodeExporter commented 9 years ago
Hi Woody,

I'm working on this issue. I was thinking, in addition to returning the 
elements in
the JList, we could introduce some like a 'ValueToStringConverter', which 
converts an
element in a JList to a String, this way users could write:

layerListFixture.requireSelection("Hello", myConverter);

In addition, I'm thinking about also checking if a custom cell renderer is an
AbstractButton, and get the text using "getText".

To avoid confusion with this bug, I'm confirming we are adding methods to get an
element from the JList as it is (which is the original request in this bug.)

Do you consider these options helpful?

Thanks!
-Alex

Original comment by Alex.Rui...@gmail.com on 12 Apr 2008 at 3:02

GoogleCodeExporter commented 9 years ago
Introduced 'JListCellReader' to read values from JLists. Users can implement 
their
own JListCellReaders when using custom cell renderers in JLists. After creating 
a
JListCellRendering, users only need to pass an instance to the method
'cellReader(JListCellReader)' in JListFixture.

Original comment by Alex.Rui...@gmail.com on 2 May 2008 at 5:51

GoogleCodeExporter commented 9 years ago
Set the module as a label, instead of being part of the title.

Original comment by Alex.Rui...@gmail.com on 1 Dec 2008 at 1:55