Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
WithPerspectiveId |
|
| 1.4;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 WithPerspectiveId extends AbstractMatcher<IPerspectiveDescriptor> { | |
27 | ||
28 | private final Matcher<String> idMatcher; | |
29 | ||
30 | /** | |
31 | * @param idMatcher the perspective id matcher. | |
32 | */ | |
33 | 2 | WithPerspectiveId(Matcher<String> idMatcher) { |
34 | 2 | this.idMatcher = idMatcher; |
35 | 2 | } |
36 | ||
37 | @Override | |
38 | public boolean doMatch(Object item) { | |
39 | 18 | if (item instanceof IPerspectiveDescriptor) { |
40 | 18 | IPerspectiveDescriptor perspective = (IPerspectiveDescriptor) item; |
41 | 18 | return idMatcher.matches(perspective.getId()); |
42 | } | |
43 | 0 | return false; |
44 | } | |
45 | ||
46 | public void describeTo(Description description) { | |
47 | 0 | description.appendText("with id '").appendDescriptionOf(idMatcher).appendText("'"); |
48 | 0 | } |
49 | ||
50 | /** | |
51 | * Matches a perspective with the specified id. | |
52 | * | |
53 | * @param id the id of the perspective. | |
54 | * @return a matcher. | |
55 | * @since 2.0 | |
56 | */ | |
57 | @Factory | |
58 | public static WithPerspectiveId withPerspectiveId(String id) { | |
59 | 2 | return withPerspectiveId(equalTo(id)); |
60 | } | |
61 | ||
62 | /** | |
63 | * Matches a perspective with the specified id. | |
64 | * | |
65 | * @param idMatcher the matcher that matches the id of the perspective. | |
66 | * @return a matcher. | |
67 | * @since 2.0 | |
68 | */ | |
69 | @Factory | |
70 | public static WithPerspectiveId withPerspectiveId(Matcher<String> idMatcher) { | |
71 | 2 | return new WithPerspectiveId(idMatcher); |
72 | } | |
73 | } |