为DoubleClick Listener编写Junit测试类

时间:2014-03-25 12:04:06

标签: junit swt

我需要为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完全不熟悉。

0 个答案:

没有答案