Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
7   79   5   1.75
2   29   0.71   4
4     1.25  
1    
 
  TypeMatcher       Line # 30 7 0% 5 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Jun 18, 2007
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10    * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11    * or implied. See the License for the specific language governing permissions and limitations under
12    * the License.
13    *
14    * Copyright @2007-2010 the original author or authors.
15    */
16    package org.fest.swing.core;
17   
18    import static java.lang.String.valueOf;
19    import static org.fest.util.Strings.concat;
20   
21    import java.awt.Component;
22   
23    import org.fest.swing.annotation.RunsInCurrentThread;
24   
25    /**
26    * Understands <code>{@link java.awt.Component}</code> matching by type.
27    *
28    * @author Alex Ruiz
29    */
 
30    public final class TypeMatcher extends AbstractComponentMatcher {
31   
32    private final Class<? extends Component> type;
33   
34    /**
35    * Creates a new <code>{@link TypeMatcher}</code>. The component to match does not have to be showing.
36    * @param type the type of the component we are looking for.
37    * @throws NullPointerException if the given type is <code>null</code>.
38    */
 
39  127 toggle public TypeMatcher(Class<? extends Component> type) {
40  127 this(type, false);
41    }
42   
43    /**
44    * Creates a new <code>{@link TypeMatcher}</code>.
45    * @param type the type of the component we are looking for.
46    * @param requireShowing indicates if the component to match should be showing or not.
47    * @throws NullPointerException if the given type is <code>null</code>.
48    */
 
49  1443 toggle public TypeMatcher(Class<? extends Component> type, boolean requireShowing) {
50  1443 super(requireShowing);
51  1443 if (type == null)
52  3 throw new NullPointerException("The type of component to find should not be null");
53  1440 this.type = type;
54    }
55   
56    /**
57    * Indicates whether the type and visibility of the given <code>{@link java.awt.Component}</code> matches the value
58    * specified in this matcher.
59    * <p>
60    * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
61    * responsible for calling this method from the EDT.
62    * </p>
63    * @return <code>true</code> if the type and visibility of the given <code>Component</code> matches the values
64    * specified in this matcher, <code>false</code> otherwise.
65    */
 
66  30237 toggle @RunsInCurrentThread
67    public boolean matches(Component c) {
68  30237 return type.isAssignableFrom(c.getClass()) && requireShowingMatches(c);
69    }
70   
 
71  4166 toggle @Override public String toString() {
72  4166 return concat(
73    getClass().getName(), "[",
74    "type=", type.getName(), ", ",
75    "requireShowing=", valueOf(requireShowing()),
76    "]"
77    );
78    }
79    }