void (String[] initialItems, int initialSelectionIdx, int selectionIndexAfterMerge, String... itemsToMerge) { final StringFinderRecursivePanel panel = createStringPanel(initialItems); disposeOnTearDown(panel); JBList<String> list = panel.getList(); CollectionListModel<String> model = panel.getListModel(); list.setSelectedIndex(initialSelectionIdx); ListSelectionListener selectionListener = new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (panel.isMergeListItemsRunning()) return; fail("selection changed"); } }; list.addListSelectionListener(selectionListener); panel.merge(model, list, Arrays.asList(itemsToMerge)); assertEquals(itemsToMerge.length, model.getSize()); for (int i = 0; i < itemsToMerge.length; i++) { assertEquals("idx:" + i + " " + toString(model.getItems(), ","), itemsToMerge[i], model.getElementAt(i)); } assertEquals(toString(model.getItems(), ","), selectionIndexAfterMerge, list.getSelectedIndex()); list.removeListSelectionListener(selectionListener); }