blob: b78720e078a74146aa091f24bae1b61e6b1802a5 (
plain) (
blame)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/*
* Copyright (c) 2014 CEA and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christian W. Damus (CEA) - Initial API and implementation
*
*/
package org.eclipse.papyrus.junit.matchers;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.ui.palette.PaletteViewer;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
/**
* Hamcrest matchers for assertions on GMF diagrams.
*/
public class DiagramMatchers {
private DiagramMatchers() {
super();
}
/**
* Match an edit part that is selected in its viewer.
*/
public static Matcher<EditPart> editPartSelected() {
return EditPartSelected.INSTANCE;
}
/**
* Match a drawer that is expanded in the specified {@code viewer}.
*/
public static Matcher<PaletteDrawer> expandedIn(PaletteViewer viewer) {
return new DrawerExpansion(viewer, true);
}
/**
* Match a drawer that is collapsed (closed) in the specified {@code viewer}.
*/
public static Matcher<PaletteDrawer> collapsedIn(PaletteViewer viewer) {
return new DrawerExpansion(viewer, false);
}
//
// Nested types
//
static class EditPartSelected extends BaseMatcher<EditPart> {
private static final EditPartSelected INSTANCE = new EditPartSelected();
private EditPartSelected() {
super();
}
public void describeTo(Description description) {
description.appendText("edit-part is selected");
}
public boolean matches(Object item) {
return (item instanceof EditPart) && isSelected((EditPart)item);
}
boolean isSelected(EditPart editPart) {
EditPartViewer viewer = editPart.getViewer();
return (viewer != null) && viewer.getSelectedEditParts().contains(editPart);
}
}
static class DrawerExpansion extends BaseMatcher<PaletteDrawer> {
private final PaletteViewer viewer;
private final boolean expanded;
DrawerExpansion(PaletteViewer viewer, boolean expanded) {
this.viewer = viewer;
this.expanded = expanded;
}
public void describeTo(Description description) {
description.appendText("drawer is ");
description.appendText(expanded ? "expanded" : "collapsed");
}
public boolean matches(Object item) {
return (item instanceof PaletteDrawer) && (isExpanded((PaletteDrawer)item) == expanded);
}
boolean isExpanded(PaletteDrawer drawer) {
return viewer.isExpanded(drawer);
}
}
}
|