我需要为DoubleClickImplementation
课程编写一个Junit测试类。这是代码:
DoubleClickImplementation.java
public class DoubleClickImplementation implements IDoubleClickListener {
private TreeViewer treeViewer;
public DoubleClickImplementation(TreeViewer viewer) {
this.treeViewer = viewer;
}
/**
* Expands and Collapses the tree items.
*
* @param event
*
*/
@Override
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
if (selection == null || selection.isEmpty()) {
return;
}
Object item = selection.getFirstElement();
ITreeContentProvider provider = (ITreeContentProvider) treeViewer.getContentProvider();
if (!provider.hasChildren(item)) {
return;
}
if (treeViewer.getExpandedState(item)) {
treeViewer.collapseToLevel(item, AbstractTreeViewer.ALL_LEVELS);
} else {
treeViewer.expandToLevel(item, 1);
}
}
}
这就是我从另一个名为DoubleClickImplementation
RepoView
类的方法
private TreeViewer browseTreeViewer;
private DoubleClickImplementation doubleClickExpansionListener;
doubleClickExpansionListener = new DoubleClickImplementation(browseTreeViewer);
browseTreeViewer.addDoubleClickListener(doubleClickExpansionListener);
请为上面提到的DoubleClickImplementation
班级的doubleClick()
方法提供一个Junit测试课程。我对JUnits完全不熟悉。