Coverage Report - org.eclipse.swtbot.swt.finder.waits.TableHasRows
 
Classes in this File Line Coverage Branch Coverage Complexity
TableHasRows
87%
7/8
75%
3/4
1
 
 1  
 /*******************************************************************************
 2  
  * Copyright (c) 2008 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  
  *     Ketan Padegaonkar - 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.widgets.SWTBotTable;
 15  
 
 16  
 /**
 17  
  * A condition that returns <code>false</code> until the table has the specified number of rows.
 18  
  *
 19  
  * @see Conditions
 20  
  * @author Ketan Padegaonkar &lt;KetanPadegaonkar [at] gmail [dot] com&gt;
 21  
  * @version $Id$
 22  
  */
 23  
 class TableHasRows 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 SWTBotTable        table;
 33  
 
 34  
         /**
 35  
          * Constructs an instance of the condition for the given table. The row count is used to know how many rows it needs
 36  
          * to satisfy the condition.
 37  
          *
 38  
          * @param table the table
 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
         TableHasRows(SWTBotTable table, int rowCount) {
 44  2
                 Assert.isNotNull(table, "The table can not be null"); //$NON-NLS-1$
 45  2
                 Assert.isLegal(rowCount >= 0, "The row count must be greater then zero (0)"); //$NON-NLS-1$
 46  2
                 this.table = table;
 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 row count equals the number of rows in the table. Otherwise
 55  
          *         <code>false</code> is returned.
 56  
          */
 57  
         public boolean test() {
 58  2
                 return table.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 " + table + " to contain " + rowCount + " rows."; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 69  
         }
 70  
 }