labs / tiddlers / content / reference / Testing / _Reference_Testing_GUI Testing_Checking the Contents of a List Component (JComboBox, JList).md

Sometimes you will need to check the contents of a list component (such as a JList or JComboBox). An example would be making sure that the report dialog is displaying the correct products in response to clicking the search button or category filter combobox.

You can check that the component contains the correct number of elements using:

// products JList should contain 2 products

To check for specific elements in the list component, you need to look at the component's model. You can use any of the usual Hamcrest collection matchers to check the model for specific elements.

// get the model
SimpleListModel model = (SimpleListModel) fixture.list("lstProducts").target().getModel();

// check the contents
assertThat(model, containsInAnyOrder(product1, product2, product3));