Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikaël Barbero2012-11-19 10:10:31 +0000
committerMikaël Barbero2012-11-19 10:10:55 +0000
commit584e82412999f39d86e04e6cf11b14629e8871a8 (patch)
treeea1703aaec73933748769d6ecde5990d4e6986e2 /plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command
parentd71dbeebc94f461f621994d7e7414de23f11b87d (diff)
downloadorg.eclipse.emf.compare-584e82412999f39d86e04e6cf11b14629e8871a8.tar.gz
org.eclipse.emf.compare-584e82412999f39d86e04e6cf11b14629e8871a8.tar.xz
org.eclipse.emf.compare-584e82412999f39d86e04e6cf11b14629e8871a8.zip
refactor EMFCompareEditingDomain to implement an interface.
refactor EMFCompareCommandStack to implement an interface. add 2 implementations of CompareCommandStack (delegating to one, and delegating to two other CommandStacks). refactor CopyAllNonConflictingCommand and CopyCommand to implement a common interface. add unittests on ICompareCommandStack implementations.
Diffstat (limited to 'plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command')
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/AbstractTestCompareCommandStack.java562
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/CommandStackTestSuite.java25
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/MockCompareCommand.java134
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/TestCompareCommandStack.java32
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/TestCompareSideCommandStack.java193
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/TestDualCompareCommandStack.java32
6 files changed, 978 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/AbstractTestCompareCommandStack.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/AbstractTestCompareCommandStack.java
new file mode 100644
index 000000000..7de3334f8
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/AbstractTestCompareCommandStack.java
@@ -0,0 +1,562 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.command;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.emf.compare.command.ICompareCommandStack;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public abstract class AbstractTestCompareCommandStack {
+
+ private ICompareCommandStack commandStack;
+
+ private MockCompareCommand leftToRight1;
+
+ private MockCompareCommand leftToRight2;
+
+ private MockCompareCommand leftToRight3;
+
+ private MockCompareCommand leftToRight4;
+
+ private MockCompareCommand rightToLeft1;
+
+ private MockCompareCommand rightToLeft2;
+
+ private MockCompareCommand rightToLeft3;
+
+ private MockCompareCommand rightToLeft4;
+
+ @Before
+ public void before() {
+ commandStack = createCommandStack();
+
+ leftToRight1 = new MockCompareCommand(true);
+ leftToRight2 = new MockCompareCommand(true);
+ leftToRight3 = new MockCompareCommand(true);
+ leftToRight4 = new MockCompareCommand(true);
+
+ rightToLeft1 = new MockCompareCommand(false);
+ rightToLeft2 = new MockCompareCommand(false);
+ rightToLeft3 = new MockCompareCommand(false);
+ rightToLeft4 = new MockCompareCommand(false);
+ }
+
+ /**
+ * @return the commandStack
+ */
+ protected abstract ICompareCommandStack createCommandStack();
+
+ @Test
+ public void testInitState() {
+ assertEquals(null, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(null, commandStack.getUndoCommand());
+ assertFalse(commandStack.canRedo());
+ assertFalse(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteLTROnce() {
+ commandStack.execute(leftToRight1);
+
+ assertEquals(leftToRight1, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(leftToRight1, commandStack.getUndoCommand());
+ assertFalse(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertTrue(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteLTROnceUndo() {
+ commandStack.execute(leftToRight1);
+ commandStack.undo();
+
+ assertEquals(leftToRight1, commandStack.getMostRecentCommand());
+ assertEquals(leftToRight1, commandStack.getRedoCommand());
+ assertEquals(null, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertFalse(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteLTROnceUndoRedo() {
+ commandStack.execute(leftToRight1);
+ commandStack.undo();
+ commandStack.redo();
+
+ assertEquals(leftToRight1, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(leftToRight1, commandStack.getUndoCommand());
+ assertFalse(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertTrue(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteLTRTwice() {
+ commandStack.execute(leftToRight2);
+ commandStack.execute(leftToRight1);
+
+ assertEquals(leftToRight1, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(leftToRight1, commandStack.getUndoCommand());
+ assertFalse(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertTrue(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteLTRTwiceUndo() {
+ commandStack.execute(leftToRight1);
+ commandStack.execute(leftToRight2);
+ commandStack.undo();
+
+ assertEquals(leftToRight2, commandStack.getMostRecentCommand());
+ assertEquals(leftToRight2, commandStack.getRedoCommand());
+ assertEquals(leftToRight1, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertTrue(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteLTRTwiceUndoTwice() {
+ commandStack.execute(leftToRight1);
+ commandStack.execute(leftToRight2);
+ commandStack.undo();
+ commandStack.undo();
+
+ assertEquals(leftToRight1, commandStack.getMostRecentCommand());
+ assertEquals(leftToRight1, commandStack.getRedoCommand());
+ assertEquals(null, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertFalse(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteLTRTwiceUndoTwiceRedo() {
+ commandStack.execute(leftToRight1);
+ commandStack.execute(leftToRight2);
+ commandStack.undo();
+ commandStack.undo();
+ commandStack.redo();
+
+ assertEquals(leftToRight1, commandStack.getMostRecentCommand());
+ assertEquals(leftToRight2, commandStack.getRedoCommand());
+ assertEquals(leftToRight1, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertTrue(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteLTRTwiceUndoTwiceRedoTwice() {
+ commandStack.execute(leftToRight1);
+ commandStack.execute(leftToRight2);
+ commandStack.undo();
+ commandStack.undo();
+ commandStack.redo();
+ commandStack.redo();
+
+ assertEquals(leftToRight2, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(leftToRight2, commandStack.getUndoCommand());
+ assertFalse(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertTrue(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteLTRTwiceUndoExecuteLTR() {
+ commandStack.execute(leftToRight1);
+ commandStack.execute(leftToRight2);
+ commandStack.undo();
+ commandStack.execute(leftToRight3);
+
+ assertEquals(leftToRight3, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(leftToRight3, commandStack.getUndoCommand());
+ assertFalse(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertTrue(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteLTRTwiceUndoExecuteLTRUndo() {
+ commandStack.execute(leftToRight1);
+ commandStack.execute(leftToRight2);
+ commandStack.undo();
+ commandStack.execute(leftToRight3);
+ commandStack.undo();
+
+ assertEquals(leftToRight3, commandStack.getMostRecentCommand());
+ assertEquals(leftToRight3, commandStack.getRedoCommand());
+ assertEquals(leftToRight1, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertTrue(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLOnce() {
+ commandStack.execute(rightToLeft1);
+
+ assertEquals(rightToLeft1, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(rightToLeft1, commandStack.getUndoCommand());
+ assertFalse(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertTrue(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLOnceUndo() {
+ commandStack.execute(rightToLeft1);
+ commandStack.undo();
+
+ assertEquals(rightToLeft1, commandStack.getMostRecentCommand());
+ assertEquals(rightToLeft1, commandStack.getRedoCommand());
+ assertEquals(null, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertFalse(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLOnceUndoRedo() {
+ commandStack.execute(rightToLeft1);
+ commandStack.undo();
+ commandStack.redo();
+
+ assertEquals(rightToLeft1, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(rightToLeft1, commandStack.getUndoCommand());
+ assertFalse(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertTrue(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLTwice() {
+ commandStack.execute(rightToLeft2);
+ commandStack.execute(rightToLeft1);
+
+ assertEquals(rightToLeft1, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(rightToLeft1, commandStack.getUndoCommand());
+ assertFalse(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertTrue(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLTwiceUndo() {
+ commandStack.execute(rightToLeft1);
+ commandStack.execute(rightToLeft2);
+ commandStack.undo();
+
+ assertEquals(rightToLeft2, commandStack.getMostRecentCommand());
+ assertEquals(rightToLeft2, commandStack.getRedoCommand());
+ assertEquals(rightToLeft1, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertTrue(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLTwiceUndoTwice() {
+ commandStack.execute(rightToLeft1);
+ commandStack.execute(rightToLeft2);
+ commandStack.undo();
+ commandStack.undo();
+
+ assertEquals(rightToLeft1, commandStack.getMostRecentCommand());
+ assertEquals(rightToLeft1, commandStack.getRedoCommand());
+ assertEquals(null, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertFalse(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLTwiceUndoTwiceRedo() {
+ commandStack.execute(rightToLeft1);
+ commandStack.execute(rightToLeft2);
+ commandStack.undo();
+ commandStack.undo();
+ commandStack.redo();
+
+ assertEquals(rightToLeft1, commandStack.getMostRecentCommand());
+ assertEquals(rightToLeft2, commandStack.getRedoCommand());
+ assertEquals(rightToLeft1, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertTrue(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLTwiceUndoTwiceRedoTwice() {
+ commandStack.execute(rightToLeft1);
+ commandStack.execute(rightToLeft2);
+ commandStack.undo();
+ commandStack.undo();
+ commandStack.redo();
+ commandStack.redo();
+
+ assertEquals(rightToLeft2, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(rightToLeft2, commandStack.getUndoCommand());
+ assertFalse(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertTrue(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLTwiceUndoExecuteRTL() {
+ commandStack.execute(rightToLeft1);
+ commandStack.execute(rightToLeft2);
+ commandStack.undo();
+ commandStack.execute(rightToLeft3);
+
+ assertEquals(rightToLeft3, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(rightToLeft3, commandStack.getUndoCommand());
+ assertFalse(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertTrue(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLTwiceUndoExecuteRTLUndo() {
+ commandStack.execute(rightToLeft1);
+ commandStack.execute(rightToLeft2);
+ commandStack.undo();
+ commandStack.execute(rightToLeft3);
+ commandStack.undo();
+
+ assertEquals(rightToLeft3, commandStack.getMostRecentCommand());
+ assertEquals(rightToLeft3, commandStack.getRedoCommand());
+ assertEquals(rightToLeft1, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertTrue(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteLTRExecuteRTL() {
+ commandStack.execute(leftToRight1);
+ commandStack.execute(rightToLeft1);
+
+ assertEquals(rightToLeft1, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(rightToLeft1, commandStack.getUndoCommand());
+ assertFalse(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertTrue(commandStack.isLeftSaveNeeded());
+ assertTrue(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteLTRExecuteRTLUndo() {
+ commandStack.execute(leftToRight1);
+ commandStack.execute(rightToLeft1);
+ commandStack.undo();
+
+ assertEquals(rightToLeft1, commandStack.getMostRecentCommand());
+ assertEquals(rightToLeft1, commandStack.getRedoCommand());
+ assertEquals(leftToRight1, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertTrue(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLExecuteLTRUndo() {
+ commandStack.execute(rightToLeft1);
+ commandStack.execute(leftToRight1);
+ commandStack.undo();
+
+ assertEquals(leftToRight1, commandStack.getMostRecentCommand());
+ assertEquals(leftToRight1, commandStack.getRedoCommand());
+ assertEquals(rightToLeft1, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertTrue(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLExecuteLTRUndoUndo() {
+ commandStack.execute(rightToLeft1);
+ commandStack.execute(leftToRight1);
+ commandStack.undo();
+ commandStack.undo();
+
+ assertEquals(rightToLeft1, commandStack.getMostRecentCommand());
+ assertEquals(rightToLeft1, commandStack.getRedoCommand());
+ assertEquals(null, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertFalse(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLExecuteLTRUndoRedo() {
+ commandStack.execute(rightToLeft1);
+ commandStack.execute(leftToRight1);
+ commandStack.undo();
+ commandStack.redo();
+
+ assertEquals(leftToRight1, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(leftToRight1, commandStack.getUndoCommand());
+ assertFalse(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertTrue(commandStack.isLeftSaveNeeded());
+ assertTrue(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLExecuteLTRUndoExecuteLTR() {
+ commandStack.execute(rightToLeft1);
+ commandStack.execute(leftToRight1);
+ commandStack.undo();
+ commandStack.execute(leftToRight2);
+
+ assertEquals(leftToRight2, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(leftToRight2, commandStack.getUndoCommand());
+ assertFalse(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertTrue(commandStack.isLeftSaveNeeded());
+ assertTrue(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLExecuteLTRUndoExecuteRTL() {
+ commandStack.execute(rightToLeft1);
+ commandStack.execute(leftToRight1);
+ commandStack.undo();
+ commandStack.execute(rightToLeft2);
+
+ assertEquals(rightToLeft2, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(rightToLeft2, commandStack.getUndoCommand());
+ assertFalse(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertTrue(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLExecuteLTRUndoExecuteRTLUndo() {
+ commandStack.execute(rightToLeft1);
+ commandStack.execute(leftToRight1);
+ commandStack.undo();
+ commandStack.execute(rightToLeft2);
+ commandStack.undo();
+
+ assertEquals(rightToLeft2, commandStack.getMostRecentCommand());
+ assertEquals(rightToLeft2, commandStack.getRedoCommand());
+ assertEquals(rightToLeft1, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertTrue(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLExecuteLTRUndoExecuteRTLUndoUndo() {
+ commandStack.execute(rightToLeft1);
+ commandStack.execute(leftToRight1);
+ commandStack.undo();
+ commandStack.execute(rightToLeft2);
+ commandStack.undo();
+ commandStack.undo();
+
+ assertEquals(rightToLeft1, commandStack.getMostRecentCommand());
+ assertEquals(rightToLeft1, commandStack.getRedoCommand());
+ assertEquals(null, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertFalse(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLExecuteLTRUndoExecuteLTRUndo() {
+ commandStack.execute(rightToLeft1);
+ commandStack.execute(leftToRight1);
+ commandStack.undo();
+ commandStack.execute(leftToRight2);
+ commandStack.undo();
+
+ assertEquals(leftToRight2, commandStack.getMostRecentCommand());
+ assertEquals(leftToRight2, commandStack.getRedoCommand());
+ assertEquals(rightToLeft1, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertTrue(commandStack.canUndo());
+ assertTrue(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+
+ @Test
+ public void testExecuteRTLExecuteLTRUndoExecuteLTRUndoUndo() {
+ commandStack.execute(rightToLeft1);
+ commandStack.execute(leftToRight1);
+ commandStack.undo();
+ commandStack.execute(leftToRight2);
+ commandStack.undo();
+ commandStack.undo();
+
+ assertEquals(rightToLeft1, commandStack.getMostRecentCommand());
+ assertEquals(rightToLeft1, commandStack.getRedoCommand());
+ assertEquals(null, commandStack.getUndoCommand());
+ assertTrue(commandStack.canRedo());
+ assertFalse(commandStack.canUndo());
+ assertFalse(commandStack.isLeftSaveNeeded());
+ assertFalse(commandStack.isRightSaveNeeded());
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/CommandStackTestSuite.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/CommandStackTestSuite.java
new file mode 100644
index 000000000..4aea29309
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/CommandStackTestSuite.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.command;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+@RunWith(Suite.class)
+@SuiteClasses(value = {TestCompareCommandStack.class, TestCompareSideCommandStack.class,
+ TestDualCompareCommandStack.class, })
+public class CommandStackTestSuite {
+
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/MockCompareCommand.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/MockCompareCommand.java
new file mode 100644
index 000000000..cafc0bc35
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/MockCompareCommand.java
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.command;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.compare.command.ICompareCopyCommand;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class MockCompareCommand implements ICompareCopyCommand {
+
+ private final boolean leftToRight;
+
+ public MockCompareCommand(boolean leftToRight) {
+ this.leftToRight = leftToRight;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.command.Command#canExecute()
+ */
+ public boolean canExecute() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.command.Command#execute()
+ */
+ public void execute() {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.command.Command#canUndo()
+ */
+ public boolean canUndo() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.command.Command#undo()
+ */
+ public void undo() {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.command.Command#redo()
+ */
+ public void redo() {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.command.Command#getResult()
+ */
+ public Collection<?> getResult() {
+ return new ArrayList<Object>();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.command.Command#getAffectedObjects()
+ */
+ public Collection<?> getAffectedObjects() {
+ return new ArrayList<Object>();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.command.Command#getLabel()
+ */
+ public String getLabel() {
+ return MockCompareCommand.class.getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.command.Command#getDescription()
+ */
+ public String getDescription() {
+ return MockCompareCommand.class.getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.command.Command#dispose()
+ */
+ public void dispose() {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.command.Command#chain(org.eclipse.emf.common.command.Command)
+ */
+ public Command chain(Command command) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.command.ICompareCopyCommand#isLeftToRight()
+ */
+ public boolean isLeftToRight() {
+ return leftToRight;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/TestCompareCommandStack.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/TestCompareCommandStack.java
new file mode 100644
index 000000000..cb41f68b4
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/TestCompareCommandStack.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.command;
+
+import org.eclipse.emf.common.command.BasicCommandStack;
+import org.eclipse.emf.compare.command.ICompareCommandStack;
+import org.eclipse.emf.compare.domain.impl.EMFCompareEditingDomain.CompareCommandStack;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class TestCompareCommandStack extends AbstractTestCompareCommandStack {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.tests.command.AbstractTestCompareCommandStack#createCommandStack()
+ */
+ @Override
+ protected ICompareCommandStack createCommandStack() {
+ return new CompareCommandStack(new BasicCommandStack());
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/TestCompareSideCommandStack.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/TestCompareSideCommandStack.java
new file mode 100644
index 000000000..95d23daa1
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/TestCompareSideCommandStack.java
@@ -0,0 +1,193 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.command;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.emf.compare.domain.impl.EMFCompareEditingDomain.CompareSideCommandStack;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class TestCompareSideCommandStack {
+
+ private MockCompareCommand leftToRight1;
+
+ private MockCompareCommand leftToRight2;
+
+ private CompareSideCommandStack commandStack;
+
+ private MockCompareCommand leftToRight3;
+
+ private MockCompareCommand leftToRight4;
+
+ @Before
+ public void before() {
+ commandStack = new CompareSideCommandStack();
+ leftToRight1 = new MockCompareCommand(true);
+ leftToRight2 = new MockCompareCommand(true);
+ leftToRight3 = new MockCompareCommand(true);
+ leftToRight4 = new MockCompareCommand(true);
+ }
+
+ @Test
+ public void testInitState() {
+ assertEquals(null, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(null, commandStack.getUndoCommand());
+ assertFalse(commandStack.isSaveNeeded());
+ }
+
+ @Test
+ public void testExecutedOnce() {
+ commandStack.executed(leftToRight1);
+
+ assertEquals(leftToRight1, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(leftToRight1, commandStack.getUndoCommand());
+ assertTrue(commandStack.isSaveNeeded());
+ }
+
+ @Test
+ public void testExecutedOnceUndo() {
+ commandStack.executed(leftToRight1);
+ commandStack.undone();
+
+ assertEquals(leftToRight1, commandStack.getMostRecentCommand());
+ assertEquals(leftToRight1, commandStack.getRedoCommand());
+ assertEquals(null, commandStack.getUndoCommand());
+ assertFalse(commandStack.isSaveNeeded());
+ }
+
+ @Test(expected = IndexOutOfBoundsException.class)
+ public void testExecutedOnceUndoTwice() {
+ commandStack.executed(leftToRight1);
+ commandStack.undone();
+ commandStack.undone();
+ }
+
+ @Test
+ public void testExecutedOnceUndoRedo() {
+ commandStack.executed(leftToRight1);
+ commandStack.undone();
+ commandStack.redone();
+
+ assertEquals(leftToRight1, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(leftToRight1, commandStack.getUndoCommand());
+ assertTrue(commandStack.isSaveNeeded());
+ }
+
+ @Test
+ public void testExecutedTwice() {
+ commandStack.executed(leftToRight2);
+ commandStack.executed(leftToRight1);
+
+ assertEquals(leftToRight1, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(leftToRight1, commandStack.getUndoCommand());
+ assertTrue(commandStack.isSaveNeeded());
+ }
+
+ @Test
+ public void testExecutedTwiceUndo() {
+ commandStack.executed(leftToRight1);
+ commandStack.executed(leftToRight2);
+ commandStack.undone();
+
+ assertEquals(leftToRight2, commandStack.getMostRecentCommand());
+ assertEquals(leftToRight2, commandStack.getRedoCommand());
+ assertEquals(leftToRight1, commandStack.getUndoCommand());
+ assertTrue(commandStack.isSaveNeeded());
+ }
+
+ @Test
+ public void testExecutedTwiceUndoTwice() {
+ commandStack.executed(leftToRight1);
+ commandStack.executed(leftToRight2);
+ commandStack.undone();
+ commandStack.undone();
+
+ assertEquals(leftToRight1, commandStack.getMostRecentCommand());
+ assertEquals(leftToRight1, commandStack.getRedoCommand());
+ assertEquals(null, commandStack.getUndoCommand());
+ assertFalse(commandStack.isSaveNeeded());
+ }
+
+ @Test
+ public void testExecutedTwiceUndoTwiceRedo() {
+ commandStack.executed(leftToRight1);
+ commandStack.executed(leftToRight2);
+ commandStack.undone();
+ commandStack.undone();
+ commandStack.redone();
+
+ assertEquals(leftToRight1, commandStack.getMostRecentCommand());
+ assertEquals(leftToRight2, commandStack.getRedoCommand());
+ assertEquals(leftToRight1, commandStack.getUndoCommand());
+ assertTrue(commandStack.isSaveNeeded());
+ }
+
+ @Test
+ public void testExecutedTwiceUndoTwiceRedoTwice() {
+ commandStack.executed(leftToRight1);
+ commandStack.executed(leftToRight2);
+ commandStack.undone();
+ commandStack.undone();
+ commandStack.redone();
+ commandStack.redone();
+
+ assertEquals(leftToRight2, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(leftToRight2, commandStack.getUndoCommand());
+ assertTrue(commandStack.isSaveNeeded());
+ }
+
+ @Test
+ public void testExecutedTwiceUndoExecuted() {
+ commandStack.executed(leftToRight1);
+ commandStack.executed(leftToRight2);
+ commandStack.undone();
+ commandStack.executed(leftToRight3);
+
+ assertEquals(leftToRight3, commandStack.getMostRecentCommand());
+ assertEquals(null, commandStack.getRedoCommand());
+ assertEquals(leftToRight3, commandStack.getUndoCommand());
+ assertTrue(commandStack.isSaveNeeded());
+ }
+
+ @Test(expected = IndexOutOfBoundsException.class)
+ public void testExecutedTwiceUndoExecutedRedo() {
+ commandStack.executed(leftToRight1);
+ commandStack.executed(leftToRight2);
+ commandStack.undone();
+ commandStack.executed(leftToRight3);
+ commandStack.redone();
+ }
+
+ @Test
+ public void testExecutedTwiceUndoExecutedUndo() {
+ commandStack.executed(leftToRight1);
+ commandStack.executed(leftToRight2);
+ commandStack.undone();
+ commandStack.executed(leftToRight3);
+ commandStack.undone();
+
+ assertEquals(leftToRight3, commandStack.getMostRecentCommand());
+ assertEquals(leftToRight3, commandStack.getRedoCommand());
+ assertEquals(leftToRight1, commandStack.getUndoCommand());
+ assertTrue(commandStack.isSaveNeeded());
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/TestDualCompareCommandStack.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/TestDualCompareCommandStack.java
new file mode 100644
index 000000000..5306d5199
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/command/TestDualCompareCommandStack.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.command;
+
+import org.eclipse.emf.common.command.BasicCommandStack;
+import org.eclipse.emf.compare.command.ICompareCommandStack;
+import org.eclipse.emf.compare.domain.impl.EMFCompareEditingDomain.DualCompareCommandStack;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class TestDualCompareCommandStack extends AbstractTestCompareCommandStack {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.tests.command.AbstractTestCompareCommandStack#createCommandStack()
+ */
+ @Override
+ protected ICompareCommandStack createCommandStack() {
+ return new DualCompareCommandStack(new BasicCommandStack(), new BasicCommandStack());
+ }
+
+}

Back to the top