Coverage Report - org.eclipse.swtbot.swt.finder.waits.WaitForObjectCondition
 
Classes in this File Line Coverage Branch Coverage Complexity
WaitForObjectCondition
100%
9/9
100%
2/2
1
 
 1  
 /*******************************************************************************
 2  
  * Copyright (c) 2008-2009 SWTBot Committers 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 java.util.ArrayList;
 14  
 import java.util.List;
 15  
 
 16  
 import org.hamcrest.Matcher;
 17  
 
 18  
 /**
 19  
  * Waits for objects to appear until the matcher evaluates to true.
 20  
  *
 21  
  * @see Conditions
 22  
  * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
 23  
  * @version $Id$
 24  
  */
 25  
 public abstract class WaitForObjectCondition<T> extends DefaultCondition {
 26  
 
 27  
         /** The matcher that is used to match widgets. */
 28  
         protected final Matcher<T>        matcher;
 29  
         private final List<T>                matches;
 30  
 
 31  
         /**
 32  
          * Waits until the matcher is true.
 33  
          *
 34  
          * @param matcher the matcher.
 35  
          */
 36  1317
         public WaitForObjectCondition(Matcher<T> matcher) {
 37  1317
                 this.matcher = matcher;
 38  1317
                 matches = new ArrayList<T>();
 39  1317
         }
 40  
 
 41  
         public boolean test() throws Exception {
 42  1397
                 matches.clear();
 43  1397
                 matches.addAll(findMatches());
 44  1397
                 return !matches.isEmpty();
 45  
         }
 46  
 
 47  
         /**
 48  
          * @return the matches that subclasses that matched.
 49  
          */
 50  
         protected abstract List<T> findMatches();
 51  
 
 52  
         /**
 53  
          * @return all objects that matched the matcher.
 54  
          */
 55  
         public List<T> getAllMatches() {
 56  33
                 return this.matches;
 57  
         }
 58  
 
 59  
         /**
 60  
          * @param index the index of the object.
 61  
          * @return the element at the specified index in the list of matched objects.
 62  
          */
 63  
         public T get(int index) {
 64  1258
                 return this.matches.get(index);
 65  
         }
 66  
 }