Coverage Report - org.eclipse.swtbot.swt.finder.matchers.WithStyle
 
Classes in this File Line Coverage Branch Coverage Complexity
WithStyle
100%
8/8
N/A
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  
  *     Ketan Padegaonkar - http://swtbot.org/bugzilla/show_bug.cgi?id=126
 11  
  *******************************************************************************/
 12  
 package org.eclipse.swtbot.swt.finder.matchers;
 13  
 
 14  
 import org.eclipse.swt.widgets.Widget;
 15  
 import org.eclipse.swtbot.swt.finder.utils.SWTUtils;
 16  
 import org.hamcrest.Description;
 17  
 import org.hamcrest.Factory;
 18  
 import org.hamcrest.Matcher;
 19  
 
 20  
 /**
 21  
  * Matches if the widget has the specified style bits set.
 22  
  * 
 23  
  * @see Widget#getStyle()
 24  
  * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
 25  
  * @version $Id$
 26  
  * @since 2.0
 27  
  */
 28  
 public class WithStyle<T extends Widget> extends AbstractMatcher<T> {
 29  
 
 30  
         private final int                style;
 31  
         private final String        styleDescription;
 32  
 
 33  
         /**
 34  
          * Matches a widget that has the specified style bit set.
 35  
          * 
 36  
          * @param style the style bits.
 37  
          * @param styleDescription the description of the style bits.
 38  
          */
 39  721
         WithStyle(int style, String styleDescription) {
 40  721
                 this.style = style;
 41  721
                 this.styleDescription = styleDescription;
 42  721
         }
 43  
 
 44  
         protected boolean doMatch(Object obj) {
 45  1190
                 return SWTUtils.hasStyle((Widget) obj, style);
 46  
         }
 47  
 
 48  
         public void describeTo(Description description) {
 49  5430
                 description.appendText("with style '").appendText(styleDescription).appendText("'"); //$NON-NLS-1$ //$NON-NLS-2$
 50  5430
         }
 51  
 
 52  
         /**
 53  
          * Matches a widget that has the specified style bit set.
 54  
          * 
 55  
          * @param style the style bits.
 56  
          * @param styleDescription the description of the style bits.
 57  
          * @return a matcher.
 58  
          * @since 2.0
 59  
          */
 60  
         @Factory
 61  
         public static <T extends Widget> Matcher<T> withStyle(int style, String styleDescription) {
 62  721
                 return new WithStyle<T>(style, styleDescription);
 63  
         }
 64  
 
 65  
 }