Coverage Report - org.eclipse.swtbot.eclipse.finder.matchers.WithPerspectiveLabel
 
Classes in this File Line Coverage Branch Coverage Complexity
WithPerspectiveLabel
0%
0/11
0%
0/2
1.4
 
 1  
 /*******************************************************************************
 2  
  * Copyright (c) 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  
  *     Ralf Ebert www.ralfebert.de - (bug 271630) SWTBot Improved RCP / Workbench support
 10  
  *******************************************************************************/
 11  
 package org.eclipse.swtbot.eclipse.finder.matchers;
 12  
 
 13  
 import static org.hamcrest.Matchers.equalTo;
 14  
 
 15  
 import org.eclipse.swtbot.swt.finder.matchers.AbstractMatcher;
 16  
 import org.eclipse.ui.IPerspectiveDescriptor;
 17  
 import org.hamcrest.Description;
 18  
 import org.hamcrest.Factory;
 19  
 import org.hamcrest.Matcher;
 20  
 
 21  
 /**
 22  
  * @author Ralf Ebert www.ralfebert.de (bug 271630)
 23  
  * @version $Id$
 24  
  * @since 2.0
 25  
  */
 26  
 public class WithPerspectiveLabel extends AbstractMatcher<IPerspectiveDescriptor> {
 27  
 
 28  
         private final Matcher<String>        labelMatcher;
 29  
 
 30  
         /**
 31  
          * @param labelMatcher the perspective label matcher.
 32  
          */
 33  0
         WithPerspectiveLabel(Matcher<String> labelMatcher) {
 34  0
                 this.labelMatcher = labelMatcher;
 35  0
         }
 36  
 
 37  
         @Override
 38  
         public boolean doMatch(Object item) {
 39  0
                 if (item instanceof IPerspectiveDescriptor) {
 40  0
                         IPerspectiveDescriptor perspective = (IPerspectiveDescriptor) item;
 41  0
                         return labelMatcher.matches(perspective.getLabel());
 42  
                 }
 43  0
                 return false;
 44  
         }
 45  
 
 46  
         public void describeTo(Description description) {
 47  0
                 description.appendText("with label '").appendDescriptionOf(labelMatcher).appendText("'");
 48  0
         }
 49  
 
 50  
         /**
 51  
          * Matches a perspective with the specified label.
 52  
          * 
 53  
          * @param label the label of the perspective.
 54  
          * @return a matcher.
 55  
          * @since 2.0
 56  
          */
 57  
         @Factory
 58  
         public static WithPerspectiveLabel withPerspectiveLabel(String label) {
 59  0
                 return withPerspectiveLabel(equalTo(label));
 60  
         }
 61  
 
 62  
         /**
 63  
          * Matches a perspective with the specified label.
 64  
          * 
 65  
          * @param labelMatcher the matcher that matches the perspective label.
 66  
          * @return a matcher.
 67  
          * @since 2.0
 68  
          */
 69  
         @Factory
 70  
         public static WithPerspectiveLabel withPerspectiveLabel(Matcher<String> labelMatcher) {
 71  0
                 return new WithPerspectiveLabel(labelMatcher);
 72  
         }
 73  
 }