/
ClassMatcher.java
70 lines (63 loc) · 2.14 KB
/
ClassMatcher.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*******************************************************************************
* Copyright (c) 2017 Red Hat, Inc and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc - initial API and implementation
*******************************************************************************/
package org.eclipse.reddeer.core.matcher;
import org.eclipse.swt.widgets.Widget;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
/**
* Matcher matching {@link Widget} widget classes.
* Matching is satisfied if class specified in constructor is same or is superclass of class of object specified
* as argument a in method {@link ClassMatcher#matches(Object)}.
*
* @author jpeterka
* @author rawagner
* @author Radoslav Rabara
*
*/
@SuppressWarnings("rawtypes")
public class ClassMatcher extends BaseMatcher {
private Class<? extends Widget> c;
/**
* Constructs new ClassMatcher matcher matching {@link Widget} objects.
* For satisfied match it is required the class specified in constructor
* is either same class as class of object in matches method or it is superclass
* of object provided in matches method.
*
* @param c descendant of widget class to be used as a base for matching
*/
public ClassMatcher(Class<? extends Widget> c) {
if(c==null)
throw new NullPointerException("c is null");
this.c = c;
}
/* (non-Javadoc)
* @see org.hamcrest.Matcher#matches(java.lang.Object)
*/
@Override
public boolean matches(Object item) {
return c.isAssignableFrom(item.getClass());
}
/* (non-Javadoc)
* @see org.hamcrest.SelfDescribing#describeTo(org.hamcrest.Description)
*/
@Override
public void describeTo(Description description) {
description.appendText("has the same type as " + c +" or its type extends " + c);
}
/* (non-Javadoc)
* @see org.hamcrest.BaseMatcher#toString()
*/
@Override
public String toString() {
return "Matcher matching widget with the same type as or type extending " + c;
}
}