| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| TreeHasRows |
|
| 1.0;1 |
| 1 | /******************************************************************************* | |
| 2 | * Copyright (c) 2010 Ketan Padegaonkar and others. | |
| 3 | * All rights reserved. This program and the accompanying materials | |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | |
| 5 | * which accompanies this distribution, and is available at | |
| 6 | * http://www.eclipse.org/legal/epl-v10.html | |
| 7 | * | |
| 8 | * Contributors: | |
| 9 | * Jesper S Møller - initial API and implementation | |
| 10 | *******************************************************************************/ | |
| 11 | package org.eclipse.swtbot.swt.finder.waits; | |
| 12 | ||
| 13 | import org.eclipse.swtbot.swt.finder.utils.internal.Assert; | |
| 14 | import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; | |
| 15 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; | |
| 16 | ||
| 17 | /** | |
| 18 | * A condition that returns <code>false</code> until the table has the specified number of rows. | |
| 19 | * | |
| 20 | * @see Conditions | |
| 21 | * @author Jesper Steen Moeller <jesper [at] selskabet [dot] org> | |
| 22 | */ | |
| 23 | class TreeHasRows extends DefaultCondition { | |
| 24 | ||
| 25 | /** | |
| 26 | * The row count. | |
| 27 | */ | |
| 28 | private final int rowCount; | |
| 29 | /** | |
| 30 | * The table (SWTBotTable) instance to check. | |
| 31 | */ | |
| 32 | private final SWTBotTree tree; | |
| 33 | ||
| 34 | /** | |
| 35 | * Constructs an instance of the condition for the given tree. The row count is used to know how many rows it needs | |
| 36 | * to satisfy the condition. | |
| 37 | * | |
| 38 | * @param tree the tree | |
| 39 | * @param rowCount the number of rows needed. | |
| 40 | * @throws NullPointerException Thrown if the table is <code>null</code>. | |
| 41 | * @throws IllegalArgumentException Thrown if the row count is less then 1. | |
| 42 | */ | |
| 43 | 2 | TreeHasRows(SWTBotTree tree, int rowCount) { |
| 44 | 2 | Assert.isNotNull(tree, "The tree can not be null"); //$NON-NLS-1$ |
| 45 | 2 | Assert.isLegal(rowCount >= 0, "The node count must be greater than zero (0)"); //$NON-NLS-1$ |
| 46 | 2 | this.tree = tree; |
| 47 | 2 | this.rowCount = rowCount; |
| 48 | 2 | } |
| 49 | ||
| 50 | /** | |
| 51 | * Performs the check to see if the condition is satisfied. | |
| 52 | * | |
| 53 | * @see org.eclipse.swtbot.swt.finder.waits.ICondition#test() | |
| 54 | * @return <code>true</code> if the condition node count equals the number of nodes in the tree. Otherwise | |
| 55 | * <code>false</code> is returned. | |
| 56 | */ | |
| 57 | public boolean test() { | |
| 58 | 2 | return tree.rowCount() == rowCount; |
| 59 | } | |
| 60 | ||
| 61 | /** | |
| 62 | * Gets the failure message if the test is not satisfied. | |
| 63 | * | |
| 64 | * @see org.eclipse.swtbot.swt.finder.waits.ICondition#getFailureMessage() | |
| 65 | * @return The failure message. | |
| 66 | */ | |
| 67 | public String getFailureMessage() { | |
| 68 | 0 | return "Timed out waiting for " + tree + " to contain " + rowCount + " rows."; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 69 | } | |
| 70 | } |