Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2018-04-25 12:23:11 +0000
committerNicolas FAUVERGUE2018-05-14 15:15:01 +0000
commit6ba0f3d2f43bae21f387ac58ec5a357767620115 (patch)
tree244ae9092ce8d87e647292a5bcd619cd712d03ed /tests/junit/framework/org.eclipse.papyrus.junit.utils
parent044dc1170629e1657f39305fdaf900abca5a7aa1 (diff)
downloadorg.eclipse.papyrus-6ba0f3d2f43bae21f387ac58ec5a357767620115.tar.gz
org.eclipse.papyrus-6ba0f3d2f43bae21f387ac58ec5a357767620115.tar.xz
org.eclipse.papyrus-6ba0f3d2f43bae21f387ac58ec5a357767620115.zip
Bug 533672: [Sequence Diagram] InteractionOperand should be created on Lifeline and Interaction
Ensure that the Interaction Operand tool is responsive on lifelines where they are covered by combined fragments. Change-Id: Idd29228845e4ac3cd3aa84cbe4d8c4ccd12cf3ce Signed-off-by: Christian W. Damus <give.a.damus@gmail.com>
Diffstat (limited to 'tests/junit/framework/org.eclipse.papyrus.junit.utils')
-rw-r--r--tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/CommandMatchers.java103
-rw-r--r--tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/MoreMatchers.java104
-rw-r--r--tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java9
3 files changed, 195 insertions, 21 deletions
diff --git a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/CommandMatchers.java b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/CommandMatchers.java
new file mode 100644
index 00000000000..3cd355c83b3
--- /dev/null
+++ b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/CommandMatchers.java
@@ -0,0 +1,103 @@
+/*****************************************************************************
+ * Copyright (c) 2018 Christian W. Damus 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 - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.junit.matchers;
+
+import java.util.function.Predicate;
+
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+
+/**
+ * Matchers for commands of various flavours, which are defined in nested classes.
+ *
+ * @since 2.2
+ */
+public final class CommandMatchers {
+
+ /**
+ * Not instantiable by clients.
+ */
+ private CommandMatchers() {
+ super();
+ }
+
+ static <C> Matcher<C> executable(Predicate<? super C> canExecute) {
+ return new TypeSafeMatcher<C>() {
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("unexecutable");
+ }
+
+ @Override
+ protected boolean matchesSafely(C item) {
+ return canExecute.test(item);
+ }
+ };
+ }
+
+ /**
+ * Matchers for GMF commands.
+ *
+ * @since 2.2
+ */
+ public static final class GMF {
+ /**
+ * Not instantiable by clients.
+ */
+ private GMF() {
+ super();
+ }
+
+ public static Matcher<org.eclipse.gmf.runtime.common.core.command.ICommand> canExecute() {
+ return executable(org.eclipse.gmf.runtime.common.core.command.ICommand::canExecute);
+ }
+ }
+
+ /**
+ * Matchers for EMF commands.
+ *
+ * @since 2.2
+ */
+ public static class EMF {
+ /**
+ * Not instantiable by clients.
+ */
+ private EMF() {
+ super();
+ }
+
+ public static Matcher<org.eclipse.emf.common.command.Command> canExecute() {
+ return executable(org.eclipse.emf.common.command.Command::canExecute);
+ }
+ }
+
+ /**
+ * Matchers for GEF commands.
+ *
+ * @since 2.2
+ */
+ public static final class GEF {
+ /**
+ * Not instantiable by clients.
+ */
+ private GEF() {
+ super();
+ }
+
+ public static Matcher<org.eclipse.gef.commands.Command> canExecute() {
+ return executable(org.eclipse.gef.commands.Command::canExecute);
+ }
+ }
+}
diff --git a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/MoreMatchers.java b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/MoreMatchers.java
index 9765f99db05..9dccc7de618 100644
--- a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/MoreMatchers.java
+++ b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/MoreMatchers.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014, 2015 Christian W. Damus and others.
+ * Copyright (c) 2014, 2018 Christian W. Damus and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -19,6 +19,7 @@ import org.eclipse.core.runtime.IStatus;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
import org.hamcrest.core.CombinableMatcher;
import com.google.common.base.Strings;
@@ -33,32 +34,99 @@ public class MoreMatchers {
super();
}
+ /**
+ * Obtain a matcher for numbers greater than a {@code minimum}.
+ *
+ * @param minimum
+ * the lower bound (exclusive) to match against
+ * @return the matcher
+ */
public static <N extends Number & Comparable<N>> Matcher<N> greaterThan(final N minimum) {
- return new BaseMatcher<N>() {
- @Override
- public void describeTo(Description description) {
- description.appendText("greater than ").appendValue(minimum);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public boolean matches(Object item) {
- return ((N) item).compareTo(minimum) > 0;
- }
- };
+ return comparesAs(minimum, +1, false);
}
+ /**
+ * Obtain a matcher for numbers less than a {@code maximum}.
+ *
+ * @param maximum
+ * the upper bound (exclusive) to match against
+ * @return the matcher
+ */
public static <N extends Number & Comparable<N>> Matcher<N> lessThan(final N maximum) {
- return new BaseMatcher<N>() {
+ return comparesAs(maximum, -1, false);
+ }
+
+ /**
+ * Obtain a matcher for numbers greater or equal to a {@code minimum}.
+ *
+ * @param minimum
+ * the lower bound (inclusive) to match against
+ * @return the matcher
+ * @since 2.2
+ */
+ public static <N extends Number & Comparable<N>> Matcher<N> greaterThanOrEqual(final N minimum) {
+ return comparesAs(minimum, +1, true);
+ }
+
+ /**
+ * Obtain a matcher for numbers less or equal to a {@code maximum}.
+ *
+ * @param maximum
+ * the upper bound (inclusive) to match against
+ * @return the matcher
+ * @since 2.2
+ */
+ public static <N extends Number & Comparable<N>> Matcher<N> lessThanOrEqual(final N maximum) {
+ return comparesAs(maximum, -1, true);
+ }
+
+ /**
+ * Obtain a matcher for comparables that matches comparisons yielding the given
+ * {@code sign}.
+ *
+ * @param compareTo
+ * the value to compare with
+ * @param sign
+ * the sign of the comparison result, either negative for less
+ * than {@code compareTo}, positive for greater than {@code compareTo},
+ * or zero for equal to {@code compareTo}
+ * @param orEqual
+ * in the case of non-zero {@code sign}, whether to match equality also
+ *
+ * @return the matcher
+ *
+ * @since 2.2
+ */
+ public static <C extends Comparable<C>> Matcher<C> comparesAs(final C compareTo, final int sign, final boolean orEqual) {
+ final int normalizedSign = Integer.signum(sign);
+ return new TypeSafeMatcher<C>() {
@Override
public void describeTo(Description description) {
- description.appendText("less than ").appendValue(maximum);
+ switch (normalizedSign) {
+ case -1:
+ description.appendText(orEqual ? "≤ " : "< ");
+ break;
+ case +1:
+ description.appendText(orEqual ? "≥ " : "> ");
+ break;
+ default:
+ description.appendText("= ");
+ break;
+ }
+ description.appendValue(compareTo);
}
@Override
- @SuppressWarnings("unchecked")
- public boolean matches(Object item) {
- return ((N) item).compareTo(maximum) < 0;
+ protected boolean matchesSafely(C item) {
+ int comparison = item.compareTo(compareTo);
+ switch (normalizedSign) {
+ case -1:
+ return orEqual ? comparison <= 0 : comparison < 0;
+ case +1:
+ return orEqual ? comparison >= 0 : comparison > 0;
+ default:
+ return comparison == 0;
+ }
}
};
}
diff --git a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
index 759cf747fb5..8753f5f3de8 100644
--- a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
+++ b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
@@ -14,7 +14,6 @@
package org.eclipse.papyrus.junit.utils.rules;
import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;
@@ -101,6 +100,7 @@ import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
import org.eclipse.papyrus.infra.tools.util.PlatformHelper;
import org.eclipse.papyrus.infra.tools.util.TypeUtils;
import org.eclipse.papyrus.infra.ui.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.junit.matchers.CommandMatchers;
import org.eclipse.papyrus.junit.utils.EditorUtils;
import org.eclipse.papyrus.junit.utils.JUnitUtils;
import org.eclipse.papyrus.junit.utils.tests.AbstractEditorTest;
@@ -1163,7 +1163,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
public void execute(org.eclipse.gef.commands.Command command) {
assertThat("No command", command, notNullValue());
- assertThat("Command not executable", command.canExecute(), is(true));
+ assertThat(command, CommandMatchers.GEF.canExecute());
getActiveDiagramEditor().getDiagramEditDomain().getDiagramCommandStack().execute(command);
flushDisplayEvents();
}
@@ -1493,7 +1493,10 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
request.setLocation(location);
request.setSize(size);
- org.eclipse.gef.commands.Command command = parent.getCommand(request);
+
+ EditPart target = parent.getTargetEditPart(request);
+ assertThat("No target edit part", target, notNullValue());
+ org.eclipse.gef.commands.Command command = target.getCommand(request);
execute(command);
// Find the new edit-part

Back to the top