Class GUIRunner.HierarchyWrapper
- java.lang.Object
-
- eu.simuline.testhelpers.GUIRunner.HierarchyWrapper
-
- All Implemented Interfaces:
GUIRunner.Selector,java.util.EventListener,javax.swing.event.TreeSelectionListener
- Enclosing class:
- GUIRunner
static class GUIRunner.HierarchyWrapper extends java.lang.Object implements GUIRunner.Selector, javax.swing.event.TreeSelectionListener
Represents the hierarchy of testsuites and testcases as a treehierarchyTreepossibly with a single selected node given bysingleSelectedNode.
-
-
Field Summary
Fields Modifier and Type Field Description private ActionsactionsThis is used only byvalueChanged(TreeSelectionEvent)to set the filter viaActions.setFilter(Description).private GUIRunner.TreePathIteratorcurrPathIterRepresents the path to the testcase currently run.private javax.swing.JTreehierarchyTreeThe hierarchy of testsuites and testcases as a tree.private GUIRunner.SelectorselectorSelector to be influenced: If this is in the selected tab,selectoris the tab with theTestCaseLister; otherwise it isGUIRunner.TabChangeListener.EMPTY_SELECTOR.private javax.swing.tree.DefaultMutableTreeNodesingleSelectedNodeRepresents the selected node inhierarchyTree.private GUIRunner.TestCaseListertestCaseListerThe theGUIRunner.TestCaseListerlisting the failed test cases.private javax.swing.tree.TreeSelectionModeltreeSelectionThe selection model forhierarchyTree.
-
Constructor Summary
Constructors Constructor Description HierarchyWrapper(Actions actions, GUIRunner.TestCaseLister testCaseLister)Creates a new HierarchyWrapper with the givenactionsandtestCaseListerwhich are used to initializeactionsandtestCaseLister.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearSelection()Clears the selection.(package private) voidcollapseAlongPath()Collapses the path to the leafcurrPathIterpoints to as much as possible in order not to hidesingleSelectedNodeand the leafs corresponding with singular tests which failed already (assumption failure, failure and error).(package private) voidexpandAlongPath()Expands the path to the leafcurrPathIterpoints to.(package private) ActionsgetActions()Returns the action.(package private) javax.swing.tree.TreePathgetPath()(package private) TestCasegetRoot()(package private) javax.swing.JTreegetTree()(package private) voidinitClassStructure(TestCase testCase)Notifies that the structure of the test class may have been updated.private booleanisSelected(TestCase testCase)Returns whether the given testcasetestCaseis selected in this HierarchyTree.(package private) voidnoteReportResult(TestCase testCase)Notifies that the singular testtestCaseis finished.(package private) TestCasenoteTestStartedI(Quality qual)Notifies that an atomic test is started or ignored.voidregisterSelector(GUIRunner.Selector selector)Acquaints this selector with another one which is notified of the selection events of thisSelector.private voidsetFilter()Sets the filter (given by a description) invokingActions.setFilter(Description): The description is taken fromsingleSelectedNode.voidsetSelection(int index)Sets selection ofindexth item and clears other selections.(package private) voidstartTestRun(Description desc)Notifies that a test run with structure given bydescis going to be run next.private static javax.swing.tree.DefaultMutableTreeNodetestCase2treeNode(TestCase testCase)Converts the (tree of) testcases given bytestCase.voidvalueChanged(javax.swing.event.TreeSelectionEvent selEvent)Called whenever the value of the selection changes.
-
-
-
Field Detail
-
hierarchyTree
private final javax.swing.JTree hierarchyTree
The hierarchy of testsuites and testcases as a tree. After creation this is a default tree, after invocation ofinitClassStructure(TestCase)the hierarchy reflects the given testcase. The selection model is given bytreeSelectionand this is theTreeSelectionListener.
-
treeSelection
private final javax.swing.tree.TreeSelectionModel treeSelection
The selection model forhierarchyTree. At most one entry is selected. If the entry represents a failure, the according element inGUIRunner.TestCaseLister.failureSelectionis selected also.- See Also:
valueChanged(TreeSelectionEvent)
-
actions
private final Actions actions
This is used only byvalueChanged(TreeSelectionEvent)to set the filter viaActions.setFilter(Description).
-
testCaseLister
private final GUIRunner.TestCaseLister testCaseLister
The theGUIRunner.TestCaseListerlisting the failed test cases. This is used innoteReportResult(TestCase)only and is to notify that a certain tescase failed and is selected.
-
singleSelectedNode
private javax.swing.tree.DefaultMutableTreeNode singleSelectedNode
Represents the selected node inhierarchyTree. This isnullif nothing selected which is also the initial value. This is set byvalueChanged(TreeSelectionEvent)and updated also byinitClassStructure(TestCase).
-
currPathIter
private GUIRunner.TreePathIterator currPathIter
Represents the path to the testcase currently run. This isnullafter this is created and is initialized bystartTestRun(Description).
-
selector
private GUIRunner.Selector selector
Selector to be influenced: If this is in the selected tab,selectoris the tab with theTestCaseLister; otherwise it isGUIRunner.TabChangeListener.EMPTY_SELECTOR. Set byregisterSelector(GUIRunner.Selector).
-
-
Constructor Detail
-
HierarchyWrapper
HierarchyWrapper(Actions actions, GUIRunner.TestCaseLister testCaseLister)
Creates a new HierarchyWrapper with the givenactionsandtestCaseListerwhich are used to initializeactionsandtestCaseLister.- Parameters:
actions- the Actions to be written intoactions.testCaseLister- TestCaseLister to be written intotestCaseLister.
-
-
Method Detail
-
testCase2treeNode
private static javax.swing.tree.DefaultMutableTreeNode testCase2treeNode(TestCase testCase)
Converts the (tree of) testcases given bytestCase. ****
-
getRoot
TestCase getRoot()
-
getActions
Actions getActions()
Returns the action. Invoked by the enclosing GUIRunner.
-
initClassStructure
void initClassStructure(TestCase testCase)
Notifies that the structure of the test class may have been updated.Converts the overall test case hierarchy
testCaseinto a a tree node hierarchy invokingtestCase2treeNode(TestCase). This defines the tree model of the hierarchyhierarchyTree. The selected nodesingleSelectedNodeis set to the root.Since
currPathIterpoints to the first testcase run, it is set tonull. Finally,actionsis notified about the test to be run next which is specified by the testcase given by the selected node. by invokingsetFilter().- Parameters:
testCase- a description of the test structure defined in the test class which is a hierarchy of suites and singular tests.
-
setFilter
private void setFilter()
Sets the filter (given by a description) invokingActions.setFilter(Description): The description is taken fromsingleSelectedNode.
-
startTestRun
void startTestRun(Description desc)
Notifies that a test run with structure given bydescis going to be run next.Sets the quality of the testcases given by
singleSelectedNoderecursively toQuality.Scheduledand setscurrPathIter.- Parameters:
desc- describes the (hierarchy of) tests to be run. This is a sub-hierarchy of the one given by the test class. This parameter is purely formally because it is given bysingleSelectedNode.
-
expandAlongPath
void expandAlongPath()
Expands the path to the leafcurrPathIterpoints to. This is invoked bynoteTestStartedI(Quality)when a testcase is started or ignored.- See Also:
collapseAlongPath()
-
collapseAlongPath
void collapseAlongPath()
Collapses the path to the leafcurrPathIterpoints to as much as possible in order not to hidesingleSelectedNodeand the leafs corresponding with singular tests which failed already (assumption failure, failure and error). This is invoked bynoteReportResult(TestCase)when a testcase is finished or after being ignored.- See Also:
expandAlongPath()
-
getTree
javax.swing.JTree getTree()
-
getPath
javax.swing.tree.TreePath getPath()
-
noteTestStartedI
TestCase noteTestStartedI(Quality qual)
Notifies that an atomic test is started or ignored.To Updates
currPathIterpointing to the current testcase and expands along the path given by the current testcase. Then sets the quality of the according testcase toqualand updates the according tree node.- Parameters:
qual- the quality of the testcase: This isQuality.StartedorQuality.Ignored.- Returns:
- the current testcase.
-
noteReportResult
void noteReportResult(TestCase testCase)
Notifies that the singular testtestCaseis finished.Collapses the current path invoking
collapseAlongPath(), updates the tree nodecurrPathIterpoints to and notifiestestCaseListeriftestCasefailed and is selected invokingGUIRunner.TestCaseLister.addSelectedTestCaseByNeed(TestCase).- Parameters:
testCase- The testcase comprising the result of the singular test finished.
-
isSelected
private boolean isSelected(TestCase testCase)
Returns whether the given testcasetestCaseis selected in this HierarchyTree.- Returns:
- whether the given testcase
testCaseis selected in this HierarchyTree.
-
setSelection
public void setSelection(int index)
Description copied from interface:GUIRunner.SelectorSets selection ofindexth item and clears other selections.- Specified by:
setSelectionin interfaceGUIRunner.Selector- Parameters:
index- a non-negativeintvalue representing the index of a testcase. **** CAUTION: This presupposes that in a tree only the leaves can be selected.
-
clearSelection
public void clearSelection()
Description copied from interface:GUIRunner.SelectorClears the selection.- Specified by:
clearSelectionin interfaceGUIRunner.Selector
-
registerSelector
public void registerSelector(GUIRunner.Selector selector)
Description copied from interface:GUIRunner.SelectorAcquaints this selector with another one which is notified of the selection events of thisSelector. The one in the foreground is notified directly by a mouse event, whereas the one in the background is selected via registration. The one in the background in turn notifies the empty selectorGUIRunner.TabChangeListener.EMPTY_SELECTORwhich takes no actions.- Specified by:
registerSelectorin interfaceGUIRunner.Selector- Parameters:
selector- anotherSelector.- See Also:
GUIRunner.TabChangeListener.setSelUnSel(int)
-
valueChanged
public void valueChanged(javax.swing.event.TreeSelectionEvent selEvent)
Called whenever the value of the selection changes. Note that deselection is treated as selection of the root, so w.l.o.g, we have to consider selections only.If an entry is selected,
singleSelectedNodeholds the selected node. Nextselectoris notified of the selection:- if a failure is selected (which is a leaf) triggers according selection in the failure list, otherwise triggers a deselection.
GUIRunner.TestCaseLister.valueChanged(ListSelectionEvent).Finally, invokes
setFilter()setting the filter for the next test run.- Specified by:
valueChangedin interfacejavax.swing.event.TreeSelectionListener
-
-