diff options
| author | Markus Tiede | 2013-08-21 08:52:18 +0000 |
|---|---|---|
| committer | Markus Tiede | 2013-08-21 08:52:18 +0000 |
| commit | 5020a1a278114fba1992fb3dbf9d2d6ce8fdf3cb (patch) | |
| tree | 247a4d0e6e667c42ae0f6afe9bae979a670ffdda | |
| parent | 04bddedfd559cd2a09fe1c3eb41444fcb7c7aca4 (diff) | |
| download | org.eclipse.jubula.core-5020a1a278114fba1992fb3dbf9d2d6ce8fdf3cb.tar.gz org.eclipse.jubula.core-5020a1a278114fba1992fb3dbf9d2d6ce8fdf3cb.tar.xz org.eclipse.jubula.core-5020a1a278114fba1992fb3dbf9d2d6ce8fdf3cb.zip | |
Sprint task - fix for http://bugs.eclipse.org/414550 reviewed, changed and applied.
9 files changed, 87 insertions, 55 deletions
diff --git a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/tester/AbstractTreeTester.java b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/tester/AbstractTreeTester.java index 407ca0085..a5e331681 100644 --- a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/tester/AbstractTreeTester.java +++ b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/tester/AbstractTreeTester.java @@ -555,11 +555,6 @@ public abstract class AbstractTreeTester extends WidgetTester { AbstractTreeOperationContext context = getTreeAdapter().getContext(); Object selectedNode = getSelectedNode(context); - if (selectedNode == null) { - throw new StepExecutionException("No tree item selected", //$NON-NLS-1$ - EventFactory.createActionError(TestErrorEvent.NO_SELECTION)); - } - return context.getRenderedText(selectedNode); } diff --git a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/tester/ListTester.java b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/tester/ListTester.java index 576a23a23..d8b364386 100644 --- a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/tester/ListTester.java +++ b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/tester/ListTester.java @@ -20,6 +20,7 @@ import org.eclipse.jubula.rc.common.driver.ClickOptions; import org.eclipse.jubula.rc.common.driver.DragAndDropHelper; import org.eclipse.jubula.rc.common.exception.StepExecutionException; import org.eclipse.jubula.rc.common.tester.adapter.interfaces.IListComponent; +import org.eclipse.jubula.rc.common.util.SelectionUtil; import org.eclipse.jubula.rc.common.util.IndexConverter; import org.eclipse.jubula.rc.common.util.ListSelectionVerifier; import org.eclipse.jubula.rc.common.util.MatchUtil; @@ -58,10 +59,7 @@ public class ListTester extends AbstractTextVerifiableTester { */ private int[] getCheckedSelectedIndices() throws StepExecutionException { int[] selected = getListAdapter().getSelectedIndices(); - if (selected.length == 0) { - throw new StepExecutionException("No list element selected", //$NON-NLS-1$ - EventFactory.createActionError(TestErrorEvent.NO_SELECTION)); - } + SelectionUtil.validateSelection(selected); return selected; } @@ -131,10 +129,7 @@ public class ListTester extends AbstractTextVerifiableTester { public void rcVerifyText(String text, String operator) { String[] selected = getListAdapter().getSelectedValues(); final int selCount = selected.length; - if (selCount < 1) { - throw new StepExecutionException("No selection", //$NON-NLS-1$ - EventFactory.createActionError(TestErrorEvent.NO_SELECTION)); - } + SelectionUtil.validateSelection(selected); for (int i = 0; i < selCount; i++) { Verifier.match(selected[i], text, operator); } @@ -211,11 +206,7 @@ public class ListTester extends AbstractTextVerifiableTester { */ public String rcReadValue(String variable) { String[] selected = getListAdapter().getSelectedValues(); - if (selected.length > 0) { - return selected[0]; - } - throw new StepExecutionException("No list item selected", //$NON-NLS-1$ - EventFactory.createActionError(TestErrorEvent.NO_SELECTION)); + return (String) SelectionUtil.validateSelection(selected); } /** diff --git a/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/util/SelectionUtil.java b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/util/SelectionUtil.java new file mode 100644 index 000000000..0ba2963c4 --- /dev/null +++ b/org.eclipse.jubula.rc.common/src/org/eclipse/jubula/rc/common/util/SelectionUtil.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2013 BREDEX GmbH. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * BREDEX GmbH - initial API and implementation and/or initial documentation + *******************************************************************************/ +package org.eclipse.jubula.rc.common.util; + +import org.apache.commons.lang.ArrayUtils; +import org.eclipse.jubula.rc.common.exception.StepExecutionException; +import org.eclipse.jubula.tools.objects.event.EventFactory; +import org.eclipse.jubula.tools.objects.event.TestErrorEvent; + +/** + * Utility methods to check whether a given selection is valid or not. + * + * @author BREDEX GmbH + * @created Aug 06, 2013 + * + */ +public class SelectionUtil { + /** private constructor */ + private SelectionUtil() { + // do nothing + } + + /** + * Checks if there is any selection on the widget + * + * @param array + * an array of Objects to be validated + * @throws StepExecutionException + * thrown if no selection given + * @return The first selected Item + */ + public static Object validateSelection(Object[] array) + throws StepExecutionException { + if (ArrayUtils.isEmpty(array)) { + throw new StepExecutionException("No selection found", //$NON-NLS-1$ + EventFactory.createActionError( + TestErrorEvent.NO_SELECTION)); + } + return array[0]; + } + + /** + * Checks if there is any selection on the widget + * + * @param array + * an array of integers to be validated + * @throws StepExecutionException + * thrown if no selection given + * @return The first selected Item + */ + public static int validateSelection(int[] array) + throws StepExecutionException { + if (ArrayUtils.isEmpty(array)) { + throw new StepExecutionException("No selection found", //$NON-NLS-1$ + EventFactory.createActionError( + TestErrorEvent.NO_SELECTION)); + } + return array[0]; + } +} diff --git a/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/tester/adapter/JListAdapter.java b/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/tester/adapter/JListAdapter.java index 1932d76cf..486ee2ac6 100644 --- a/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/tester/adapter/JListAdapter.java +++ b/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/tester/adapter/JListAdapter.java @@ -21,6 +21,7 @@ import org.eclipse.jubula.rc.common.driver.ClickOptions; import org.eclipse.jubula.rc.common.driver.IRunnable; import org.eclipse.jubula.rc.common.exception.StepExecutionException; import org.eclipse.jubula.rc.common.tester.adapter.interfaces.IListComponent; +import org.eclipse.jubula.rc.common.util.SelectionUtil; import org.eclipse.jubula.rc.common.util.MatchUtil; import org.eclipse.jubula.rc.swing.tester.util.TesterUtil; import org.eclipse.jubula.tools.objects.event.EventFactory; @@ -48,11 +49,7 @@ public class JListAdapter extends JComponentAdapter implements IListComponent { */ public String getText() { String[] selected = getSelectedValues(); - if (selected.length > 0) { - return selected[0]; - } - throw new StepExecutionException("No list item selected", //$NON-NLS-1$ - EventFactory.createActionError(TestErrorEvent.NO_SELECTION)); + return (String) SelectionUtil.validateSelection(selected); } /** diff --git a/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/tester/adapter/JTableAdapter.java b/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/tester/adapter/JTableAdapter.java index 6989350e7..832e42984 100644 --- a/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/tester/adapter/JTableAdapter.java +++ b/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/tester/adapter/JTableAdapter.java @@ -266,7 +266,7 @@ public class JTableAdapter extends JComponentAdapter .Property .DESCRIPTION_KEY)))) { // set "invalid index" to "no selection" -> better description! - throw new StepExecutionException("No selection", //$NON-NLS-1$ + throw new StepExecutionException("No selection found", //$NON-NLS-1$ EventFactory.createActionError( TestErrorEvent.NO_SELECTION)); } diff --git a/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/tester/util/TreeOperationContext.java b/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/tester/util/TreeOperationContext.java index 203e30891..9717a73e4 100644 --- a/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/tester/util/TreeOperationContext.java +++ b/org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/tester/util/TreeOperationContext.java @@ -31,9 +31,8 @@ import org.eclipse.jubula.rc.common.driver.IRunnable; import org.eclipse.jubula.rc.common.exception.StepExecutionException; import org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext; import org.eclipse.jubula.rc.common.logger.AutServerLogger; +import org.eclipse.jubula.rc.common.util.SelectionUtil; import org.eclipse.jubula.rc.swing.driver.EventThreadQueuerAwtImpl; -import org.eclipse.jubula.tools.objects.event.EventFactory; -import org.eclipse.jubula.tools.objects.event.TestErrorEvent; /** @@ -512,10 +511,7 @@ public class TreeOperationContext extends AbstractTreeOperationContext { */ private TreePath[] getCheckedSelectedPaths() { TreePath[] paths = (TreePath[])getSelectionPaths(); - if (paths == null) { - throw new StepExecutionException("No tree node(s) selected", //$NON-NLS-1$ - EventFactory.createActionError(TestErrorEvent.NO_SELECTION)); - } + SelectionUtil.validateSelection(paths); return paths; } /** diff --git a/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/tester/TreeTester.java b/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/tester/TreeTester.java index cbdccc1bd..420ea5a00 100644 --- a/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/tester/TreeTester.java +++ b/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/tester/TreeTester.java @@ -32,6 +32,7 @@ import org.eclipse.jubula.rc.common.implclasses.tree.StandardDepthFirstTraverser import org.eclipse.jubula.rc.common.implclasses.tree.TreeNodeOperation; import org.eclipse.jubula.rc.common.implclasses.tree.TreeNodeOperationConstraint; import org.eclipse.jubula.rc.common.tester.AbstractTreeTester; +import org.eclipse.jubula.rc.common.tester.adapter.interfaces.ITreeComponent; import org.eclipse.jubula.rc.common.util.IndexConverter; import org.eclipse.jubula.rc.common.util.KeyStrokeUtil; import org.eclipse.jubula.rc.common.util.MatchUtil; @@ -785,8 +786,10 @@ public class TreeTester extends AbstractTreeTester { throws StepExecutionException { Boolean checkSelected = ((Boolean)getEventThreadQueuer().invokeAndWait( "rcVerifyTreeCheckbox", new IRunnable() { //$NON-NLS-1$ - public Object run() { - TreeItem node = getTree().getSelection()[0]; + public Object run() { + AbstractTreeOperationContext context = + ((ITreeComponent)getComponent()).getContext(); + TreeItem node = (TreeItem) getSelectedNode(context); return new Boolean(node.getChecked()); } })); diff --git a/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/tester/adapter/ListAdapter.java b/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/tester/adapter/ListAdapter.java index 7e94adaa7..3c59b77e5 100644 --- a/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/tester/adapter/ListAdapter.java +++ b/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/tester/adapter/ListAdapter.java @@ -14,9 +14,8 @@ import org.eclipse.jubula.rc.common.driver.ClickOptions; import org.eclipse.jubula.rc.common.driver.IRunnable; import org.eclipse.jubula.rc.common.exception.StepExecutionException; import org.eclipse.jubula.rc.common.tester.adapter.interfaces.IListComponent; +import org.eclipse.jubula.rc.common.util.SelectionUtil; import org.eclipse.jubula.rc.swt.utils.SwtUtils; -import org.eclipse.jubula.tools.objects.event.EventFactory; -import org.eclipse.jubula.tools.objects.event.TestErrorEvent; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.List; /** @@ -39,11 +38,7 @@ public class ListAdapter extends ControlAdapter implements IListComponent { */ public String getText() { String[] selected = getSelectedValues(); - if (selected.length > 0) { - return selected[0]; - } - throw new StepExecutionException("No list item selected", //$NON-NLS-1$ - EventFactory.createActionError(TestErrorEvent.NO_SELECTION)); + return (String) SelectionUtil.validateSelection(selected); } /** diff --git a/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/tester/tree/TreeOperationContext.java b/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/tester/tree/TreeOperationContext.java index b32df7b01..ce2142443 100644 --- a/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/tester/tree/TreeOperationContext.java +++ b/org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/tester/tree/TreeOperationContext.java @@ -21,13 +21,12 @@ import org.eclipse.jubula.rc.common.driver.IRunnable; import org.eclipse.jubula.rc.common.exception.StepExecutionException; import org.eclipse.jubula.rc.common.implclasses.tree.AbstractTreeOperationContext; import org.eclipse.jubula.rc.common.logger.AutServerLogger; +import org.eclipse.jubula.rc.common.util.SelectionUtil; import org.eclipse.jubula.rc.common.util.Verifier; import org.eclipse.jubula.rc.swt.tester.CAPUtil; import org.eclipse.jubula.rc.swt.utils.SwtPointUtil; import org.eclipse.jubula.rc.swt.utils.SwtUtils; import org.eclipse.jubula.tools.constants.SwtAUTHierarchyConstants; -import org.eclipse.jubula.tools.objects.event.EventFactory; -import org.eclipse.jubula.tools.objects.event.TestErrorEvent; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Event; @@ -454,13 +453,7 @@ public class TreeOperationContext extends AbstractTreeOperationContext { public Object run() { TreeItem [] selectedItems = ((Tree)getTree()).getSelection(); - if (selectedItems == null || selectedItems.length == 0) { - throw new StepExecutionException( - "No tree node(s) selected", //$NON-NLS-1$ - EventFactory.createActionError( - TestErrorEvent.NO_SELECTION)); - } - return selectedItems[0]; + return SelectionUtil.validateSelection(selectedItems); } }); @@ -476,13 +469,7 @@ public class TreeOperationContext extends AbstractTreeOperationContext { public Object run() { TreeItem [] selectedItems = ((Tree)getTree()).getSelection(); - if (selectedItems == null || selectedItems.length == 0) { - throw new StepExecutionException( - "No tree node(s) selected", //$NON-NLS-1$ - EventFactory.createActionError( - TestErrorEvent.NO_SELECTION)); - } - return selectedItems; + return SelectionUtil.validateSelection(selectedItems); } }); |
