Skip to content

Commit

Permalink
Cleaned GEF Tests (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
azoitl committed Nov 13, 2023
1 parent 01deb9b commit 764ad84
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 118 deletions.
162 changes: 79 additions & 83 deletions org.eclipse.gef.tests/src/org/eclipse/gef/test/CommandStackTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,20 @@
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.commands.CommandStackEvent;
import org.eclipse.gef.commands.CommandStackEventListener;

import org.junit.Assert;
import org.junit.Test;

public class CommandStackTest extends Assert {

@SuppressWarnings("static-method")
@Test
public void testCommandStackEventListenerNotifications() {
final List commandStackEvents = new ArrayList();
final List<CommandStackEvent> commandStackEvents = new ArrayList<>();

// capture all notifications in an event list
CommandStack stack = new CommandStack();
stack.addCommandStackEventListener(new CommandStackEventListener() {
@Override
public void stackChanged(CommandStackEvent event) {
commandStackEvents.add(event);
}
});
stack.addCommandStackEventListener(event -> commandStackEvents.add(event));

Command c = new Command() {
};
Expand All @@ -33,87 +29,87 @@ public void stackChanged(CommandStackEvent event) {
stack.execute(c);

Assert.assertEquals(2, commandStackEvents.size());
Assert.assertEquals(c, ((CommandStackEvent) commandStackEvents.get(0)).getCommand());
Assert.assertTrue(((CommandStackEvent) commandStackEvents.get(0)).isPreChangeEvent());
Assert.assertFalse(((CommandStackEvent) commandStackEvents.get(0)).isPostChangeEvent());
Assert.assertEquals(stack, ((CommandStackEvent) commandStackEvents.get(0)).getSource());
Assert.assertEquals(CommandStack.PRE_EXECUTE, ((CommandStackEvent) commandStackEvents.get(0)).getDetail());
Assert.assertNotEquals(0, ((CommandStackEvent) commandStackEvents.get(0)).getDetail() & CommandStack.PRE_MASK);
Assert.assertEquals(0, ((CommandStackEvent) commandStackEvents.get(0)).getDetail() & CommandStack.POST_MASK);

Assert.assertEquals(c, ((CommandStackEvent) commandStackEvents.get(1)).getCommand());
Assert.assertFalse(((CommandStackEvent) commandStackEvents.get(1)).isPreChangeEvent());
Assert.assertTrue(((CommandStackEvent) commandStackEvents.get(1)).isPostChangeEvent());
Assert.assertEquals(stack, ((CommandStackEvent) commandStackEvents.get(1)).getSource());
Assert.assertEquals(CommandStack.POST_EXECUTE, ((CommandStackEvent) commandStackEvents.get(1)).getDetail());
Assert.assertEquals(0, ((CommandStackEvent) commandStackEvents.get(1)).getDetail() & CommandStack.PRE_MASK);
Assert.assertNotEquals(0, ((CommandStackEvent) commandStackEvents.get(1)).getDetail() & CommandStack.POST_MASK);
Assert.assertEquals(c, commandStackEvents.get(0).getCommand());
Assert.assertTrue(commandStackEvents.get(0).isPreChangeEvent());
Assert.assertFalse(commandStackEvents.get(0).isPostChangeEvent());
Assert.assertEquals(stack, commandStackEvents.get(0).getSource());
Assert.assertEquals(CommandStack.PRE_EXECUTE, commandStackEvents.get(0).getDetail());
Assert.assertNotEquals(0, commandStackEvents.get(0).getDetail() & CommandStack.PRE_MASK);
Assert.assertEquals(0, commandStackEvents.get(0).getDetail() & CommandStack.POST_MASK);

Assert.assertEquals(c, commandStackEvents.get(1).getCommand());
Assert.assertFalse(commandStackEvents.get(1).isPreChangeEvent());
Assert.assertTrue(commandStackEvents.get(1).isPostChangeEvent());
Assert.assertEquals(stack, commandStackEvents.get(1).getSource());
Assert.assertEquals(CommandStack.POST_EXECUTE, commandStackEvents.get(1).getDetail());
Assert.assertEquals(0, commandStackEvents.get(1).getDetail() & CommandStack.PRE_MASK);
Assert.assertNotEquals(0, commandStackEvents.get(1).getDetail() & CommandStack.POST_MASK);

// // test undo pre and post events
commandStackEvents.clear();
Assert.assertEquals(0, commandStackEvents.size());
stack.undo();

Assert.assertEquals(2, commandStackEvents.size());
Assert.assertEquals(c, ((CommandStackEvent) commandStackEvents.get(0)).getCommand());
Assert.assertTrue(((CommandStackEvent) commandStackEvents.get(0)).isPreChangeEvent());
Assert.assertFalse(((CommandStackEvent) commandStackEvents.get(0)).isPostChangeEvent());
Assert.assertEquals(stack, ((CommandStackEvent) commandStackEvents.get(0)).getSource());
Assert.assertEquals(CommandStack.PRE_UNDO, ((CommandStackEvent) commandStackEvents.get(0)).getDetail());
Assert.assertNotEquals(0, ((CommandStackEvent) commandStackEvents.get(0)).getDetail() & CommandStack.PRE_MASK);
Assert.assertEquals(0, ((CommandStackEvent) commandStackEvents.get(0)).getDetail() & CommandStack.POST_MASK);

Assert.assertEquals(c, ((CommandStackEvent) commandStackEvents.get(1)).getCommand());
Assert.assertFalse(((CommandStackEvent) commandStackEvents.get(1)).isPreChangeEvent());
Assert.assertTrue(((CommandStackEvent) commandStackEvents.get(1)).isPostChangeEvent());
Assert.assertEquals(stack, ((CommandStackEvent) commandStackEvents.get(1)).getSource());
Assert.assertEquals(CommandStack.POST_UNDO, ((CommandStackEvent) commandStackEvents.get(1)).getDetail());
Assert.assertEquals(0, ((CommandStackEvent) commandStackEvents.get(1)).getDetail() & CommandStack.PRE_MASK);
Assert.assertNotEquals(0, ((CommandStackEvent) commandStackEvents.get(1)).getDetail() & CommandStack.POST_MASK);
Assert.assertEquals(c, commandStackEvents.get(0).getCommand());
Assert.assertTrue(commandStackEvents.get(0).isPreChangeEvent());
Assert.assertFalse(commandStackEvents.get(0).isPostChangeEvent());
Assert.assertEquals(stack, commandStackEvents.get(0).getSource());
Assert.assertEquals(CommandStack.PRE_UNDO, commandStackEvents.get(0).getDetail());
Assert.assertNotEquals(0, commandStackEvents.get(0).getDetail() & CommandStack.PRE_MASK);
Assert.assertEquals(0, commandStackEvents.get(0).getDetail() & CommandStack.POST_MASK);

Assert.assertEquals(c, commandStackEvents.get(1).getCommand());
Assert.assertFalse(commandStackEvents.get(1).isPreChangeEvent());
Assert.assertTrue(commandStackEvents.get(1).isPostChangeEvent());
Assert.assertEquals(stack, commandStackEvents.get(1).getSource());
Assert.assertEquals(CommandStack.POST_UNDO, commandStackEvents.get(1).getDetail());
Assert.assertEquals(0, commandStackEvents.get(1).getDetail() & CommandStack.PRE_MASK);
Assert.assertNotEquals(0, commandStackEvents.get(1).getDetail() & CommandStack.POST_MASK);

// // test redo pre and post events
commandStackEvents.clear();
Assert.assertEquals(0, commandStackEvents.size());
stack.redo();

Assert.assertEquals(2, commandStackEvents.size());
Assert.assertEquals(c, ((CommandStackEvent) commandStackEvents.get(0)).getCommand());
Assert.assertTrue(((CommandStackEvent) commandStackEvents.get(0)).isPreChangeEvent());
Assert.assertFalse(((CommandStackEvent) commandStackEvents.get(0)).isPostChangeEvent());
Assert.assertEquals(stack, ((CommandStackEvent) commandStackEvents.get(0)).getSource());
Assert.assertEquals(CommandStack.PRE_REDO, ((CommandStackEvent) commandStackEvents.get(0)).getDetail());
Assert.assertNotEquals(0, ((CommandStackEvent) commandStackEvents.get(0)).getDetail() & CommandStack.PRE_MASK);
Assert.assertEquals(0, ((CommandStackEvent) commandStackEvents.get(0)).getDetail() & CommandStack.POST_MASK);

Assert.assertEquals(c, ((CommandStackEvent) commandStackEvents.get(1)).getCommand());
Assert.assertFalse(((CommandStackEvent) commandStackEvents.get(1)).isPreChangeEvent());
Assert.assertTrue(((CommandStackEvent) commandStackEvents.get(1)).isPostChangeEvent());
Assert.assertEquals(stack, ((CommandStackEvent) commandStackEvents.get(1)).getSource());
Assert.assertEquals(CommandStack.POST_REDO, ((CommandStackEvent) commandStackEvents.get(1)).getDetail());
Assert.assertEquals(0, ((CommandStackEvent) commandStackEvents.get(1)).getDetail() & CommandStack.PRE_MASK);
Assert.assertNotEquals(0, ((CommandStackEvent) commandStackEvents.get(1)).getDetail() & CommandStack.POST_MASK);
Assert.assertEquals(c, commandStackEvents.get(0).getCommand());
Assert.assertTrue(commandStackEvents.get(0).isPreChangeEvent());
Assert.assertFalse(commandStackEvents.get(0).isPostChangeEvent());
Assert.assertEquals(stack, commandStackEvents.get(0).getSource());
Assert.assertEquals(CommandStack.PRE_REDO, commandStackEvents.get(0).getDetail());
Assert.assertNotEquals(0, commandStackEvents.get(0).getDetail() & CommandStack.PRE_MASK);
Assert.assertEquals(0, commandStackEvents.get(0).getDetail() & CommandStack.POST_MASK);

Assert.assertEquals(c, commandStackEvents.get(1).getCommand());
Assert.assertFalse(commandStackEvents.get(1).isPreChangeEvent());
Assert.assertTrue(commandStackEvents.get(1).isPostChangeEvent());
Assert.assertEquals(stack, commandStackEvents.get(1).getSource());
Assert.assertEquals(CommandStack.POST_REDO, commandStackEvents.get(1).getDetail());
Assert.assertEquals(0, commandStackEvents.get(1).getDetail() & CommandStack.PRE_MASK);
Assert.assertNotEquals(0, commandStackEvents.get(1).getDetail() & CommandStack.POST_MASK);

// test flush event
commandStackEvents.clear();
Assert.assertEquals(0, commandStackEvents.size());
stack.flush();

Assert.assertEquals(2, commandStackEvents.size());
Assert.assertEquals(null, ((CommandStackEvent) commandStackEvents.get(0)).getCommand());
Assert.assertTrue(((CommandStackEvent) commandStackEvents.get(0)).isPreChangeEvent());
Assert.assertFalse(((CommandStackEvent) commandStackEvents.get(0)).isPostChangeEvent());
Assert.assertEquals(stack, ((CommandStackEvent) commandStackEvents.get(0)).getSource());
Assert.assertEquals(CommandStack.PRE_FLUSH, ((CommandStackEvent) commandStackEvents.get(0)).getDetail());
Assert.assertNotEquals(0, ((CommandStackEvent) commandStackEvents.get(0)).getDetail() & CommandStack.PRE_MASK);
Assert.assertEquals(0, ((CommandStackEvent) commandStackEvents.get(0)).getDetail() & CommandStack.POST_MASK);

Assert.assertEquals(null, ((CommandStackEvent) commandStackEvents.get(1)).getCommand());
Assert.assertFalse(((CommandStackEvent) commandStackEvents.get(1)).isPreChangeEvent());
Assert.assertTrue(((CommandStackEvent) commandStackEvents.get(1)).isPostChangeEvent());
Assert.assertEquals(stack, ((CommandStackEvent) commandStackEvents.get(1)).getSource());
Assert.assertEquals(CommandStack.POST_FLUSH, ((CommandStackEvent) commandStackEvents.get(1)).getDetail());
Assert.assertEquals(0, ((CommandStackEvent) commandStackEvents.get(1)).getDetail() & CommandStack.PRE_MASK);
Assert.assertNotEquals(0, ((CommandStackEvent) commandStackEvents.get(1)).getDetail() & CommandStack.POST_MASK);
Assert.assertEquals(null, commandStackEvents.get(0).getCommand());
Assert.assertTrue(commandStackEvents.get(0).isPreChangeEvent());
Assert.assertFalse(commandStackEvents.get(0).isPostChangeEvent());
Assert.assertEquals(stack, commandStackEvents.get(0).getSource());
Assert.assertEquals(CommandStack.PRE_FLUSH, commandStackEvents.get(0).getDetail());
Assert.assertNotEquals(0, commandStackEvents.get(0).getDetail() & CommandStack.PRE_MASK);
Assert.assertEquals(0, commandStackEvents.get(0).getDetail() & CommandStack.POST_MASK);

Assert.assertEquals(null, commandStackEvents.get(1).getCommand());
Assert.assertFalse(commandStackEvents.get(1).isPreChangeEvent());
Assert.assertTrue(commandStackEvents.get(1).isPostChangeEvent());
Assert.assertEquals(stack, commandStackEvents.get(1).getSource());
Assert.assertEquals(CommandStack.POST_FLUSH, commandStackEvents.get(1).getDetail());
Assert.assertEquals(0, commandStackEvents.get(1).getDetail() & CommandStack.PRE_MASK);
Assert.assertNotEquals(0, commandStackEvents.get(1).getDetail() & CommandStack.POST_MASK);

// test mark save location event
commandStackEvents.clear();
Expand All @@ -122,21 +118,21 @@ public void stackChanged(CommandStackEvent event) {
stack.markSaveLocation();

Assert.assertEquals(2, commandStackEvents.size());
Assert.assertEquals(null, ((CommandStackEvent) commandStackEvents.get(0)).getCommand());
Assert.assertTrue(((CommandStackEvent) commandStackEvents.get(0)).isPreChangeEvent());
Assert.assertFalse(((CommandStackEvent) commandStackEvents.get(0)).isPostChangeEvent());
Assert.assertEquals(stack, ((CommandStackEvent) commandStackEvents.get(0)).getSource());
Assert.assertEquals(CommandStack.PRE_MARK_SAVE, ((CommandStackEvent) commandStackEvents.get(0)).getDetail());
Assert.assertNotEquals(0, ((CommandStackEvent) commandStackEvents.get(0)).getDetail() & CommandStack.PRE_MASK);
Assert.assertEquals(0, ((CommandStackEvent) commandStackEvents.get(0)).getDetail() & CommandStack.POST_MASK);

Assert.assertEquals(null, ((CommandStackEvent) commandStackEvents.get(1)).getCommand());
Assert.assertFalse(((CommandStackEvent) commandStackEvents.get(1)).isPreChangeEvent());
Assert.assertTrue(((CommandStackEvent) commandStackEvents.get(1)).isPostChangeEvent());
Assert.assertEquals(stack, ((CommandStackEvent) commandStackEvents.get(1)).getSource());
Assert.assertEquals(CommandStack.POST_MARK_SAVE, ((CommandStackEvent) commandStackEvents.get(1)).getDetail());
Assert.assertEquals(0, ((CommandStackEvent) commandStackEvents.get(1)).getDetail() & CommandStack.PRE_MASK);
Assert.assertNotEquals(0, ((CommandStackEvent) commandStackEvents.get(1)).getDetail() & CommandStack.POST_MASK);
Assert.assertEquals(null, commandStackEvents.get(0).getCommand());
Assert.assertTrue(commandStackEvents.get(0).isPreChangeEvent());
Assert.assertFalse(commandStackEvents.get(0).isPostChangeEvent());
Assert.assertEquals(stack, commandStackEvents.get(0).getSource());
Assert.assertEquals(CommandStack.PRE_MARK_SAVE, commandStackEvents.get(0).getDetail());
Assert.assertNotEquals(0, commandStackEvents.get(0).getDetail() & CommandStack.PRE_MASK);
Assert.assertEquals(0, commandStackEvents.get(0).getDetail() & CommandStack.POST_MASK);

Assert.assertEquals(null, commandStackEvents.get(1).getCommand());
Assert.assertFalse(commandStackEvents.get(1).isPreChangeEvent());
Assert.assertTrue(commandStackEvents.get(1).isPostChangeEvent());
Assert.assertEquals(stack, commandStackEvents.get(1).getSource());
Assert.assertEquals(CommandStack.POST_MARK_SAVE, commandStackEvents.get(1).getDetail());
Assert.assertEquals(0, commandStackEvents.get(1).getDetail() & CommandStack.PRE_MASK);
Assert.assertNotEquals(0, commandStackEvents.get(1).getDetail() & CommandStack.POST_MASK);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@

import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.gef.tools.DragEditPartsTracker;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.PartInitException;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;

import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.gef.tools.DragEditPartsTracker;

import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -169,18 +172,18 @@ public TestDragEditPartsTracker(EditPart sourceEditPart) {
}

@Override
public List createOperationSet() {
public List<? extends EditPart> createOperationSet() {
return super.createOperationSet();
}
};
}

@Test
public void test_createOperationSet() {
public void testCreateOperationSet() {
TestDragEditPartsTracker dept = new TestDragEditPartsTracker(new TestGraphicalEditPart());

dept.setEditDomain(new DefaultEditDomain(new DummyEditorPart()));
dept.activate();
List operationSet = dept.createOperationSet();
List<? extends EditPart> operationSet = dept.createOperationSet();
assertTrue(operationSet != null);
dept.deactivate();
}
Expand Down
Loading

0 comments on commit 764ad84

Please sign in to comment.