SourceProductSelector { public void setSelectedProduct(Product product) { if (product == null) { productListModel.setSelectedItem(null); return; } if (productListModelContains(product)) { productListModel.setSelectedItem(product); } else { if (productFilter.accept(product)) { if (extraProduct != null) { productListModel.removeElement(extraProduct); extraProduct.dispose(); } productListModel.addElement(product); productListModel.setSelectedItem(product); extraProduct = product; } } } SourceProductSelector(AppContext appContext);  SourceProductSelector(AppContext appContext, String labelText); ProductFilter getProductFilter(); void setProductFilter(ProductFilter productFilter); synchronized void initProducts(); int getProductCount(); void setSelectedIndex(int index); Product getSelectedProduct(); void setCurrentDirectory(File directory); File getCurrentDirectory(); void setSelectedProduct(Product product); synchronized void releaseProducts(); void addSelectionChangeListener(SelectionChangeListener listener); void removeSelectionChangeListener(SelectionChangeListener listener); JComboBox<Object> getProductNameComboBox(); JLabel getProductNameLabel(); JButton getProductFileChooserButton(); JPanel createDefaultPanel();  }
@Test public void testSetSelectedProduct() throws Exception { SourceProductSelector selector = new SourceProductSelector(appContext, "Source"); selector.initProducts(); Product selectedProduct = selector.getSelectedProduct(); Assert.assertSame(appContext.getSelectedProduct(), selectedProduct); selector.setSelectedProduct(defaultProducts[1]); selectedProduct = selector.getSelectedProduct(); Assert.assertSame(defaultProducts[1], selectedProduct); Product oldProduct = new Product("new", "T1", 0, 0); oldProduct.setFileLocation(new File("")); selector.setSelectedProduct(oldProduct); selectedProduct = selector.getSelectedProduct(); Assert.assertSame(oldProduct, selectedProduct); Product newProduct = new Product("new", "T2", 0, 0); selector.setSelectedProduct(newProduct); selectedProduct = selector.getSelectedProduct(); Assert.assertSame(newProduct, selectedProduct); Assert.assertNull(oldProduct.getFileLocation()); }