) changes.get(composite);
} catch (Exception e) {
- fail("Could not access private changes field of CompositeChangeDescription: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assertions.fail(
+ "Could not access private changes field of CompositeChangeDescription: " + e.getLocalizedMessage());
}
return result;
}
-
+
private static class ChangeExternalData extends AbstractOperation {
private final String[] externalData;
private Book book;
private Library[] library;
private String oldData;
-
+
ChangeExternalData(String[] externalData, Book book) {
- super("Change External Data"); //$NON-NLS-1$
-
+ super("Change External Data");
+
this.externalData = externalData;
this.book = book;
}
-
+
ChangeExternalData(String[] externalData, Library[] library) {
- super("Change External Data"); //$NON-NLS-1$
-
+ super("Change External Data");
+
this.externalData = externalData;
this.library = library;
}
-
+
@Override
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
oldData = externalData[0];
-
+
// can safely read in the enclosing composite's write transaction
if (book == null) {
// get the book from the new library, then
book = library[0].getBooks().get(0);
}
-
+
externalData[0] = book.getTitle();
-
+
return Status.OK_STATUS;
}
-
+
@Override
public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
externalData[0] = oldData;
return Status.OK_STATUS;
}
-
+
@Override
public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
externalData[0] = book.getTitle();
return Status.OK_STATUS;
}
}
-
+
private static class FailCancelOperation extends AbstractOperation {
private final IStatus executeStatus;
private final IStatus undoStatus;
private final IStatus redoStatus;
private final boolean cancelMonitor;
-
+
FailCancelOperation(IStatus exec, IStatus undo, IStatus redo, boolean cancel) {
- super("Fail/Cancel Operation"); //$NON-NLS-1$
+ super("Fail/Cancel Operation");
this.executeStatus = exec;
this.undoStatus = undo;
this.redoStatus = redo;
this.cancelMonitor = cancel;
}
-
+
@Override
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
if ((executeStatus.getSeverity() == IStatus.CANCEL) && cancelMonitor) {
monitor.setCanceled(true);
return Status.OK_STATUS;
}
-
+
return executeStatus;
}
-
+
@Override
public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
if ((undoStatus.getSeverity() == IStatus.CANCEL) && cancelMonitor) {
monitor.setCanceled(true);
return Status.OK_STATUS;
}
-
+
return undoStatus;
}
-
+
@Override
public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
if ((redoStatus.getSeverity() == IStatus.CANCEL) && cancelMonitor) {
monitor.setCanceled(true);
return Status.OK_STATUS;
}
-
+
return redoStatus;
}
}
-
+
static class MarkerOperation extends AbstractOperation {
boolean wasExecuted;
boolean wasUndone;
boolean wasRedone;
-
+
MarkerOperation() {
- super("Marker operation"); //$NON-NLS-1$
+ super("Marker operation");
}
-
+
void reset() {
wasExecuted = false;
wasUndone = false;
wasRedone = false;
}
-
+
@Override
- public IStatus execute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
wasExecuted = true;
return Status.OK_STATUS;
}
-
+
@Override
- public IStatus undo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
wasUndone = true;
return Status.OK_STATUS;
}
-
+
@Override
- public IStatus redo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
wasRedone = true;
return Status.OK_STATUS;
}
}
-
+
private static class TransactionCapture extends ResourceSetListenerImpl {
private Transaction transaction;
-
+
@Override
public boolean isPostcommitOnly() {
return true;
}
-
+
@Override
public void resourceSetChanged(ResourceSetChangeEvent event) {
if (transaction == null) {
transaction = event.getTransaction();
}
}
-
+
void clear() {
transaction = null;
}
-
+
Transaction getTransaction() {
return transaction;
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/EMFCommandOperationTest.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/EMFCommandOperationTest.java
index 70bbe846..b8077187 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/EMFCommandOperationTest.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/EMFCommandOperationTest.java
@@ -12,8 +12,11 @@
*/
package org.eclipse.emf.workspace.tests;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.IUndoContext;
@@ -43,7 +46,7 @@
import org.eclipse.emf.workspace.tests.fixtures.LibraryDefaultNameTrigger;
import org.eclipse.emf.workspace.tests.fixtures.TestCommand;
import org.eclipse.emf.workspace.tests.fixtures.TestUndoContext;
-
+import org.junit.jupiter.api.Test;
/**
* Tests the {@link EMFCommandOperation} class.
@@ -52,55 +55,40 @@
*/
public class EMFCommandOperationTest extends AbstractTest {
- public EMFCommandOperationTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(EMFCommandOperationTest.class, "EMF Command Operation Tests"); //$NON-NLS-1$
- }
-
+ @Test
public void test_execute_undo_redo() {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
final String oldTitle = book.getTitle();
final Writer oldAuthor = book.getAuthor();
-
- final String newTitle = "New Title"; //$NON-NLS-1$
- final Writer newAuthor = (Writer) find("root/level1/Level1 Writer"); //$NON-NLS-1$
+
+ final String newTitle = "New Title";
+ final Writer newAuthor = (Writer) find("root/level1/Level1 Writer");
assertNotNull(newAuthor);
-
+
commit();
-
+
IUndoContext ctx = new TestUndoContext();
-
- Command cmd = new SetCommand(
- domain,
- book,
- EXTLibraryPackage.eINSTANCE.getBook_Title(),
- newTitle);
- cmd = cmd.chain(new AddCommand(
- domain,
- newAuthor,
- EXTLibraryPackage.eINSTANCE.getWriter_Books(),
- book));
+
+ Command cmd = new SetCommand(domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle);
+ cmd = cmd.chain(new AddCommand(domain, newAuthor, EXTLibraryPackage.eINSTANCE.getWriter_Books(), book));
IUndoableOperation oper = new EMFCommandOperation(domain, cmd);
-
+
try {
oper.addContext(ctx);
history.execute(oper, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were applied
assertSame(newTitle, book.getTitle());
assertSame(newAuthor, book.getAuthor());
-
+
commit();
try {
@@ -109,67 +97,64 @@ public void test_execute_undo_redo() {
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were undone
assertSame(oldTitle, book.getTitle());
assertSame(oldAuthor, book.getAuthor());
-
+
commit();
-
+
try {
assertTrue(history.canRedo(ctx));
history.redo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were redone
assertSame(newTitle, book.getTitle());
assertSame(newAuthor, book.getAuthor());
-
+
commit();
}
-
+
/**
* Tests that trigger commands are executed correctly when executing operations,
* including undo and redo.
*/
+ @Test
public void test_triggerCommands() {
// one trigger sets default library names
domain.addResourceSetListener(new LibraryDefaultNameTrigger());
-
+
// another (distinct) trigger creates default books in new libraries
domain.addResourceSetListener(new LibraryDefaultBookTrigger());
-
+
final Library newLibrary = EXTLibraryFactory.eINSTANCE.createLibrary();
-
+
IUndoContext ctx = new TestUndoContext();
-
- // add a new library. Our triggers will set a default name and book
- Command cmd = new AddCommand(
- domain,
- root,
- EXTLibraryPackage.eINSTANCE.getLibrary_Branches(),
- newLibrary);
+
+ // add a new library. Our triggers will set a default name and book
+ Command cmd = new AddCommand(domain, root, EXTLibraryPackage.eINSTANCE.getLibrary_Branches(), newLibrary);
IUndoableOperation oper = new EMFCommandOperation(domain, cmd);
-
+
try {
oper.addContext(ctx);
history.execute(oper, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
- assertEquals("New Library", newLibrary.getName()); //$NON-NLS-1$
+
+ assertEquals("New Library", newLibrary.getName());
assertEquals(1, newLibrary.getBooks().size());
- assertEquals("New Book", newLibrary.getBooks().get(0).getTitle()); //$NON-NLS-1$
-
+ assertEquals("New Book", newLibrary.getBooks().get(0).getTitle());
+
commit();
try {
@@ -178,72 +163,69 @@ public void test_triggerCommands() {
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were undone
assertFalse(root.getBranches().contains(newLibrary));
-
+
commit();
-
+
try {
assertTrue(history.canRedo(ctx));
history.redo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were redone
assertTrue(root.getBranches().contains(newLibrary));
- assertEquals("New Library", newLibrary.getName()); //$NON-NLS-1$
+ assertEquals("New Library", newLibrary.getName());
assertEquals(1, newLibrary.getBooks().size());
- assertEquals("New Book", newLibrary.getBooks().get(0).getTitle()); //$NON-NLS-1$
-
+ assertEquals("New Book", newLibrary.getBooks().get(0).getTitle());
+
commit();
}
-
+
/**
* Tests that a command resulting from a pre-commit (trigger) listener will,
* itself, trigger further changes.
*/
+ @Test
public void test_triggerCommands_cascading() {
// add the trigger to create a default book in a new library
domain.addResourceSetListener(new LibraryDefaultBookTrigger());
-
+
// add another trigger that will set default publication dates for new items
domain.addResourceSetListener(new ItemDefaultPublicationDateTrigger());
-
+
final Library newLibrary = EXTLibraryFactory.eINSTANCE.createLibrary();
-
+
IUndoContext ctx = new TestUndoContext();
-
- // add a new library. Our triggers will set a default name and book
- Command cmd = new AddCommand(
- domain,
- root,
- EXTLibraryPackage.eINSTANCE.getLibrary_Branches(),
- newLibrary);
+
+ // add a new library. Our triggers will set a default name and book
+ Command cmd = new AddCommand(domain, root, EXTLibraryPackage.eINSTANCE.getLibrary_Branches(), newLibrary);
IUndoableOperation oper = new EMFCommandOperation(domain, cmd);
-
+
try {
oper.addContext(ctx);
history.execute(oper, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// the book is created by the first trigger
assertEquals(1, newLibrary.getBooks().size());
Book book = newLibrary.getBooks().get(0);
- assertEquals("New Book", book.getTitle()); //$NON-NLS-1$
-
+ assertEquals("New Book", book.getTitle());
+
// the publication date is created by the cascaded trigger
assertNotNull(book.getPublicationDate());
-
+
commit();
try {
@@ -252,74 +234,76 @@ public void test_triggerCommands_cascading() {
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were undone
assertFalse(root.getBranches().contains(newLibrary));
-
+
commit();
-
+
try {
assertTrue(history.canRedo(ctx));
history.redo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were redone
assertTrue(root.getBranches().contains(newLibrary));
assertEquals(1, newLibrary.getBooks().size());
book = newLibrary.getBooks().get(0);
- assertEquals("New Book", book.getTitle()); //$NON-NLS-1$
+ assertEquals("New Book", book.getTitle());
assertNotNull(book.getPublicationDate());
-
+
commit();
}
-
+
/**
* Tests that an EMF Command Operation works well with recording commands.
*/
+ @Test
public void test_RecordingCommand_execute_undo_redo() {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
final String oldTitle = book.getTitle();
final Writer oldAuthor = book.getAuthor();
-
- final String newTitle = "New Title"; //$NON-NLS-1$
- final Writer newAuthor = (Writer) find("root/level1/Level1 Writer"); //$NON-NLS-1$
+
+ final String newTitle = "New Title";
+ final Writer newAuthor = (Writer) find("root/level1/Level1 Writer");
assertNotNull(newAuthor);
-
+
commit();
-
+
IUndoContext ctx = new TestUndoContext();
-
+
Command cmd = new RecordingCommand(domain) {
@Override
protected void doExecute() {
book.setTitle(newTitle);
newAuthor.getBooks().add(book);
- }};
-
+ }
+ };
+
IUndoableOperation oper = new EMFCommandOperation(domain, cmd);
-
+
try {
oper.addContext(ctx);
history.execute(oper, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were applied
assertSame(newTitle, book.getTitle());
assertSame(newAuthor, book.getAuthor());
-
+
commit();
try {
@@ -328,68 +312,70 @@ protected void doExecute() {
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were undone
assertSame(oldTitle, book.getTitle());
assertSame(oldAuthor, book.getAuthor());
-
+
commit();
-
+
try {
assertTrue(history.canRedo(ctx));
history.redo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were redone
assertSame(newTitle, book.getTitle());
assertSame(newAuthor, book.getAuthor());
-
+
commit();
}
-
+
/**
* Tests that trigger commands on recording commands are correctly undone, by
* the recording command, itself (which records the entire transaction).
*/
+ @Test
public void test_RecordingCommand_triggerCommands() {
// one trigger sets default library names
domain.addResourceSetListener(new LibraryDefaultNameTrigger());
-
+
// another (distinct) trigger creates default books in new libraries
domain.addResourceSetListener(new LibraryDefaultBookTrigger());
-
+
final Library newLibrary = EXTLibraryFactory.eINSTANCE.createLibrary();
-
+
IUndoContext ctx = new TestUndoContext();
-
- // add a new library. Our triggers will set a default name and book
+
+ // add a new library. Our triggers will set a default name and book
Command cmd = new RecordingCommand(domain) {
@Override
protected void doExecute() {
root.getBranches().add(newLibrary);
- }};
-
+ }
+ };
+
IUndoableOperation oper = new EMFCommandOperation(domain, cmd);
-
+
try {
oper.addContext(ctx);
history.execute(oper, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
- assertEquals("New Library", newLibrary.getName()); //$NON-NLS-1$
+
+ assertEquals("New Library", newLibrary.getName());
assertEquals(1, newLibrary.getBooks().size());
- assertEquals("New Book", newLibrary.getBooks().get(0).getTitle()); //$NON-NLS-1$
-
+ assertEquals("New Book", newLibrary.getBooks().get(0).getTitle());
+
commit();
try {
@@ -398,65 +384,58 @@ protected void doExecute() {
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were undone
assertFalse(root.getBranches().contains(newLibrary));
-
+
commit();
-
+
try {
assertTrue(history.canRedo(ctx));
history.redo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were redone
assertTrue(root.getBranches().contains(newLibrary));
- assertEquals("New Library", newLibrary.getName()); //$NON-NLS-1$
+ assertEquals("New Library", newLibrary.getName());
assertEquals(1, newLibrary.getBooks().size());
- assertEquals("New Book", newLibrary.getBooks().get(0).getTitle()); //$NON-NLS-1$
-
+ assertEquals("New Book", newLibrary.getBooks().get(0).getTitle());
+
commit();
}
-
+
/**
* Tests that validation correctly rolls back changes and fails execution.
*/
+ @Test
public void test_validation() {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
final String oldTitle = book.getTitle();
final Writer oldAuthor = book.getAuthor();
-
+
final String newTitle = null; // will fail validation
- final Writer newAuthor = (Writer) find("root/level1/Level1 Writer"); //$NON-NLS-1$
+ final Writer newAuthor = (Writer) find("root/level1/Level1 Writer");
assertNotNull(newAuthor);
-
+
commit();
-
+
IUndoContext ctx = new TestUndoContext();
-
- Command cmd = new SetCommand(
- domain,
- book,
- EXTLibraryPackage.eINSTANCE.getBook_Title(),
- newTitle);
- cmd = cmd.chain(new AddCommand(
- domain,
- newAuthor,
- EXTLibraryPackage.eINSTANCE.getWriter_Books(),
- book));
+
+ Command cmd = new SetCommand(domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle);
+ cmd = cmd.chain(new AddCommand(domain, newAuthor, EXTLibraryPackage.eINSTANCE.getWriter_Books(), book));
IUndoableOperation oper = new EMFCommandOperation(domain, cmd);
-
+
IStatus status = null;
-
+
try {
validationEnabled = true;
oper.addContext(ctx);
@@ -466,50 +445,53 @@ public void test_validation() {
} finally {
validationEnabled = false;
}
-
+
assertNotNull(status);
assertTrue(status.matches(IStatus.ERROR));
-
+
status = findValidationStatus(status, IStatus.ERROR);
assertNotNull(status);
-
+
startReading();
-
+
// verify that the changes were rolled back
assertSame(oldTitle, book.getTitle());
assertSame(oldAuthor, book.getAuthor());
-
+
commit();
}
-
+
/**
- * Tests that the the EMFCommandOperation tests its wrapped
- * command for redoability.
+ * Tests that the the EMFCommandOperation tests its wrapped command
+ * for redoability.
*/
+ @Test
public void test_nonredoableCommand_138287() {
Command cmd = new TestCommand.Redoable() {
public void execute() {
// nothing to do
}
-
+
@Override
public boolean canRedo() {
return false;
- }};
-
+ }
+ };
+
getCommandStack().execute(cmd);
-
+
assertTrue(getCommandStack().canUndo());
-
+
getCommandStack().undo();
-
+
assertFalse(getCommandStack().canRedo());
}
-
+
/**
* Tests that the EMFCommandOperation tests its wrapped trigger
* command for redoability.
*/
+ @Test
public void test_nonredoableTriggerCommand_138287() {
// add a trigger command that is not redoable
domain.addResourceSetListener(new TriggerListener() {
@@ -519,156 +501,162 @@ protected Command trigger(TransactionalEditingDomain domain, Notification notifi
public void execute() {
// nothing to do
}
-
+
@Override
public boolean canRedo() {
return false;
- }};
- }});
-
+ }
+ };
+ }
+ });
+
Library newLibrary = EXTLibraryFactory.eINSTANCE.createLibrary();
-
+
// this command *is* implicitly redoable; it is the trigger that is not
- Command cmd = AddCommand.create(
- domain, root, EXTLibraryPackage.Literals.LIBRARY__BRANCHES,
- newLibrary);
-
+ Command cmd = AddCommand.create(domain, root, EXTLibraryPackage.Literals.LIBRARY__BRANCHES, newLibrary);
+
getCommandStack().execute(cmd);
-
+
assertTrue(getCommandStack().canUndo());
-
+
getCommandStack().undo();
-
+
assertFalse(getCommandStack().canRedo());
}
-
- /**
- * Tests that recording-commands used as triggers are not undone twice when
- * executing a recording-command on the command-stack.
- */
- public void test_undoRecordingCommandWithRecordingCommandTrigger_218276() {
- final Book[] book = new Book[] {(Book) find("root/Root Book")}; //$NON-NLS-1$
- final int newCopies = 30;
-
- final RecordingCommand trigger = new RecordingCommand(domain, "Test Trigger") { //$NON-NLS-1$
-
+
+ /**
+ * Tests that recording-commands used as triggers are not undone twice when
+ * executing a recording-command on the command-stack.
+ */
+ @Test
+ public void test_undoRecordingCommandWithRecordingCommandTrigger_218276() {
+ final Book[] book = new Book[] { (Book) find("root/Root Book") };
+ final int newCopies = 30;
+
+ final RecordingCommand trigger = new RecordingCommand(domain, "Test Trigger") {
+
@Override
protected void doExecute() {
book[0].setCopies(newCopies);
- }};
-
+ }
+ };
+
ResourceSetListener listener = new ResourceSetListenerImpl() {
@Override
public boolean isPrecommitOnly() {
return true;
}
-
+
@Override
- public Command transactionAboutToCommit(ResourceSetChangeEvent event)
- throws RollbackException {
-
+ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
+
CompoundCommand result = new CompoundCommand();
-
+
for (Notification next : event.getNotifications()) {
if (next.getFeature() == EXTLibraryPackage.Literals.BOOK__TITLE) {
return trigger;
}
}
-
+
return result;
- }};
-
+ }
+ };
+
try {
domain.addResourceSetListener(listener);
-
- final String newTitle = "New Title"; //$NON-NLS-1$
-
- getCommandStack().execute(new RecordingCommand(domain, "Test") { //$NON-NLS-1$
+
+ final String newTitle = "New Title";
+
+ getCommandStack().execute(new RecordingCommand(domain, "Test") {
@Override
protected void doExecute() {
book[0].setTitle(newTitle);
- }});
-
- assertEquals("Wrong number of copies on execute", newCopies, book[0].getCopies()); //$NON-NLS-1$
-
+ }
+ });
+
+ assertEquals(newCopies, book[0].getCopies(), "Wrong number of copies on execute");
+
getCommandStack().undo();
-
- assertFalse("Wrong number of copies on undo", book[0].getCopies() == newCopies); //$NON-NLS-1$
-
+
+ assertFalse(book[0].getCopies() == newCopies, "Wrong number of copies on undo");
+
getCommandStack().redo();
-
- assertEquals("Wrong number of copies on redo", newCopies, book[0].getCopies()); //$NON-NLS-1$
+
+ assertEquals(newCopies, book[0].getCopies(), "Wrong number of copies on redo");
} catch (Exception e) {
fail(e);
} finally {
domain.removeResourceSetListener(listener);
}
- }
-
- /**
- * Tests that recording-commands used as triggers are not undone twice
- * when executing recording-commands that are nested in some compound
- * command that is executed on the command-stack.
- */
- public void test_undoNestedRecordingCommandWithRecordingCommandTrigger_218276() {
- final Book[] book = new Book[] {(Book) find("root/Root Book")}; //$NON-NLS-1$
- final int newCopies = 30;
-
- final RecordingCommand trigger = new RecordingCommand(domain, "Test Trigger") { //$NON-NLS-1$
-
+ }
+
+ /**
+ * Tests that recording-commands used as triggers are not undone twice when
+ * executing recording-commands that are nested in some compound command that is
+ * executed on the command-stack.
+ */
+ @Test
+ public void test_undoNestedRecordingCommandWithRecordingCommandTrigger_218276() {
+ final Book[] book = new Book[] { (Book) find("root/Root Book") };
+ final int newCopies = 30;
+
+ final RecordingCommand trigger = new RecordingCommand(domain, "Test Trigger") {
+
@Override
protected void doExecute() {
book[0].setCopies(newCopies);
- }};
-
+ }
+ };
+
ResourceSetListener listener = new ResourceSetListenerImpl() {
@Override
public boolean isPrecommitOnly() {
return true;
}
-
+
@Override
- public Command transactionAboutToCommit(ResourceSetChangeEvent event)
- throws RollbackException {
-
+ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
+
CompoundCommand result = new CompoundCommand();
-
+
for (Notification next : event.getNotifications()) {
if (next.getFeature() == EXTLibraryPackage.Literals.BOOK__TITLE) {
return trigger;
}
}
-
+
return result;
- }};
-
+ }
+ };
+
try {
domain.addResourceSetListener(listener);
-
- final String newTitle = "New Title"; //$NON-NLS-1$
-
- CompoundCommand cc = new CompoundCommand("Test"); //$NON-NLS-1$
- cc.append(new RecordingCommand(domain, "Test") { //$NON-NLS-1$
+
+ final String newTitle = "New Title";
+
+ CompoundCommand cc = new CompoundCommand("Test");
+ cc.append(new RecordingCommand(domain, "Test") {
@Override
protected void doExecute() {
book[0].setTitle(newTitle);
- }});
+ }
+ });
getCommandStack().execute(cc);
-
- assertEquals("Wrong number of copies on execute", newCopies, book[0].getCopies()); //$NON-NLS-1$
-
+
+ assertEquals(newCopies, book[0].getCopies(), "Wrong number of copies on execute");
+
getCommandStack().undo();
-
- assertFalse("Wrong number of copies on undo", book[0].getCopies() == newCopies); //$NON-NLS-1$
-
+
+ assertFalse(book[0].getCopies() == newCopies, "Wrong number of copies on undo");
+
getCommandStack().redo();
-
- assertEquals("Wrong number of copies on redo", newCopies, book[0].getCopies()); //$NON-NLS-1$
+
+ assertEquals(newCopies, book[0].getCopies(), "Wrong number of copies on redo");
} catch (Exception e) {
fail(e);
} finally {
domain.removeResourceSetListener(listener);
}
- }
+ }
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/EMFOperationCommandTest.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/EMFOperationCommandTest.java
index 4f78a524..10fc4317 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/EMFOperationCommandTest.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/EMFOperationCommandTest.java
@@ -12,8 +12,12 @@
*/
package org.eclipse.emf.workspace.tests;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.AbstractOperation;
@@ -38,7 +42,8 @@
import org.eclipse.emf.workspace.tests.fixtures.ExternalDataOperation;
import org.eclipse.emf.workspace.tests.fixtures.TestOperation;
import org.eclipse.emf.workspace.tests.fixtures.TestUndoContext;
-
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests the {@link EMFOperationCommand} class.
@@ -47,59 +52,45 @@
*/
public class EMFOperationCommandTest extends AbstractTest {
- public EMFOperationCommandTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(EMFOperationCommandTest.class, "EMF Operation Command Tests"); //$NON-NLS-1$
- }
-
/**
- * Tests execution, undo, and redo of operations wrapped within an
- * EMF command.
+ * Tests execution, undo, and redo of operations wrapped within an EMF command.
*/
+ @Test
public void test_execute_undo_redo() {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
final String oldTitle = book.getTitle();
-
- final String[] externalData = new String[] {"external"}; //$NON-NLS-1$
+
+ final String[] externalData = new String[] { "external" };
final String oldExternalData = externalData[0];
- final String newExternalData = "newValue"; //$NON-NLS-1$
-
- final String newTitle = "New Title"; //$NON-NLS-1$
-
+ final String newExternalData = "newValue";
+
+ final String newTitle = "New Title";
+
commit();
-
+
IUndoContext ctx = new TestUndoContext();
-
- Command cmd = new SetCommand(
- domain,
- book,
- EXTLibraryPackage.eINSTANCE.getBook_Title(),
- newTitle);
- IUndoableOperation oper = new ExternalDataOperation(
- externalData,
- newExternalData);
-
+
+ Command cmd = new SetCommand(domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle);
+ IUndoableOperation oper = new ExternalDataOperation(externalData, newExternalData);
+
cmd = cmd.chain(new EMFOperationCommand(domain, oper));
-
+
try {
history.addOperationHistoryListener(new ContextAdder(ctx));
getCommandStack().execute(cmd, null);
} catch (Exception e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were applied
assertSame(newTitle, book.getTitle());
assertEquals(newExternalData, externalData[0]);
-
+
commit();
try {
@@ -108,92 +99,87 @@ public void test_execute_undo_redo() {
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were undone
assertSame(oldTitle, book.getTitle());
assertEquals(oldExternalData, externalData[0]);
-
+
commit();
-
+
try {
assertTrue(history.canRedo(ctx));
history.redo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were redone
assertSame(newTitle, book.getTitle());
assertEquals(newExternalData, externalData[0]);
-
+
commit();
}
-
+
/**
* Tests execution, undo, and redo of operations wrapped in commands as
* pre-commit triggers.
*/
+ @Test
public void test_execute_undo_redo_trigger() {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
final String oldTitle = book.getTitle();
-
- final String[] externalData = new String[] {"external"}; //$NON-NLS-1$
+
+ final String[] externalData = new String[] { "external" };
final String oldExternalData = externalData[0];
- final String newExternalData = "newValue"; //$NON-NLS-1$
-
- final String newTitle = "New Title"; //$NON-NLS-1$
-
+ final String newExternalData = "newValue";
+
+ final String newTitle = "New Title";
+
commit();
-
+
IUndoContext ctx = new TestUndoContext();
-
- Command cmd = new SetCommand(
- domain,
- book,
- EXTLibraryPackage.eINSTANCE.getBook_Title(),
- newTitle);
-
+
+ Command cmd = new SetCommand(domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle);
+
domain.addResourceSetListener(new TriggerListener() {
-
+
@Override
protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
Command result = null;
-
- if ((notification.getNotifier() == book)
- && newTitle.equals(notification.getNewValue())) {
-
- trace("Adding external data trigger command"); //$NON-NLS-1$
-
- IUndoableOperation oper = new ExternalDataOperation(
- externalData,
- newExternalData);
-
+
+ if ((notification.getNotifier() == book) && newTitle.equals(notification.getNewValue())) {
+
+ trace("Adding external data trigger command");
+
+ IUndoableOperation oper = new ExternalDataOperation(externalData, newExternalData);
+
result = new EMFOperationCommand(domain, oper);
}
-
+
return result;
- }});
-
+ }
+ });
+
try {
history.addOperationHistoryListener(new ContextAdder(ctx));
getCommandStack().execute(cmd, null);
} catch (Exception e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were applied
assertSame(newTitle, book.getTitle());
assertEquals(newExternalData, externalData[0]);
-
+
commit();
try {
@@ -202,161 +188,157 @@ protected Command trigger(TransactionalEditingDomain domain, Notification notifi
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were undone
assertSame(oldTitle, book.getTitle());
assertEquals(oldExternalData, externalData[0]);
-
+
commit();
-
+
try {
assertTrue(history.canRedo(ctx));
history.redo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were redone
assertSame(newTitle, book.getTitle());
assertEquals(newExternalData, externalData[0]);
-
+
commit();
}
-
+
/**
- * Tests rollback of operations wrapped in commands as pre-commit triggers
- * when the transactions that include the triggers roll back.
+ * Tests rollback of operations wrapped in commands as pre-commit triggers when
+ * the transactions that include the triggers roll back.
*/
+ @Test
public void test_rollback_trigger() {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
final String oldTitle = book.getTitle();
-
- final String[] externalData = new String[] {"external"}; //$NON-NLS-1$
+
+ final String[] externalData = new String[] { "external" };
final String oldExternalData = externalData[0];
- final String newExternalData = "newValue"; //$NON-NLS-1$
-
+ final String newExternalData = "newValue";
+
commit();
-
+
IUndoContext ctx = new TestUndoContext();
-
- Command cmd = new SetCommand(
- domain,
- book,
- EXTLibraryPackage.eINSTANCE.getBook_Title(),
- null); // books must have titles
-
+
+ Command cmd = new SetCommand(domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), null); // books must
+ // have titles
+
domain.addResourceSetListener(new TriggerListener() {
-
+
@Override
protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
Command result = null;
-
- if ((notification.getNotifier() == book)
- && (notification.getNewValue() == null)) {
-
- trace("Adding external data trigger command"); //$NON-NLS-1$
-
- IUndoableOperation oper = new ExternalDataOperation(
- externalData,
- newExternalData);
-
+
+ if ((notification.getNotifier() == book) && (notification.getNewValue() == null)) {
+
+ trace("Adding external data trigger command");
+
+ IUndoableOperation oper = new ExternalDataOperation(externalData, newExternalData);
+
result = new EMFOperationCommand(domain, oper);
}
-
+
return result;
- }});
-
+ }
+ });
+
try {
history.addOperationHistoryListener(new ContextAdder(ctx));
getCommandStack().execute(cmd, null);
-
- fail("Should have thrown RollbackException"); //$NON-NLS-1$
+
+ Assertions.fail("Should have thrown RollbackException");
} catch (RollbackException e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
} catch (Exception e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were not applied
assertSame(oldTitle, book.getTitle());
assertEquals(oldExternalData, externalData[0]);
-
+
commit();
}
-
+
/**
* Tests execution, undo, and redo of operations wrapped in commands as
- * pre-commit triggers in a {@link RecordingCommand} context (where
- * undo/redo of triggers is different from other commands).
+ * pre-commit triggers in a {@link RecordingCommand} context (where undo/redo of
+ * triggers is different from other commands).
*/
+ @Test
public void test_execute_undo_redo_trigger_recordingCommand() {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
final String oldTitle = book.getTitle();
-
- final String[] externalData = new String[] {"external"}; //$NON-NLS-1$
+
+ final String[] externalData = new String[] { "external" };
final String oldExternalData = externalData[0];
- final String newExternalData = "newValue"; //$NON-NLS-1$
-
- final String newTitle = "New Title"; //$NON-NLS-1$
-
+ final String newExternalData = "newValue";
+
+ final String newTitle = "New Title";
+
commit();
-
+
IUndoContext ctx = new TestUndoContext();
-
- Command cmd = new RecordingCommand(domain, "Testing") { //$NON-NLS-1$
-
+
+ Command cmd = new RecordingCommand(domain, "Testing") {
+
@Override
protected void doExecute() {
book.setTitle(newTitle);
- }};
-
+ }
+ };
+
domain.addResourceSetListener(new TriggerListener() {
-
+
@Override
protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
Command result = null;
-
- if ((notification.getNotifier() == book)
- && newTitle.equals(notification.getNewValue())) {
-
- trace("Adding external data trigger command"); //$NON-NLS-1$
-
- IUndoableOperation oper = new ExternalDataOperation(
- externalData,
- newExternalData);
-
+
+ if ((notification.getNotifier() == book) && newTitle.equals(notification.getNewValue())) {
+
+ trace("Adding external data trigger command");
+
+ IUndoableOperation oper = new ExternalDataOperation(externalData, newExternalData);
+
result = new EMFOperationCommand(domain, oper);
}
-
+
return result;
- }});
-
+ }
+ });
+
try {
history.addOperationHistoryListener(new ContextAdder(ctx));
getCommandStack().execute(cmd, null);
} catch (Exception e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were applied
assertSame(newTitle, book.getTitle());
assertEquals(newExternalData, externalData[0]);
-
+
commit();
try {
@@ -365,60 +347,63 @@ protected Command trigger(TransactionalEditingDomain domain, Notification notifi
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were undone
assertSame(oldTitle, book.getTitle());
assertEquals(oldExternalData, externalData[0]);
-
+
commit();
-
+
try {
assertTrue(history.canRedo(ctx));
history.redo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were redone
assertSame(newTitle, book.getTitle());
assertEquals(newExternalData, externalData[0]);
-
+
commit();
}
-
+
/**
* Tests that the EMFOperationCommand tests its wrapped operation for
* redoability.
*/
+ @Test
public void test_nonredoableOperation_138287() {
IUndoableOperation operation = new TestOperation(domain) {
@Override
protected void doExecute() {
// nothing to do
}
-
+
@Override
public boolean canRedo() {
return false;
- }};
-
+ }
+ };
+
getCommandStack().execute(new EMFOperationCommand(domain, operation));
-
+
assertTrue(getCommandStack().canUndo());
-
+
getCommandStack().undo();
-
+
assertFalse(getCommandStack().canRedo());
}
/**
- * Tests that the EMFOperationCommand tests its wrapped operation for
- * multiple disposability.
+ * Tests that the EMFOperationCommand tests its wrapped operation for multiple
+ * disposability.
*/
+ @Test
public void test_multipleDisposableOperation_209491() {
IUndoableOperation operation = new TestOperation(domain) {
@@ -430,7 +415,8 @@ protected void doExecute() {
@Override
public boolean canRedo() {
return false;
- }};
+ }
+ };
EMFOperationCommand operationCommand = new EMFOperationCommand(domain, operation);
getCommandStack().execute(operationCommand);
@@ -439,11 +425,11 @@ public boolean canRedo() {
Exception exception;
try {
- // Confirm that the operation has been nulled by testing that this throws a null pointer exception.
+ // Confirm that the operation has been nulled by testing that this throws a null
+ // pointer exception.
operationCommand.canExecute();
exception = null;
- }
- catch (NullPointerException nullPointerException) {
+ } catch (NullPointerException nullPointerException) {
exception = nullPointerException;
}
assertNotNull(exception);
@@ -452,291 +438,288 @@ public boolean canRedo() {
// This should not throw a null pointer exception.
operationCommand.dispose();
exception = null;
- }
- catch (NullPointerException nullPointerException) {
+ } catch (NullPointerException nullPointerException) {
exception = nullPointerException;
}
assertNull(exception);
}
-
+
/**
- * Tests that failure of an EMFOperationCommand used as a trigger will
- * roll back a transaction.
+ * Tests that failure of an EMFOperationCommand used as a trigger will roll back
+ * a transaction.
*/
+ @Test
public void test_operationTriggerFails_234868() {
final TestOperation trigger = new TestOperation(domain) {
-
+
@Override
- protected void doExecute()
- throws ExecutionException {
-
- throw new ExecutionException("I should fail"); //$NON-NLS-1$
- }};
-
+ protected void doExecute() throws ExecutionException {
+
+ throw new ExecutionException("I should fail");
+ }
+ };
+
TriggerListener listener = new TriggerListener() {
-
+
@Override
- protected Command trigger(TransactionalEditingDomain domain,
- Notification notification) {
+ protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
return new EMFOperationCommand(domain, trigger);
- }};
-
+ }
+ };
+
try {
domain.addResourceSetListener(listener);
-
+
startWriting();
- Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+ Book book = (Book) find("root/Root Book");
book.setCopies(book.getCopies() + 30);
- commitWithRollback(); // should roll back due to trigger
-
- fail("Should have rolled back."); //$NON-NLS-1$
+ commitWithRollback(); // should roll back due to trigger
+
+ Assertions.fail("Should have rolled back.");
} catch (RollbackException rbe) {
// success
- System.out.println("Got expected exception: " + rbe.getLocalizedMessage()); //$NON-NLS-1$
+ System.out.println("Got expected exception: " + rbe.getLocalizedMessage());
} finally {
domain.removeResourceSetListener(listener);
}
}
-
+
/**
- * Tests that execution of an EMFOperationCommand used as a trigger will
- * roll back a transaction when the operation status is an ERROR.
+ * Tests that execution of an EMFOperationCommand used as a trigger will roll
+ * back a transaction when the operation status is an ERROR.
*/
+ @Test
public void test_operationTriggerErrorStatus_234868() {
final TestOperation trigger = new TestOperation(domain) {
-
+
@Override
protected void doExecute() {
-
- setStatus(new Status(IStatus.ERROR,
- "org.eclipse.emf.workspace.tests", "I should fail")); //$NON-NLS-1$ //$NON-NLS-2$
- }};
-
+
+ setStatus(new Status(IStatus.ERROR, "org.eclipse.emf.workspace.tests", "I should fail")); //$NON-NLS-2$
+ }
+ };
+
TriggerListener listener = new TriggerListener() {
-
+
@Override
- protected Command trigger(TransactionalEditingDomain domain,
- Notification notification) {
+ protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
return new EMFOperationCommand(domain, trigger);
- }};
-
+ }
+ };
+
try {
domain.addResourceSetListener(listener);
-
+
startWriting();
- Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+ Book book = (Book) find("root/Root Book");
book.setCopies(book.getCopies() + 30);
- commitWithRollback(); // should roll back due to trigger
-
- fail("Should have rolled back."); //$NON-NLS-1$
+ commitWithRollback(); // should roll back due to trigger
+
+ Assertions.fail("Should have rolled back.");
} catch (RollbackException rbe) {
// success
- System.out.println("Got expected exception: " + rbe.getLocalizedMessage()); //$NON-NLS-1$
+ System.out.println("Got expected exception: " + rbe.getLocalizedMessage());
} finally {
domain.removeResourceSetListener(listener);
}
}
-
+
/**
- * Tests that execution of a non-EMF operation used as a trigger will
- * roll back a transaction when the operation status is a ERROR.
+ * Tests that execution of a non-EMF operation used as a trigger will roll back
+ * a transaction when the operation status is a ERROR.
*/
+ @Test
public void test_operationTriggerErrorStatus_nonEMF_234868() {
- final IUndoableOperation trigger = new AbstractOperation("Non-EMF Changes") { //$NON-NLS-1$
-
+ final IUndoableOperation trigger = new AbstractOperation("Non-EMF Changes") {
+
@Override
- public IStatus execute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
- return new Status(IStatus.ERROR,
- "org.eclipse.emf.workspace.tests", "I should fail"); //$NON-NLS-1$ //$NON-NLS-2$
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ return new Status(IStatus.ERROR, "org.eclipse.emf.workspace.tests", "I should fail"); //$NON-NLS-2$
}
-
+
@Override
- public IStatus undo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
-
+
@Override
- public IStatus redo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
- }};
-
+ }
+ };
+
TriggerListener listener = new TriggerListener() {
-
+
@Override
- protected Command trigger(TransactionalEditingDomain domain,
- Notification notification) {
+ protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
return new EMFOperationCommand(domain, trigger);
- }};
-
+ }
+ };
+
try {
domain.addResourceSetListener(listener);
-
+
startWriting();
- Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+ Book book = (Book) find("root/Root Book");
book.setCopies(book.getCopies() + 30);
- commitWithRollback(); // should roll back due to trigger
-
- fail("Should have rolled back."); //$NON-NLS-1$
+ commitWithRollback(); // should roll back due to trigger
+
+ Assertions.fail("Should have rolled back.");
} catch (RollbackException rbe) {
// success
- System.out.println("Got expected exception: " + rbe.getLocalizedMessage()); //$NON-NLS-1$
+ System.out.println("Got expected exception: " + rbe.getLocalizedMessage());
} finally {
domain.removeResourceSetListener(listener);
}
}
-
+
/**
- * Tests that undo of a non-EMF operation used as a trigger will
- * roll back a transaction when the operation status is a ERROR.
+ * Tests that undo of a non-EMF operation used as a trigger will roll back a
+ * transaction when the operation status is a ERROR.
*/
+ @Test
public void test_operationTriggerErrorStatus_nonEMF_undo_234868() {
- final IUndoableOperation trigger = new AbstractOperation("Non-EMF Changes") { //$NON-NLS-1$
-
+ final IUndoableOperation trigger = new AbstractOperation("Non-EMF Changes") {
+
@Override
- public IStatus execute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
-
+
@Override
- public IStatus undo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
- return new Status(IStatus.ERROR,
- "org.eclipse.emf.workspace.tests", "I should fail"); //$NON-NLS-1$ //$NON-NLS-2$
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ return new Status(IStatus.ERROR, "org.eclipse.emf.workspace.tests", "I should fail"); //$NON-NLS-2$
}
-
+
@Override
- public IStatus redo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
- }};
-
+ }
+ };
+
TriggerListener listener = new TriggerListener() {
-
+
@Override
- protected Command trigger(TransactionalEditingDomain domain,
- Notification notification) {
+ protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
return new EMFOperationCommand(domain, trigger);
- }};
-
+ }
+ };
+
try {
domain.addResourceSetListener(listener);
-
+
IUndoableOperation op = new TestOperation(domain) {
+ @Override
protected void doExecute() throws ExecutionException {
- Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+ Book book = (Book) find("root/Root Book");
book.setCopies(book.getCopies() + 30);
- }};
-
+ }
+ };
+
try {
op.execute(null, null);
} catch (ExecutionException e) {
- fail("Should not fail to execute: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assertions.fail("Should not fail to execute: " + e.getLocalizedMessage());
}
-
+
try {
op.undo(null, null);
- fail("Should have failed to undo."); //$NON-NLS-1$
+ Assertions.fail("Should have failed to undo.");
} catch (ExecutionException e) {
// success
- System.out.println("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ System.out.println("Got expected exception: " + e.getLocalizedMessage());
}
} finally {
domain.removeResourceSetListener(listener);
}
}
-
+
/**
- * Tests that redo of a non-EMF operation used as a trigger will
- * roll back a transaction when the operation status is a ERROR.
+ * Tests that redo of a non-EMF operation used as a trigger will roll back a
+ * transaction when the operation status is a ERROR.
*/
+ @Test
public void test_operationTriggerErrorStatus_nonEMF_redo_234868() {
- final IUndoableOperation trigger = new AbstractOperation("Non-EMF Changes") { //$NON-NLS-1$
-
+ final IUndoableOperation trigger = new AbstractOperation("Non-EMF Changes") {
+
@Override
- public IStatus execute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
-
+
@Override
- public IStatus undo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
-
+
@Override
- public IStatus redo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
- return new Status(IStatus.ERROR,
- "org.eclipse.emf.workspace.tests", "I should fail"); //$NON-NLS-1$ //$NON-NLS-2$
- }};
-
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ return new Status(IStatus.ERROR, "org.eclipse.emf.workspace.tests", "I should fail"); //$NON-NLS-2$
+ }
+ };
+
TriggerListener listener = new TriggerListener() {
-
+
@Override
- protected Command trigger(TransactionalEditingDomain domain,
- Notification notification) {
+ protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
return new EMFOperationCommand(domain, trigger);
- }};
-
+ }
+ };
+
try {
domain.addResourceSetListener(listener);
-
+
IUndoableOperation op = new TestOperation(domain) {
+ @Override
protected void doExecute() throws ExecutionException {
- Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+ Book book = (Book) find("root/Root Book");
book.setCopies(book.getCopies() + 30);
- }};
-
+ }
+ };
+
try {
op.execute(null, null);
} catch (ExecutionException e) {
- fail("Should not fail to execute: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assertions.fail("Should not fail to execute: " + e.getLocalizedMessage());
}
-
+
try {
op.undo(null, null);
} catch (ExecutionException e) {
- fail("Should not fail to undo: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assertions.fail("Should not fail to undo: " + e.getLocalizedMessage());
}
-
+
try {
op.redo(null, null);
- fail("Should have failed to redo."); //$NON-NLS-1$
+ Assertions.fail("Should have failed to redo.");
} catch (ExecutionException e) {
// success
- System.out.println("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ System.out.println("Got expected exception: " + e.getLocalizedMessage());
}
} finally {
domain.removeResourceSetListener(listener);
}
}
-
+
//
// Test fixtures
//
-
+
@Override
- protected void doSetUp()
- throws Exception {
-
+ protected void doSetUp() throws Exception {
+
super.doSetUp();
-
+
// enable validation
validationEnabled = true;
}
-
+
@Override
- protected void doTearDown()
- throws Exception {
-
+ protected void doTearDown() throws Exception {
+
// disable validation
validationEnabled = false;
-
+
super.doTearDown();
}
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/MemoryLeakTest.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/MemoryLeakTest.java
index 385d1279..1a62eb7c 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/MemoryLeakTest.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/MemoryLeakTest.java
@@ -11,12 +11,13 @@
*/
package org.eclipse.emf.workspace.tests;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.util.Iterator;
import java.util.List;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.commands.operations.IUndoableOperation;
@@ -45,7 +46,8 @@
import org.eclipse.emf.workspace.AbstractEMFOperation;
import org.eclipse.emf.workspace.EMFOperationCommand;
import org.eclipse.emf.workspace.ResourceUndoContext;
-
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests to check for memory leaks.
@@ -54,570 +56,577 @@
*/
public class MemoryLeakTest extends AbstractTest {
- public MemoryLeakTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(MemoryLeakTest.class, "Memory Leak (GC) Tests"); //$NON-NLS-1$
- }
-
- /**
- *
- * Tests that the change descriptions that recorded execution, undo, and
- * redo of the removal of an element that has an ECrossReferenceAdapter
- * attached do not leak that adapter after the command stack has been
- * flushed.
- *
- * This is a control test, using a normal EMF RemoveCommand
- * that has been instrumented to clear the adapters of the removed
- * element(s) upon disposal.
- *
- * This test exercises the workspace command stack, not the operation
- * history directly.
- *
- */
- public void test_crossReferenceAdapter_undoredo_normalCommands() {
- // attach a cross-reference adapter to the resource set
- ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
- domain.getResourceSet().eAdapters().add(xrefAdapter);
-
- // and a transaction-sniffer to the domain
- TransactionSniffer sniffer = new TransactionSniffer(domain);
-
- EObject level1 = find(root, "level1"); //$NON-NLS-1$
-
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- Command cmd = new RemoveCommand(domain, root, EXTLibraryPackage.Literals.LIBRARY__BRANCHES, level1) {
- @Override
+ /**
+ *
+ * Tests that the change descriptions that recorded execution, undo, and redo of
+ * the removal of an element that has an ECrossReferenceAdapter attached do not
+ * leak that adapter after the command stack has been flushed.
+ *
+ *
+ * This is a control test, using a normal EMF RemoveCommand that
+ * has been instrumented to clear the adapters of the removed element(s) upon
+ * disposal.
+ *
+ *
+ * This test exercises the workspace command stack, not the operation history
+ * directly.
+ *
+ */
+ @Test
+ public void test_crossReferenceAdapter_undoredo_normalCommands() {
+ // attach a cross-reference adapter to the resource set
+ ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
+ domain.getResourceSet().eAdapters().add(xrefAdapter);
+
+ // and a transaction-sniffer to the domain
+ TransactionSniffer sniffer = new TransactionSniffer(domain);
+
+ EObject level1 = find(root, "level1");
+
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ Command cmd = new RemoveCommand(domain, root, EXTLibraryPackage.Literals.LIBRARY__BRANCHES, level1) {
+ @Override
public void doDispose() {
- if (feature instanceof EReference && ((EReference) feature).isContainment()) {
- for (Object o : collection) {
- EObject next = (EObject) o;
-
- // clear adapters on the removed object if it is still removed
- if (next.eContainer() != owner) {
- next.eAdapters().clear();
- }
- }
- }
-
- super.doDispose();
- }};
-
- getCommandStack().execute(cmd);
-
- // remove the resource undo context so that flush will dispose
- ResourceUndoContext resctx = new ResourceUndoContext(domain, testResource);
- history.getUndoOperation(resctx).removeContext(resctx);
-
- // the adapter is still attached, of course
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- // undo/redo should not change the adapter attachment
- getCommandStack().undo();
- getCommandStack().redo();
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- // flushing the command-stack should dispose the command, which should
- // remove adapters
- getCommandStack().flush();
- assertFalse(level1.eAdapters().contains(xrefAdapter));
-
- // and the change descriptions are clean
- sniffer.assertChangesDisposed();
- }
-
- /**
- *
- * Tests that the change descriptions that recorded execution, undo, and
- * redo of the removal of an element that has an ECrossReferenceAdapter
- * attached do not leak that adapter after the command stack has been
- * flushed. This tests the disposal of RecordingCommands,
- * that it clears the adapters of the change description and its contents.
- *
- * This test exercises the workspace command stack, not the operation
- * history directly.
- *
- */
- public void test_crossReferenceAdapter_undoredo_recordingCommands() {
- // attach a cross-reference adapter to the resource set
- ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
- domain.getResourceSet().eAdapters().add(xrefAdapter);
-
- // and a transaction-sniffer to the domain
- TransactionSniffer sniffer = new TransactionSniffer(domain);
-
- final EObject level1 = find(root, "level1"); //$NON-NLS-1$
-
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- Command cmd = new RecordingCommand(domain, "Remove Branch") { //$NON-NLS-1$
- @Override
+ if (feature instanceof EReference && ((EReference) feature).isContainment()) {
+ for (Object o : collection) {
+ EObject next = (EObject) o;
+
+ // clear adapters on the removed object if it is still removed
+ if (next.eContainer() != owner) {
+ next.eAdapters().clear();
+ }
+ }
+ }
+
+ super.doDispose();
+ }
+ };
+
+ getCommandStack().execute(cmd);
+
+ // remove the resource undo context so that flush will dispose
+ ResourceUndoContext resctx = new ResourceUndoContext(domain, testResource);
+ history.getUndoOperation(resctx).removeContext(resctx);
+
+ // the adapter is still attached, of course
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ // undo/redo should not change the adapter attachment
+ getCommandStack().undo();
+ getCommandStack().redo();
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ // flushing the command-stack should dispose the command, which should
+ // remove adapters
+ getCommandStack().flush();
+ assertFalse(level1.eAdapters().contains(xrefAdapter));
+
+ // and the change descriptions are clean
+ sniffer.assertChangesDisposed();
+ }
+
+ /**
+ *
+ * Tests that the change descriptions that recorded execution, undo, and redo of
+ * the removal of an element that has an ECrossReferenceAdapter attached do not
+ * leak that adapter after the command stack has been flushed. This tests the
+ * disposal of RecordingCommands, that it clears the adapters of
+ * the change description and its contents.
+ *
+ *
+ * This test exercises the workspace command stack, not the operation history
+ * directly.
+ *
+ */
+ @Test
+ public void test_crossReferenceAdapter_undoredo_recordingCommands() {
+ // attach a cross-reference adapter to the resource set
+ ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
+ domain.getResourceSet().eAdapters().add(xrefAdapter);
+
+ // and a transaction-sniffer to the domain
+ TransactionSniffer sniffer = new TransactionSniffer(domain);
+
+ final EObject level1 = find(root, "level1");
+
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ Command cmd = new RecordingCommand(domain, "Remove Branch") {
+ @Override
protected void doExecute() {
- root.getBranches().remove(level1);
- }};
-
- getCommandStack().execute(cmd);
-
- // remove the resource undo context so that flush will dispose
- ResourceUndoContext resctx = new ResourceUndoContext(domain, testResource);
- history.getUndoOperation(resctx).removeContext(resctx);
-
- // the adapter is still attached, of course
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- // undo/redo should not change the adapter attachment
- getCommandStack().undo();
- getCommandStack().redo();
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- // flushing the command-stack should dispose the command, which should
- // remove adapters from the change description and its contents
- getCommandStack().flush();
- assertFalse(level1.eAdapters().contains(xrefAdapter));
-
- // and the change descriptions are clean
- sniffer.assertChangesDisposed();
- }
-
- /**
- *
- * Tests that the change descriptions that recorded execution, undo, and
- * redo of a trigger command that removes an element that has an
- * ECrossReferenceAdapter attached do not leak that adapter after the
- * command stack has been flushed.
- *
- * This is a control test, using a normal EMF RemoveCommand
- * that has been instrumented to clear the adapters of the removed
- * element(s) upon disposal.
- *
- * This test exercises the workspace command stack, not the operation
- * history directly.
- *
- */
- public void test_crossReferenceAdapter_undoredo_normalTriggerCommands() {
- // attach a cross-reference adapter to the resource set
- ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
- domain.getResourceSet().eAdapters().add(xrefAdapter);
-
- // and a transaction-sniffer to the domain
- TransactionSniffer sniffer = new TransactionSniffer(domain);
-
- EObject level1 = find(root, "level1"); //$NON-NLS-1$
-
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- final Command trigger = new RemoveCommand(domain, root, EXTLibraryPackage.Literals.LIBRARY__BRANCHES, level1) {
- @Override
+ root.getBranches().remove(level1);
+ }
+ };
+
+ getCommandStack().execute(cmd);
+
+ // remove the resource undo context so that flush will dispose
+ ResourceUndoContext resctx = new ResourceUndoContext(domain, testResource);
+ history.getUndoOperation(resctx).removeContext(resctx);
+
+ // the adapter is still attached, of course
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ // undo/redo should not change the adapter attachment
+ getCommandStack().undo();
+ getCommandStack().redo();
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ // flushing the command-stack should dispose the command, which should
+ // remove adapters from the change description and its contents
+ getCommandStack().flush();
+ assertFalse(level1.eAdapters().contains(xrefAdapter));
+
+ // and the change descriptions are clean
+ sniffer.assertChangesDisposed();
+ }
+
+ /**
+ *
+ * Tests that the change descriptions that recorded execution, undo, and redo of
+ * a trigger command that removes an element that has an
+ * ECrossReferenceAdapter attached do not leak that adapter after the command
+ * stack has been flushed.
+ *
+ *
+ * This is a control test, using a normal EMF RemoveCommand that
+ * has been instrumented to clear the adapters of the removed element(s) upon
+ * disposal.
+ *
+ *
+ * This test exercises the workspace command stack, not the operation history
+ * directly.
+ *
+ */
+ @Test
+ public void test_crossReferenceAdapter_undoredo_normalTriggerCommands() {
+ // attach a cross-reference adapter to the resource set
+ ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
+ domain.getResourceSet().eAdapters().add(xrefAdapter);
+
+ // and a transaction-sniffer to the domain
+ TransactionSniffer sniffer = new TransactionSniffer(domain);
+
+ EObject level1 = find(root, "level1");
+
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ final Command trigger = new RemoveCommand(domain, root, EXTLibraryPackage.Literals.LIBRARY__BRANCHES, level1) {
+ @Override
public void doDispose() {
- if (feature instanceof EReference && ((EReference) feature).isContainment()) {
- for (Object o : collection) {
- EObject next = (EObject) o;
-
- // clear adapters on the removed object if it is still removed
- if (next.eContainer() != owner) {
- next.eAdapters().clear();
- }
- }
- }
-
- super.doDispose();
- }};
-
- domain.addResourceSetListener(new TriggerListener() {
- @Override
- protected Command trigger(TransactionalEditingDomain domain,
- Notification notification) {
- // trigger on the name change only
- if (notification.getFeature() == EXTLibraryPackage.Literals.LIBRARY__NAME) {
- return trigger;
- }
-
- return null;
- }});
-
- Command cmd = domain.createCommand(SetCommand.class,
- new CommandParameter(root, EXTLibraryPackage.Literals.LIBRARY__NAME, "newname")); //$NON-NLS-1$
-
- getCommandStack().execute(cmd);
-
- // remove the resource undo context so that flush will dispose
- ResourceUndoContext resctx = new ResourceUndoContext(domain, testResource);
- history.getUndoOperation(resctx).removeContext(resctx);
-
- // the adapter is still attached, of course
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- // undo/redo should not change the adapter attachment
- getCommandStack().undo();
- getCommandStack().redo();
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- // flushing the command-stack should dispose the command, which should
- // remove adapters
- getCommandStack().flush();
- assertFalse(level1.eAdapters().contains(xrefAdapter));
-
- // and the change descriptions are clean
- sniffer.assertChangesDisposed();
- }
-
- /**
- *
- * Tests that the change descriptions that recorded execution, undo, and
- * redo of a trigger command that removes an element that has an
- * ECrossReferenceAdapter attached do not leak that adapter after the
- * command stack has been flushed. This tests the disposal of
- * RecordingCommands, that it clears the adapters of the
- * change description and its contents.
- *
- * This test exercises the workspace command stack, not the operation
- * history directly.
- *
- */
- public void test_crossReferenceAdapter_undoredo_recordingTriggerCommands() {
- // attach a cross-reference adapter to the resource set
- ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
- domain.getResourceSet().eAdapters().add(xrefAdapter);
-
- // and a transaction-sniffer to the domain
- TransactionSniffer sniffer = new TransactionSniffer(domain);
-
- final EObject level1 = find(root, "level1"); //$NON-NLS-1$
-
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- final Command trigger = new RecordingCommand(domain, "Remove Branch") { //$NON-NLS-1$
- @Override
+ if (feature instanceof EReference && ((EReference) feature).isContainment()) {
+ for (Object o : collection) {
+ EObject next = (EObject) o;
+
+ // clear adapters on the removed object if it is still removed
+ if (next.eContainer() != owner) {
+ next.eAdapters().clear();
+ }
+ }
+ }
+
+ super.doDispose();
+ }
+ };
+
+ domain.addResourceSetListener(new TriggerListener() {
+ @Override
+ protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
+ // trigger on the name change only
+ if (notification.getFeature() == EXTLibraryPackage.Literals.LIBRARY__NAME) {
+ return trigger;
+ }
+
+ return null;
+ }
+ });
+
+ Command cmd = domain.createCommand(SetCommand.class,
+ new CommandParameter(root, EXTLibraryPackage.Literals.LIBRARY__NAME, "newname"));
+
+ getCommandStack().execute(cmd);
+
+ // remove the resource undo context so that flush will dispose
+ ResourceUndoContext resctx = new ResourceUndoContext(domain, testResource);
+ history.getUndoOperation(resctx).removeContext(resctx);
+
+ // the adapter is still attached, of course
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ // undo/redo should not change the adapter attachment
+ getCommandStack().undo();
+ getCommandStack().redo();
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ // flushing the command-stack should dispose the command, which should
+ // remove adapters
+ getCommandStack().flush();
+ assertFalse(level1.eAdapters().contains(xrefAdapter));
+
+ // and the change descriptions are clean
+ sniffer.assertChangesDisposed();
+ }
+
+ /**
+ *
+ * Tests that the change descriptions that recorded execution, undo, and redo of
+ * a trigger command that removes an element that has an
+ * ECrossReferenceAdapter attached do not leak that adapter after the command
+ * stack has been flushed. This tests the disposal of
+ * RecordingCommands, that it clears the adapters of the change
+ * description and its contents.
+ *
+ *
+ * This test exercises the workspace command stack, not the operation history
+ * directly.
+ *
+ */
+ @Test
+ public void test_crossReferenceAdapter_undoredo_recordingTriggerCommands() {
+ // attach a cross-reference adapter to the resource set
+ ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
+ domain.getResourceSet().eAdapters().add(xrefAdapter);
+
+ // and a transaction-sniffer to the domain
+ TransactionSniffer sniffer = new TransactionSniffer(domain);
+
+ final EObject level1 = find(root, "level1");
+
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ final Command trigger = new RecordingCommand(domain, "Remove Branch") {
+ @Override
protected void doExecute() {
- root.getBranches().remove(level1);
- }};
-
- domain.addResourceSetListener(new TriggerListener() {
- @Override
- protected Command trigger(TransactionalEditingDomain domain,
- Notification notification) {
- // trigger on the name change only
- if (notification.getFeature() == EXTLibraryPackage.Literals.LIBRARY__NAME) {
- return trigger;
- }
-
- return null;
- }});
-
- Command cmd = domain.createCommand(SetCommand.class,
- new CommandParameter(root, EXTLibraryPackage.Literals.LIBRARY__NAME, "newname")); //$NON-NLS-1$
-
- getCommandStack().execute(cmd);
-
- // remove the resource undo context so that flush will dispose
- ResourceUndoContext resctx = new ResourceUndoContext(domain, testResource);
- history.getUndoOperation(resctx).removeContext(resctx);
-
- // the adapter is still attached, of course
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- // undo/redo should not change the adapter attachment
- getCommandStack().undo();
- getCommandStack().redo();
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- // flushing the command-stack should dispose the command, which should
- // remove adapters
- getCommandStack().flush();
- assertFalse(level1.eAdapters().contains(xrefAdapter));
-
- // and the change descriptions are clean
- sniffer.assertChangesDisposed();
- }
-
- /**
- *
- * Tests that the change descriptions that recorded execution, undo, and
- * redo of the removal of an element that has an ECrossReferenceAdapter
- * attached do not leak that adapter after the operation history has been
- * flushed.
- *
- */
- public void test_crossReferenceAdapter_undoredo_operations() {
- // attach a cross-reference adapter to the resource set
- ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
- domain.getResourceSet().eAdapters().add(xrefAdapter);
-
- // and a transaction-sniffer to the domain
- TransactionSniffer sniffer = new TransactionSniffer(domain);
-
- final EObject level1 = find(root, "level1"); //$NON-NLS-1$
-
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- IUndoableOperation oper = new AbstractEMFOperation(domain, "Remove Branch") { //$NON-NLS-1$
- @Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
- root.getBranches().remove(level1);
-
- return Status.OK_STATUS;
- }};
-
- IUndoContext ctx = new UndoContext();
- oper.addContext(ctx);
-
- try {
- history.execute(oper, null, null);
- } catch (ExecutionException e) {
- fail("Failed to execute operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
-
- // remove the resource undo context so that flush will dispose
- ResourceUndoContext resctx = new ResourceUndoContext(domain, testResource);
- history.getUndoOperation(resctx).removeContext(resctx);
-
- // the adapter is still attached, of course
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- // undo/redo should not change the adapter attachment
- try {
- history.undo(ctx, null, null);
- } catch (ExecutionException e) {
- fail("Failed to undo operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
- try {
- history.redo(ctx, null, null);
- } catch (ExecutionException e) {
- fail("Failed to redo operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- // flushing the context should dispose the operation, which should
- // remove adapters from the change description and its contents
- history.dispose(ctx, true, true, true);
- assertFalse(level1.eAdapters().contains(xrefAdapter));
-
- // and the change descriptions are clean
- sniffer.assertChangesDisposed();
- }
-
- /**
- *
- * Tests that the change descriptions that recorded execution, undo, and
- * redo of a trigger command that removes an element that has an
- * ECrossReferenceAdapter attached do not leak that adapter after the
- * operation history has been flushed. This tests the disposal of
- * RecordingCommands, that it clears the adapters of the
- * change description and its contents.
- *
- */
- public void test_crossReferenceAdapter_undoredo_operationTriggerCommands() {
- // attach a cross-reference adapter to the resource set
- ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
- domain.getResourceSet().eAdapters().add(xrefAdapter);
-
- // and a transaction-sniffer to the domain
- TransactionSniffer sniffer = new TransactionSniffer(domain);
-
- final EObject level1 = find(root, "level1"); //$NON-NLS-1$
-
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- final Command trigger = new RecordingCommand(domain, "Remove Branch") { //$NON-NLS-1$
- @Override
+ root.getBranches().remove(level1);
+ }
+ };
+
+ domain.addResourceSetListener(new TriggerListener() {
+ @Override
+ protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
+ // trigger on the name change only
+ if (notification.getFeature() == EXTLibraryPackage.Literals.LIBRARY__NAME) {
+ return trigger;
+ }
+
+ return null;
+ }
+ });
+
+ Command cmd = domain.createCommand(SetCommand.class,
+ new CommandParameter(root, EXTLibraryPackage.Literals.LIBRARY__NAME, "newname"));
+
+ getCommandStack().execute(cmd);
+
+ // remove the resource undo context so that flush will dispose
+ ResourceUndoContext resctx = new ResourceUndoContext(domain, testResource);
+ history.getUndoOperation(resctx).removeContext(resctx);
+
+ // the adapter is still attached, of course
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ // undo/redo should not change the adapter attachment
+ getCommandStack().undo();
+ getCommandStack().redo();
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ // flushing the command-stack should dispose the command, which should
+ // remove adapters
+ getCommandStack().flush();
+ assertFalse(level1.eAdapters().contains(xrefAdapter));
+
+ // and the change descriptions are clean
+ sniffer.assertChangesDisposed();
+ }
+
+ /**
+ *
+ * Tests that the change descriptions that recorded execution, undo, and redo of
+ * the removal of an element that has an ECrossReferenceAdapter attached do not
+ * leak that adapter after the operation history has been flushed.
+ *
+ */
+ @Test
+ public void test_crossReferenceAdapter_undoredo_operations() {
+ // attach a cross-reference adapter to the resource set
+ ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
+ domain.getResourceSet().eAdapters().add(xrefAdapter);
+
+ // and a transaction-sniffer to the domain
+ TransactionSniffer sniffer = new TransactionSniffer(domain);
+
+ final EObject level1 = find(root, "level1");
+
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ IUndoableOperation oper = new AbstractEMFOperation(domain, "Remove Branch") {
+ @Override
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ root.getBranches().remove(level1);
+
+ return Status.OK_STATUS;
+ }
+ };
+
+ IUndoContext ctx = new UndoContext();
+ oper.addContext(ctx);
+
+ try {
+ history.execute(oper, null, null);
+ } catch (ExecutionException e) {
+ Assertions.fail("Failed to execute operation: " + e.getLocalizedMessage());
+ }
+
+ // remove the resource undo context so that flush will dispose
+ ResourceUndoContext resctx = new ResourceUndoContext(domain, testResource);
+ history.getUndoOperation(resctx).removeContext(resctx);
+
+ // the adapter is still attached, of course
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ // undo/redo should not change the adapter attachment
+ try {
+ history.undo(ctx, null, null);
+ } catch (ExecutionException e) {
+ Assertions.fail("Failed to undo operation: " + e.getLocalizedMessage());
+ }
+ try {
+ history.redo(ctx, null, null);
+ } catch (ExecutionException e) {
+ Assertions.fail("Failed to redo operation: " + e.getLocalizedMessage());
+ }
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ // flushing the context should dispose the operation, which should
+ // remove adapters from the change description and its contents
+ history.dispose(ctx, true, true, true);
+ assertFalse(level1.eAdapters().contains(xrefAdapter));
+
+ // and the change descriptions are clean
+ sniffer.assertChangesDisposed();
+ }
+
+ /**
+ *
+ * Tests that the change descriptions that recorded execution, undo, and redo of
+ * a trigger command that removes an element that has an
+ * ECrossReferenceAdapter attached do not leak that adapter after the operation
+ * history has been flushed. This tests the disposal of
+ * RecordingCommands, that it clears the adapters of the change
+ * description and its contents.
+ *
+ */
+ @Test
+ public void test_crossReferenceAdapter_undoredo_operationTriggerCommands() {
+ // attach a cross-reference adapter to the resource set
+ ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
+ domain.getResourceSet().eAdapters().add(xrefAdapter);
+
+ // and a transaction-sniffer to the domain
+ TransactionSniffer sniffer = new TransactionSniffer(domain);
+
+ final EObject level1 = find(root, "level1");
+
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ final Command trigger = new RecordingCommand(domain, "Remove Branch") {
+ @Override
protected void doExecute() {
- root.getBranches().remove(level1);
- }};
-
- domain.addResourceSetListener(new TriggerListener() {
- @Override
- protected Command trigger(TransactionalEditingDomain domain,
- Notification notification) {
- // trigger on the name change only
- if (notification.getFeature() == EXTLibraryPackage.Literals.LIBRARY__NAME) {
- return trigger;
- }
-
- return null;
- }});
-
- IUndoableOperation oper = new AbstractEMFOperation(domain, "Rename Library") { //$NON-NLS-1$
- @Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
- root.setName("newname"); //$NON-NLS-1$
-
- return Status.OK_STATUS;
- }};
-
- IUndoContext ctx = new UndoContext();
- oper.addContext(ctx);
-
- try {
- history.execute(oper, null, null);
- } catch (ExecutionException e) {
- fail("Failed to execute operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
-
- // remove the resource undo context so that flush will dispose
- ResourceUndoContext resctx = new ResourceUndoContext(domain, testResource);
- history.getUndoOperation(resctx).removeContext(resctx);
-
- // the adapter is still attached, of course
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- // undo/redo should not change the adapter attachment
- try {
- history.undo(ctx, null, null);
- } catch (ExecutionException e) {
- fail("Failed to undo operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
- try {
- history.redo(ctx, null, null);
- } catch (ExecutionException e) {
- fail("Failed to redo operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- // flushing the context should dispose the operation, which should
- // remove adapters from the change description and its contents
- history.dispose(ctx, true, true, true);
- assertFalse(level1.eAdapters().contains(xrefAdapter));
-
- // and the change descriptions are clean
- sniffer.assertChangesDisposed();
- }
-
- /**
- *
- * Tests that the change descriptions that recorded execution, undo, and
- * redo of a trigger operation that removes an element that has an
- * ECrossReferenceAdapter attached do not leak that adapter after the
- * operation history has been flushed. This tests the disposal of
- * RecordingCommands, that it clears the adapters of the
- * change description and its contents.
- *
- */
- public void test_crossReferenceAdapter_undoredo_operationTriggerOperations() {
- // attach a cross-reference adapter to the resource set
- ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
- domain.getResourceSet().eAdapters().add(xrefAdapter);
-
- // and a transaction-sniffer to the domain
- TransactionSniffer sniffer = new TransactionSniffer(domain);
-
- final EObject level1 = find(root, "level1"); //$NON-NLS-1$
-
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- IUndoableOperation triggerOper = new AbstractEMFOperation(domain, "Remove Branch") { //$NON-NLS-1$
- @Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
- root.getBranches().remove(level1);
-
- return Status.OK_STATUS;
- }};
- final Command trigger = new EMFOperationCommand(domain, triggerOper);
-
- domain.addResourceSetListener(new TriggerListener() {
- @Override
- protected Command trigger(TransactionalEditingDomain domain,
- Notification notification) {
- // trigger on the name change only
- if (notification.getFeature() == EXTLibraryPackage.Literals.LIBRARY__NAME) {
- return trigger;
- }
-
- return null;
- }});
-
- IUndoableOperation oper = new AbstractEMFOperation(domain, "Rename Library") { //$NON-NLS-1$
- @Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
- root.setName("newname"); //$NON-NLS-1$
-
- return Status.OK_STATUS;
- }};
-
- IUndoContext ctx = new UndoContext();
- oper.addContext(ctx);
-
- try {
- history.execute(oper, null, null);
- } catch (ExecutionException e) {
- fail("Failed to execute operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
-
- // remove the resource undo context so that flush will dispose
- ResourceUndoContext resctx = new ResourceUndoContext(domain, testResource);
- history.getUndoOperation(resctx).removeContext(resctx);
-
- // the adapter is still attached, of course
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- // undo/redo should not change the adapter attachment
- try {
- history.undo(ctx, null, null);
- } catch (ExecutionException e) {
- fail("Failed to undo operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
- try {
- history.redo(ctx, null, null);
- } catch (ExecutionException e) {
- fail("Failed to redo operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- // flushing the context should dispose the operation, which should
- // remove adapters from the change description and its contents
- history.dispose(ctx, true, true, true);
- assertFalse(level1.eAdapters().contains(xrefAdapter));
-
- // and the change descriptions are clean
- sniffer.assertChangesDisposed();
- }
-
- //
- // Framework methods
- //
-
- private static class TransactionSniffer extends ResourceSetListenerImpl {
- private final TransactionalEditingDomain domain;
- private final List changes =
- new java.util.ArrayList();
-
- TransactionSniffer(TransactionalEditingDomain domain) {
- this.domain = domain;
- domain.addResourceSetListener(this);
- }
-
- @Override
+ root.getBranches().remove(level1);
+ }
+ };
+
+ domain.addResourceSetListener(new TriggerListener() {
+ @Override
+ protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
+ // trigger on the name change only
+ if (notification.getFeature() == EXTLibraryPackage.Literals.LIBRARY__NAME) {
+ return trigger;
+ }
+
+ return null;
+ }
+ });
+
+ IUndoableOperation oper = new AbstractEMFOperation(domain, "Rename Library") {
+ @Override
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ root.setName("newname");
+
+ return Status.OK_STATUS;
+ }
+ };
+
+ IUndoContext ctx = new UndoContext();
+ oper.addContext(ctx);
+
+ try {
+ history.execute(oper, null, null);
+ } catch (ExecutionException e) {
+ Assertions.fail("Failed to execute operation: " + e.getLocalizedMessage());
+ }
+
+ // remove the resource undo context so that flush will dispose
+ ResourceUndoContext resctx = new ResourceUndoContext(domain, testResource);
+ history.getUndoOperation(resctx).removeContext(resctx);
+
+ // the adapter is still attached, of course
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ // undo/redo should not change the adapter attachment
+ try {
+ history.undo(ctx, null, null);
+ } catch (ExecutionException e) {
+ Assertions.fail("Failed to undo operation: " + e.getLocalizedMessage());
+ }
+ try {
+ history.redo(ctx, null, null);
+ } catch (ExecutionException e) {
+ Assertions.fail("Failed to redo operation: " + e.getLocalizedMessage());
+ }
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ // flushing the context should dispose the operation, which should
+ // remove adapters from the change description and its contents
+ history.dispose(ctx, true, true, true);
+ assertFalse(level1.eAdapters().contains(xrefAdapter));
+
+ // and the change descriptions are clean
+ sniffer.assertChangesDisposed();
+ }
+
+ /**
+ *
+ * Tests that the change descriptions that recorded execution, undo, and redo of
+ * a trigger operation that removes an element that has an
+ * ECrossReferenceAdapter attached do not leak that adapter after the operation
+ * history has been flushed. This tests the disposal of
+ * RecordingCommands, that it clears the adapters of the change
+ * description and its contents.
+ *
+ */
+ @Test
+ public void test_crossReferenceAdapter_undoredo_operationTriggerOperations() {
+ // attach a cross-reference adapter to the resource set
+ ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
+ domain.getResourceSet().eAdapters().add(xrefAdapter);
+
+ // and a transaction-sniffer to the domain
+ TransactionSniffer sniffer = new TransactionSniffer(domain);
+
+ final EObject level1 = find(root, "level1");
+
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ IUndoableOperation triggerOper = new AbstractEMFOperation(domain, "Remove Branch") {
+ @Override
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ root.getBranches().remove(level1);
+
+ return Status.OK_STATUS;
+ }
+ };
+ final Command trigger = new EMFOperationCommand(domain, triggerOper);
+
+ domain.addResourceSetListener(new TriggerListener() {
+ @Override
+ protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
+ // trigger on the name change only
+ if (notification.getFeature() == EXTLibraryPackage.Literals.LIBRARY__NAME) {
+ return trigger;
+ }
+
+ return null;
+ }
+ });
+
+ IUndoableOperation oper = new AbstractEMFOperation(domain, "Rename Library") {
+ @Override
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ root.setName("newname");
+
+ return Status.OK_STATUS;
+ }
+ };
+
+ IUndoContext ctx = new UndoContext();
+ oper.addContext(ctx);
+
+ try {
+ history.execute(oper, null, null);
+ } catch (ExecutionException e) {
+ Assertions.fail("Failed to execute operation: " + e.getLocalizedMessage());
+ }
+
+ // remove the resource undo context so that flush will dispose
+ ResourceUndoContext resctx = new ResourceUndoContext(domain, testResource);
+ history.getUndoOperation(resctx).removeContext(resctx);
+
+ // the adapter is still attached, of course
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ // undo/redo should not change the adapter attachment
+ try {
+ history.undo(ctx, null, null);
+ } catch (ExecutionException e) {
+ Assertions.fail("Failed to undo operation: " + e.getLocalizedMessage());
+ }
+ try {
+ history.redo(ctx, null, null);
+ } catch (ExecutionException e) {
+ Assertions.fail("Failed to redo operation: " + e.getLocalizedMessage());
+ }
+ assertTrue(level1.eAdapters().contains(xrefAdapter));
+
+ // flushing the context should dispose the operation, which should
+ // remove adapters from the change description and its contents
+ history.dispose(ctx, true, true, true);
+ assertFalse(level1.eAdapters().contains(xrefAdapter));
+
+ // and the change descriptions are clean
+ sniffer.assertChangesDisposed();
+ }
+
+ //
+ // Framework methods
+ //
+
+ private static class TransactionSniffer extends ResourceSetListenerImpl {
+ private final TransactionalEditingDomain domain;
+ private final List changes = new java.util.ArrayList<>();
+
+ TransactionSniffer(TransactionalEditingDomain domain) {
+ this.domain = domain;
+ domain.addResourceSetListener(this);
+ }
+
+ @Override
public boolean isPostcommitOnly() {
- return true;
- }
-
- @Override
+ return true;
+ }
+
+ @Override
public void resourceSetChanged(ResourceSetChangeEvent event) {
- Transaction tx = event.getTransaction();
-
- if ((tx != null) && (tx.getChangeDescription()) != null) {
- changes.add(tx.getChangeDescription());
- }
- }
-
- void assertChangesDisposed() {
- // stop listening, now
- domain.removeResourceSetListener(this);
-
- for (Iterator iter = EcoreUtil.getAllContents(changes); iter.hasNext();) {
- EObject next = iter.next();
- assertEquals("Adapters not cleared.", 0, next.eAdapters().size()); //$NON-NLS-1$
- }
- }
- }
+ Transaction tx = event.getTransaction();
+
+ if ((tx != null) && (tx.getChangeDescription()) != null) {
+ changes.add(tx.getChangeDescription());
+ }
+ }
+
+ void assertChangesDisposed() {
+ // stop listening, now
+ domain.removeResourceSetListener(this);
+
+ for (Iterator iter = EcoreUtil.getAllContents(changes); iter.hasNext();) {
+ EObject next = iter.next();
+ assertEquals(0, next.eAdapters().size(), "Adapters not cleared.");
+ }
+ }
+ }
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/UndoContextTest.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/UndoContextTest.java
index 493336cd..1ba5f5ca 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/UndoContextTest.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/UndoContextTest.java
@@ -11,12 +11,12 @@
*/
package org.eclipse.emf.workspace.tests;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
import java.util.Collections;
import java.util.Set;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.commands.operations.IUndoableOperation;
@@ -30,6 +30,7 @@
import org.eclipse.emf.workspace.ResourceUndoContext;
import org.eclipse.emf.workspace.tests.fixtures.TestOperation;
import org.eclipse.emf.workspace.tests.fixtures.TestUndoContext;
+import org.junit.jupiter.api.Test;
/**
@@ -39,26 +40,19 @@
*/
public class UndoContextTest extends AbstractTest {
- public UndoContextTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(UndoContextTest.class, "Undo Context Tests"); //$NON-NLS-1$
- }
-
/**
* Tests determination of undo context from local changes (in attributes and
* references).
*/
+ @Test
public void test_localChanges() {
startReading();
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
- final String newTitle = "New Title"; //$NON-NLS-1$
- final Writer newAuthor = (Writer) find("root/level1/Level1 Writer"); //$NON-NLS-1$
+ final String newTitle = "New Title";
+ final Writer newAuthor = (Writer) find("root/level1/Level1 Writer");
assertNotNull(newAuthor);
commit();
@@ -89,6 +83,7 @@ protected void doExecute() {
* Tests determination of undo context from remote changes (in attributes and
* references).
*/
+ @Test
public void test_remoteChanges() {
Resource res2 = new ResourceImpl();
Library lib2 = EXTLibraryFactory.eINSTANCE.createLibrary();
@@ -101,10 +96,10 @@ public void test_remoteChanges() {
// add this other resource to my resource set
domain.getResourceSet().getResources().add(res2);
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
- final String newTitle = "New Title"; //$NON-NLS-1$
+ final String newTitle = "New Title";
commit();
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/WorkbenchCommandStackTest.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/WorkbenchCommandStackTest.java
index d43038bc..f20f7a41 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/WorkbenchCommandStackTest.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/WorkbenchCommandStackTest.java
@@ -13,13 +13,18 @@
*/
package org.eclipse.emf.workspace.tests;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.util.Arrays;
import java.util.EventObject;
import java.util.List;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.AbstractOperation;
import org.eclipse.core.commands.operations.IOperationHistory;
@@ -64,7 +69,8 @@
import org.eclipse.emf.workspace.tests.fixtures.LogCapture;
import org.eclipse.emf.workspace.tests.fixtures.NullCommand;
import org.eclipse.emf.workspace.tests.fixtures.SelfOpeningEMFCompositeOperation;
-
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests the {@link WorkbenchCommandStack} class.
@@ -74,733 +80,733 @@
public class WorkbenchCommandStackTest extends AbstractTest {
private IUndoContext defaultContext;
-
- public WorkbenchCommandStackTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(WorkbenchCommandStackTest.class, "Command Stack Tests"); //$NON-NLS-1$
- }
-
+
/**
* Tests basic execution.
*/
+ @Test
public void test_execute() {
Command cmd = new NullCommand();
-
+
getCommandStack().execute(cmd);
-
+
IUndoableOperation[] operations = history.getUndoHistory(defaultContext);
-
+
assertNotNull(operations);
assertEquals(1, operations.length);
-
+
IUndoableOperation operation = operations[0];
-
+
assertTrue(operation instanceof EMFCommandOperation);
assertSame(cmd, ((EMFCommandOperation) operation).getCommand());
}
-
+
/**
* Tests undo/redo support.
*/
+ @Test
public void test_undo_redo() {
Command cmd = new NullCommand();
-
+
getCommandStack().execute(cmd);
-
+
Command undo = getCommandStack().getUndoCommand();
-
+
assertSame(cmd, undo);
-
+
Command redo = getCommandStack().getRedoCommand();
-
+
assertNull(redo);
-
+
getCommandStack().undo();
-
+
undo = getCommandStack().getUndoCommand();
-
+
assertNull(undo);
-
+
redo = getCommandStack().getRedoCommand();
-
+
assertSame(cmd, redo);
-
+
getCommandStack().redo();
-
+
assertSame(cmd, getCommandStack().getUndoCommand());
}
-
+
/**
* Tests most-recent-command support.
*/
+ @Test
public void test_mostRecentCommand() {
Command cmd = new NullCommand();
-
+
// execute some other command
getCommandStack().execute(new NullCommand());
-
+
getCommandStack().execute(cmd);
-
+
assertSame(cmd, getCommandStack().getMostRecentCommand());
-
+
// execute some other command
getCommandStack().execute(new NullCommand());
-
+
assertNotSame(cmd, getCommandStack().getMostRecentCommand());
-
+
getCommandStack().undo();
-
+
assertNotSame(cmd, getCommandStack().getMostRecentCommand());
-
+
getCommandStack().undo();
-
+
assertSame(cmd, getCommandStack().getMostRecentCommand());
-
+
getCommandStack().undo();
-
+
getCommandStack().redo();
-
+
assertNotSame(cmd, getCommandStack().getMostRecentCommand());
-
+
getCommandStack().redo();
-
+
assertSame(cmd, getCommandStack().getMostRecentCommand());
}
-
+
/**
* Tests flush support.
*/
+ @Test
public void test_flush() {
getCommandStack().execute(new NullCommand());
getCommandStack().execute(new NullCommand());
-
+
IUndoableOperation[] operations = history.getUndoHistory(defaultContext);
-
+
assertNotNull(operations);
assertEquals(2, operations.length);
-
+
getCommandStack().flush();
-
+
operations = history.getUndoHistory(defaultContext);
-
+
assertNotNull(operations);
assertEquals(0, operations.length);
}
-
+
+ @Test
public void test_flushingOnResourceUnload() {
- Command cmd = new SetCommand(
- domain,
- root,
- EXTLibraryPackage.eINSTANCE.getLibrary_Name(),
- "foo"); //$NON-NLS-1$
-
+ Command cmd = new SetCommand(domain, root, EXTLibraryPackage.eINSTANCE.getLibrary_Name(), "foo");
+
getCommandStack().execute(cmd);
-
+
IUndoContext resctx = new ResourceUndoContext(domain, testResource);
IUndoableOperation[] operations = history.getUndoHistory(resctx);
-
+
assertNotNull(operations);
assertEquals(1, operations.length);
-
+
IUndoableOperation operation = operations[0];
-
+
IUndoContext[] contexts = operation.getContexts();
-
+
assertEquals(2, contexts.length);
-
+
assertTrue((resctx.matches(contexts[0]) && defaultContext.matches(contexts[1]))
|| (resctx.matches(contexts[1]) && defaultContext.matches(contexts[0])));
-
+
// unload the resource (no transaction required)
testResource.unload();
// resource context was flushed
operations = history.getUndoHistory(resctx);
-
+
assertNotNull(operations);
assertEquals(0, operations.length);
}
-
+
+ @Test
public void testUndoContextPropagationFromTriggerListeners() {
final TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
final IUndoContext undoContext = new UndoContext();
-
+
domain.addResourceSetListener(new ResourceSetListenerImpl() {
@Override
public boolean isPrecommitOnly() {
return true;
}
-
+
@Override
- public Command transactionAboutToCommit(ResourceSetChangeEvent event)
- throws RollbackException {
-
- IUndoableOperation op = new AbstractOperation("") { //$NON-NLS-1$
+ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
+
+ IUndoableOperation op = new AbstractOperation("") {
@Override
- public IStatus execute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
-
+
@Override
- public IStatus redo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
-
+
@Override
- public IStatus undo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
};
-
+
op.addContext(undoContext);
-
+
return new EMFOperationCommand(domain, op);
}
});
-
- final Resource r = domain.getResourceSet().createResource(URI.createURI("file://foo.xml")); //$NON-NLS-1$
+
+ final Resource r = domain.getResourceSet().createResource(URI.createURI("file://foo.xml"));
IUndoContext resCtx = new ResourceUndoContext(domain, r);
-
- AbstractEMFOperation op = new AbstractEMFOperation(domain, "") { //$NON-NLS-1$
+
+ AbstractEMFOperation op = new AbstractEMFOperation(domain, "") {
@Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
r.getContents().add(EXTLibraryFactory.eINSTANCE.createLibrary());
-
+
return Status.OK_STATUS;
}
};
-
+
assertTrue(op.getContexts().length == 0);
-
+
// Try executing the operation manually
try {
op.execute(new NullProgressMonitor(), null);
} catch (ExecutionException e) {
e.printStackTrace();
- fail();
+ Assertions.fail();
}
-
+
assertNotNull(op.getContexts());
- List opContexts = Arrays.asList(op.getContexts());
+ List opContexts = Arrays.asList(op.getContexts());
assertTrue(opContexts.contains(resCtx));
- assertTrue(opContexts.contains(undoContext));
-
+ assertTrue(opContexts.contains(undoContext));
+
op.removeContext(undoContext);
- op.removeContext(resCtx);
-
+ op.removeContext(resCtx);
+
try {
OperationHistoryFactory.getOperationHistory().execute(op, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
e.printStackTrace();
- fail();
+ Assertions.fail();
}
-
- assertNotNull(op.getContexts());
- opContexts = Arrays.asList(op.getContexts());
- assertTrue(opContexts.contains(resCtx));
- assertTrue(opContexts.contains(undoContext));
-
- op.removeContext(undoContext);
- op.removeContext(resCtx);
+
+ assertNotNull(op.getContexts());
+ opContexts = Arrays.asList(op.getContexts());
+ assertTrue(opContexts.contains(resCtx));
+ assertTrue(opContexts.contains(undoContext));
+
+ op.removeContext(undoContext);
+ op.removeContext(resCtx);
}
-
+
+ @Test
public void testSaveIsDoneAPIs() {
TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
- final Resource r = domain.getResourceSet().createResource(URI.createURI("file://foo.xml")); //$NON-NLS-1$
-
+ final Resource r = domain.getResourceSet().createResource(URI.createURI("file://foo.xml"));
+
Command op = new RecordingCommand(domain) {
@Override
protected void doExecute() {
r.getContents().add(EXTLibraryFactory.eINSTANCE.createLibrary());
-
+
}
};
-
- BasicCommandStack stack = (BasicCommandStack)domain.getCommandStack();
-
+
+ BasicCommandStack stack = (BasicCommandStack) domain.getCommandStack();
+
// Force the operation history to clear itself of our operations.
- OperationHistoryFactory.getOperationHistory().setLimit(
- ((WorkspaceCommandStackImpl)stack).getDefaultUndoContext(), 0);
- OperationHistoryFactory.getOperationHistory().setLimit(
- ((WorkspaceCommandStackImpl)stack).getDefaultUndoContext(), 20);
-
+ OperationHistoryFactory.getOperationHistory()
+ .setLimit(((WorkspaceCommandStackImpl) stack).getDefaultUndoContext(), 0);
+ OperationHistoryFactory.getOperationHistory()
+ .setLimit(((WorkspaceCommandStackImpl) stack).getDefaultUndoContext(), 20);
+
stack.saveIsDone();
-
+
assertFalse(stack.isSaveNeeded());
-
+
stack.execute(op);
-
+
assertTrue(stack.isSaveNeeded());
-
+
stack.undo();
-
+
assertFalse(stack.isSaveNeeded());
-
+
stack.redo();
-
+
assertTrue(stack.isSaveNeeded());
-
+
stack.saveIsDone();
-
+
assertFalse(stack.isSaveNeeded());
-
+
stack.execute(op);
-
+
assertTrue(stack.isSaveNeeded());
}
-
- public void test_isSaveNeeded_214325() {
- TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
- final Resource r = domain.getResourceSet().createResource(URI.createURI("file://foo.xml")); //$NON-NLS-1$
-
- Command op = new RecordingCommand(domain) {
-
- @Override
- protected void doExecute() {
- r.getContents().add(EXTLibraryFactory.eINSTANCE.createLibrary());
-
- }
- };
-
- BasicCommandStack stack = (BasicCommandStack)domain.getCommandStack();
-
- // Force the operation history to clear itself of our operations.
- OperationHistoryFactory.getOperationHistory().setLimit(
- ((WorkspaceCommandStackImpl)stack).getDefaultUndoContext(), 0);
- OperationHistoryFactory.getOperationHistory().setLimit(
- ((WorkspaceCommandStackImpl)stack).getDefaultUndoContext(), 20);
-
- assertFalse(stack.isSaveNeeded());
-
- stack.execute(op);
-
- assertTrue(stack.isSaveNeeded());
-
- stack.saveIsDone();
-
- assertFalse(stack.isSaveNeeded());
-
- stack.undo();
-
- assertTrue(stack.isSaveNeeded());
- }
-
- /**
- * Test that run-time exceptions in a trigger command cause rollback of
- * the whole transaction.
- */
- public void test_triggerRollback_146853() {
- final RuntimeException error = new RuntimeException();
-
- ResourceSetListener testListener = new TriggerListener() {
- @Override
+
+ @Test
+ public void test_isSaveNeeded_214325() {
+ TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
+ final Resource r = domain.getResourceSet().createResource(URI.createURI("file://foo.xml"));
+
+ Command op = new RecordingCommand(domain) {
+
+ @Override
+ protected void doExecute() {
+ r.getContents().add(EXTLibraryFactory.eINSTANCE.createLibrary());
+
+ }
+ };
+
+ BasicCommandStack stack = (BasicCommandStack) domain.getCommandStack();
+
+ // Force the operation history to clear itself of our operations.
+ OperationHistoryFactory.getOperationHistory()
+ .setLimit(((WorkspaceCommandStackImpl) stack).getDefaultUndoContext(), 0);
+ OperationHistoryFactory.getOperationHistory()
+ .setLimit(((WorkspaceCommandStackImpl) stack).getDefaultUndoContext(), 20);
+
+ assertFalse(stack.isSaveNeeded());
+
+ stack.execute(op);
+
+ assertTrue(stack.isSaveNeeded());
+
+ stack.saveIsDone();
+
+ assertFalse(stack.isSaveNeeded());
+
+ stack.undo();
+
+ assertTrue(stack.isSaveNeeded());
+ }
+
+ /**
+ * Test that run-time exceptions in a trigger command cause rollback of the
+ * whole transaction.
+ */
+ @Test
+ public void test_triggerRollback_146853() {
+ final RuntimeException error = new RuntimeException();
+
+ ResourceSetListener testListener = new TriggerListener() {
+ @Override
protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
- return new RecordingCommand(domain, "Error") { //$NON-NLS-1$
- @Override
+ return new RecordingCommand(domain, "Error") {
+ @Override
protected void doExecute() {
- throw error;
- }};
- }};
-
- LogCapture logCapture = new LogCapture(
- getCommandStack(), EMFWorkspacePlugin.getPlugin().getBundle());
-
- try {
- domain.addResourceSetListener(testListener);
-
- domain.getCommandStack().execute(new RecordingCommand(domain) {
- @Override
+ throw error;
+ }
+ };
+ }
+ };
+
+ LogCapture logCapture = new LogCapture(getCommandStack(), EMFWorkspacePlugin.getPlugin().getBundle());
+
+ try {
+ domain.addResourceSetListener(testListener);
+
+ domain.getCommandStack().execute(new RecordingCommand(domain) {
+ @Override
protected void doExecute() {
- root.getWriters().clear();
- root.getStock().clear();
- root.getBranches().clear();
- }});
-
- // verify that the exception was duly logged
- logCapture.assertLogged(error);
-
- // verify that rollback occurred
- assertFalse(root.getWriters().isEmpty());
- assertFalse(root.getStock().isEmpty());
- assertFalse(root.getBranches().isEmpty());
- } finally {
- logCapture.stop();
- domain.removeResourceSetListener(testListener);
- }
- }
-
- /**
- * Test that OperationCanceledException in a trigger command causes
- * rollback of the whole transaction, without any log message (because it
- * is a normal condition).
- */
- public void test_triggerRollback_cancel_146853() {
- final RuntimeException error = new OperationCanceledException();
-
- ResourceSetListener testListener = new TriggerListener() {
- @Override
+ root.getWriters().clear();
+ root.getStock().clear();
+ root.getBranches().clear();
+ }
+ });
+
+ // verify that the exception was duly logged
+ logCapture.assertLogged(error);
+
+ // verify that rollback occurred
+ assertFalse(root.getWriters().isEmpty());
+ assertFalse(root.getStock().isEmpty());
+ assertFalse(root.getBranches().isEmpty());
+ } finally {
+ logCapture.stop();
+ domain.removeResourceSetListener(testListener);
+ }
+ }
+
+ /**
+ * Test that OperationCanceledException in a trigger command causes rollback of
+ * the whole transaction, without any log message (because it is a normal
+ * condition).
+ */
+ @Test
+ public void test_triggerRollback_cancel_146853() {
+ final RuntimeException error = new OperationCanceledException();
+
+ ResourceSetListener testListener = new TriggerListener() {
+ @Override
protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
- return new RecordingCommand(domain, "Error") { //$NON-NLS-1$
- @Override
+ return new RecordingCommand(domain, "Error") {
+ @Override
protected void doExecute() {
- throw error;
- }};
- }};
-
- LogCapture logCapture = new LogCapture(
- getCommandStack(), EMFWorkspacePlugin.getPlugin().getBundle());
-
- try {
- domain.addResourceSetListener(testListener);
-
- domain.getCommandStack().execute(new RecordingCommand(domain) {
- @Override
+ throw error;
+ }
+ };
+ }
+ };
+
+ LogCapture logCapture = new LogCapture(getCommandStack(), EMFWorkspacePlugin.getPlugin().getBundle());
+
+ try {
+ domain.addResourceSetListener(testListener);
+
+ domain.getCommandStack().execute(new RecordingCommand(domain) {
+ @Override
protected void doExecute() {
- root.getWriters().clear();
- root.getStock().clear();
- root.getBranches().clear();
- }});
-
- // verify that the exception was *not* logged
- IStatus log = logCapture.getLastLog();
- assertNull(log);
-
- // verify that rollback occurred
- assertFalse(root.getWriters().isEmpty());
- assertFalse(root.getStock().isEmpty());
- assertFalse(root.getBranches().isEmpty());
- } finally {
- logCapture.stop();
- domain.removeResourceSetListener(testListener);
- }
- }
-
- /**
- * Test that run-time exceptions in a trigger command cause rollback of
- * the whole transaction when executing an AbstractEMFOperation.
- */
- public void test_triggerRollback_operation_146853() {
- final RuntimeException error = new RuntimeException();
-
- ResourceSetListener testListener = new TriggerListener() {
- @Override
+ root.getWriters().clear();
+ root.getStock().clear();
+ root.getBranches().clear();
+ }
+ });
+
+ // verify that the exception was *not* logged
+ IStatus log = logCapture.getLastLog();
+ assertNull(log);
+
+ // verify that rollback occurred
+ assertFalse(root.getWriters().isEmpty());
+ assertFalse(root.getStock().isEmpty());
+ assertFalse(root.getBranches().isEmpty());
+ } finally {
+ logCapture.stop();
+ domain.removeResourceSetListener(testListener);
+ }
+ }
+
+ /**
+ * Test that run-time exceptions in a trigger command cause rollback of the
+ * whole transaction when executing an AbstractEMFOperation.
+ */
+ @Test
+ public void test_triggerRollback_operation_146853() {
+ final RuntimeException error = new RuntimeException();
+
+ ResourceSetListener testListener = new TriggerListener() {
+ @Override
protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
- return new RecordingCommand(domain, "Error") { //$NON-NLS-1$
- @Override
+ return new RecordingCommand(domain, "Error") {
+ @Override
protected void doExecute() {
- throw error;
- }};
- }};
-
- try {
- domain.addResourceSetListener(testListener);
-
- try {
- IStatus status = new AbstractEMFOperation(domain, "test") { //$NON-NLS-1$
- @Override
+ throw error;
+ }
+ };
+ }
+ };
+
+ try {
+ domain.addResourceSetListener(testListener);
+
+ try {
+ IStatus status = new AbstractEMFOperation(domain, "test") {
+ @Override
protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) {
- root.getWriters().clear();
- root.getStock().clear();
- root.getBranches().clear();
-
- return Status.OK_STATUS;
- }}.execute(null, null);
-
- assertEquals(IStatus.ERROR, status.getSeverity());
- } catch (ExecutionException e) {
- fail("Execution failed: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
-
- // verify that rollback occurred
- assertFalse(root.getWriters().isEmpty());
- assertFalse(root.getStock().isEmpty());
- assertFalse(root.getBranches().isEmpty());
- } finally {
- domain.removeResourceSetListener(testListener);
- }
- }
-
- /**
- * Test that OperationCanceledException in a trigger command causes
- * rollback of the whole transaction, without any log message (because it
- * is a normal condition) when executing an AbstractEMFOperation.
- */
- public void test_triggerRollback_operation_cancel_146853() {
- final RuntimeException error = new OperationCanceledException();
-
- ResourceSetListener testListener = new TriggerListener() {
- @Override
+ root.getWriters().clear();
+ root.getStock().clear();
+ root.getBranches().clear();
+
+ return Status.OK_STATUS;
+ }
+ }.execute(null, null);
+
+ assertEquals(IStatus.ERROR, status.getSeverity());
+ } catch (ExecutionException e) {
+ Assertions.fail("Execution failed: " + e.getLocalizedMessage());
+ }
+
+ // verify that rollback occurred
+ assertFalse(root.getWriters().isEmpty());
+ assertFalse(root.getStock().isEmpty());
+ assertFalse(root.getBranches().isEmpty());
+ } finally {
+ domain.removeResourceSetListener(testListener);
+ }
+ }
+
+ /**
+ * Test that OperationCanceledException in a trigger command causes rollback of
+ * the whole transaction, without any log message (because it is a normal
+ * condition) when executing an AbstractEMFOperation.
+ */
+ @Test
+ public void test_triggerRollback_operation_cancel_146853() {
+ final RuntimeException error = new OperationCanceledException();
+
+ ResourceSetListener testListener = new TriggerListener() {
+ @Override
protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
- return new RecordingCommand(domain, "Error") { //$NON-NLS-1$
- @Override
+ return new RecordingCommand(domain, "Error") {
+ @Override
protected void doExecute() {
- throw error;
- }};
- }};
-
- try {
- domain.addResourceSetListener(testListener);
-
- try {
- IStatus status = new AbstractEMFOperation(domain, "test") { //$NON-NLS-1$
- @Override
+ throw error;
+ }
+ };
+ }
+ };
+
+ try {
+ domain.addResourceSetListener(testListener);
+
+ try {
+ IStatus status = new AbstractEMFOperation(domain, "test") {
+ @Override
protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) {
- root.getWriters().clear();
- root.getStock().clear();
- root.getBranches().clear();
-
- return Status.OK_STATUS;
- }}.execute(null, null);
-
- assertEquals(IStatus.CANCEL, status.getSeverity());
- } catch (ExecutionException e) {
- fail("Execution failed: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
-
- // verify that rollback occurred
- assertFalse(root.getWriters().isEmpty());
- assertFalse(root.getStock().isEmpty());
- assertFalse(root.getBranches().isEmpty());
- } finally {
- domain.removeResourceSetListener(testListener);
- }
- }
-
- /**
- * Tests that the {@link RecordingCommand} can be used as a trigger command,
- * that in this case it is able correctly to capture its changes for
- * undo/redo.
- */
- public void test_recordingCommandsAsTriggers_bug157103() {
- // one trigger sets default library names
- domain.addResourceSetListener(new LibraryDefaultNameTrigger() {
- @Override
+ root.getWriters().clear();
+ root.getStock().clear();
+ root.getBranches().clear();
+
+ return Status.OK_STATUS;
+ }
+ }.execute(null, null);
+
+ assertEquals(IStatus.CANCEL, status.getSeverity());
+ } catch (ExecutionException e) {
+ Assertions.fail("Execution failed: " + e.getLocalizedMessage());
+ }
+
+ // verify that rollback occurred
+ assertFalse(root.getWriters().isEmpty());
+ assertFalse(root.getStock().isEmpty());
+ assertFalse(root.getBranches().isEmpty());
+ } finally {
+ domain.removeResourceSetListener(testListener);
+ }
+ }
+
+ /**
+ * Tests that the {@link RecordingCommand} can be used as a trigger command,
+ * that in this case it is able correctly to capture its changes for undo/redo.
+ */
+ @Test
+ public void test_recordingCommandsAsTriggers_bug157103() {
+ // one trigger sets default library names
+ domain.addResourceSetListener(new LibraryDefaultNameTrigger() {
+ @Override
protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
- Command result = null;
-
- final Library newLibrary = (Library) notification.getNewValue();
- if ((newLibrary.getName() == null) || (newLibrary.getName().length() == 0)) {
- result = new RecordingCommand(domain) {
- @Override
+ Command result = null;
+
+ final Library newLibrary = (Library) notification.getNewValue();
+ if ((newLibrary.getName() == null) || (newLibrary.getName().length() == 0)) {
+ result = new RecordingCommand(domain) {
+ @Override
protected void doExecute() {
- newLibrary.setName("New Library"); //$NON-NLS-1$
- }};
- }
-
- return result;
- }});
-
- final Library[] newLibrary = new Library[1];
-
- IUndoContext ctx = new UndoContext();
- IUndoableOperation operation = new AbstractEMFOperation(domain, "Test") { //$NON-NLS-1$
- @Override
+ newLibrary.setName("New Library");
+ }
+ };
+ }
+
+ return result;
+ }
+ });
+
+ final Library[] newLibrary = new Library[1];
+
+ IUndoContext ctx = new UndoContext();
+ IUndoableOperation operation = new AbstractEMFOperation(domain, "Test") {
+ @Override
protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) {
- newLibrary[0] = EXTLibraryFactory.eINSTANCE.createLibrary();
- root.getBranches().add(newLibrary[0]);
-
- assertNull(newLibrary[0].getName());
-
- return Status.OK_STATUS;
- }};
- operation.addContext(ctx);
-
- try {
- // add a new library. Our trigger will set a default name
- history.execute(operation, null, null);
- } catch (ExecutionException e) {
- fail("Failed to execute test operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
-
- startReading();
-
- assertEquals("New Library", newLibrary[0].getName()); //$NON-NLS-1$
-
- commit();
-
- try {
- history.undo(ctx, null, null);
- } catch (ExecutionException e) {
- fail("Failed to undo test operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
-
- assertFalse(root.getBranches().contains(newLibrary[0]));
- assertNull(newLibrary[0].eResource());
- assertNull(newLibrary[0].getName());
-
- try {
- history.redo(ctx, null, null);
- } catch (ExecutionException e) {
- fail("Failed to redo test operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
-
- assertTrue(root.getBranches().contains(newLibrary[0]));
- assertEquals("New Library", newLibrary[0].getName()); //$NON-NLS-1$
- }
-
- /**
- * Tests that, when a command execution is rolled back, the command stack
- * listeners are notified again that the stack is changed, so that they
- * will correctly update themselves if necessary.
- */
- public void test_rollbackNotifiesCommandStackListeners_175725() {
- class TestCSL implements CommandStackListener {
- int invocationCount = 0;
- public void commandStackChanged(EventObject event) {
- invocationCount++;
- }
- }
-
- TestCSL listener = new TestCSL();
- CommandStack stack = domain.getCommandStack();
- stack.addCommandStackListener(listener);
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
- assertNotNull(book);
- Command command = SetCommand.create(
- domain, book, EXTLibraryPackage.Literals.BOOK__TITLE, null);
-
- try {
- validationEnabled = true;
- stack.execute(command);
- } catch (Exception e) {
- fail(e);
- } finally {
- validationEnabled = false;
- stack.removeCommandStackListener(listener);
- }
-
- assertEquals("Command-stack listener invoked wrong number of times", //$NON-NLS-1$
- 1, listener.invocationCount);
- assertFalse("Should not have an undo command", stack.canUndo()); //$NON-NLS-1$
- }
-
- public void test_undoRedoNotifyListeners_173839() {
- class TestCSL implements CommandStackListener {
- int invocationCount = 0;
- public void commandStackChanged(EventObject event) {
- invocationCount++;
- }
- }
-
- TestCSL listener = new TestCSL();
- CommandStack stack = domain.getCommandStack();
- stack.addCommandStackListener(listener);
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
- assertNotNull(book);
- Command command = SetCommand.create(
- domain, book, EXTLibraryPackage.Literals.BOOK__TITLE, "New Title"); //$NON-NLS-1$
-
- Command undoCmd = null;
- Command redoCmd = null;
-
- try {
- stack.execute(command);
-
- listener.invocationCount = 0; // clear state
-
- stack.undo();
- redoCmd = stack.getRedoCommand();
-
- stack.redo();
- undoCmd = stack.getUndoCommand();
- } catch (Exception e) {
- fail(e);
- } finally {
- stack.removeCommandStackListener(listener);
- }
-
- assertEquals("Command-stack listener invoked wrong number of times", //$NON-NLS-1$
- 2, listener.invocationCount);
- assertSame(command, undoCmd);
- assertSame(command, redoCmd);
- }
-
- /**
- * Tests that we do not lose track of affected resources when executing
- * operations within open composites (nested operation execution).
- */
- public void test_nestedExecutionInOpenComposite_203352() {
- SelfOpeningEMFCompositeOperation operation = new SelfOpeningEMFCompositeOperation(
- domain) {
-
- @Override
- protected IStatus doExecute(IOperationHistory history,
- IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
- return history.execute(
- new AbstractEMFOperation(domain, "Test") { //$NON-NLS-1$
-
- @Override
- protected IStatus doExecute(IProgressMonitor monitor,
- IAdaptable info) {
- root.getBranches().add(
- EXTLibraryFactory.eINSTANCE.createLibrary());
-
- return Status.OK_STATUS;
- }
- }, monitor, info);
- }
- };
-
- try {
- history.execute(operation, null, null);
- } catch (ExecutionException e) {
- fail("Failed to execute test operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
-
- IUndoContext expected = new ResourceUndoContext(domain, testResource);
- assertTrue(operation.hasContext(expected));
- }
-
- /**
- * Tests that whatever operation is currently executing while changes occur
- * in some resource, is tagged with an undo context for that resource.
- */
+ newLibrary[0] = EXTLibraryFactory.eINSTANCE.createLibrary();
+ root.getBranches().add(newLibrary[0]);
+
+ assertNull(newLibrary[0].getName());
+
+ return Status.OK_STATUS;
+ }
+ };
+ operation.addContext(ctx);
+
+ try {
+ // add a new library. Our trigger will set a default name
+ history.execute(operation, null, null);
+ } catch (ExecutionException e) {
+ Assertions.fail("Failed to execute test operation: " + e.getLocalizedMessage());
+ }
+
+ startReading();
+
+ assertEquals("New Library", newLibrary[0].getName());
+
+ commit();
+
+ try {
+ history.undo(ctx, null, null);
+ } catch (ExecutionException e) {
+ Assertions.fail("Failed to undo test operation: " + e.getLocalizedMessage());
+ }
+
+ assertFalse(root.getBranches().contains(newLibrary[0]));
+ assertNull(newLibrary[0].eResource());
+ assertNull(newLibrary[0].getName());
+
+ try {
+ history.redo(ctx, null, null);
+ } catch (ExecutionException e) {
+ Assertions.fail("Failed to redo test operation: " + e.getLocalizedMessage());
+ }
+
+ assertTrue(root.getBranches().contains(newLibrary[0]));
+ assertEquals("New Library", newLibrary[0].getName());
+ }
+
+ /**
+ * Tests that, when a command execution is rolled back, the command stack
+ * listeners are notified again that the stack is changed, so that they will
+ * correctly update themselves if necessary.
+ */
+ @Test
+ public void test_rollbackNotifiesCommandStackListeners_175725() {
+ class TestCSL implements CommandStackListener {
+ int invocationCount = 0;
+
+ @Override
+ public void commandStackChanged(EventObject event) {
+ invocationCount++;
+ }
+ }
+
+ TestCSL listener = new TestCSL();
+ CommandStack stack = domain.getCommandStack();
+ stack.addCommandStackListener(listener);
+
+ final Book book = (Book) find("root/Root Book");
+ assertNotNull(book);
+ Command command = SetCommand.create(domain, book, EXTLibraryPackage.Literals.BOOK__TITLE, null);
+
+ try {
+ validationEnabled = true;
+ stack.execute(command);
+ } catch (Exception e) {
+ fail(e);
+ } finally {
+ validationEnabled = false;
+ stack.removeCommandStackListener(listener);
+ }
+
+ assertEquals(1, listener.invocationCount, "Command-stack listener invoked wrong number of times");
+ assertFalse(stack.canUndo(), "Should not have an undo command");
+ }
+
+ @Test
+ public void test_undoRedoNotifyListeners_173839() {
+ class TestCSL implements CommandStackListener {
+ int invocationCount = 0;
+
+ @Override
+ public void commandStackChanged(EventObject event) {
+ invocationCount++;
+ }
+ }
+
+ TestCSL listener = new TestCSL();
+ CommandStack stack = domain.getCommandStack();
+ stack.addCommandStackListener(listener);
+
+ final Book book = (Book) find("root/Root Book");
+ assertNotNull(book);
+ Command command = SetCommand.create(domain, book, EXTLibraryPackage.Literals.BOOK__TITLE, "New Title");
+
+ Command undoCmd = null;
+ Command redoCmd = null;
+
+ try {
+ stack.execute(command);
+
+ listener.invocationCount = 0; // clear state
+
+ stack.undo();
+ redoCmd = stack.getRedoCommand();
+
+ stack.redo();
+ undoCmd = stack.getUndoCommand();
+ } catch (Exception e) {
+ fail(e);
+ } finally {
+ stack.removeCommandStackListener(listener);
+ }
+
+ assertEquals(2, listener.invocationCount, "Command-stack listener invoked wrong number of times");
+ assertSame(command, undoCmd);
+ assertSame(command, redoCmd);
+ }
+
+ /**
+ * Tests that we do not lose track of affected resources when executing
+ * operations within open composites (nested operation execution).
+ */
+ @Test
+ public void test_nestedExecutionInOpenComposite_203352() {
+ SelfOpeningEMFCompositeOperation operation = new SelfOpeningEMFCompositeOperation(domain) {
+
+ @Override
+ protected IStatus doExecute(IOperationHistory history, IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+
+ return history.execute(new AbstractEMFOperation(domain, "Test") {
+
+ @Override
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) {
+ root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
+
+ return Status.OK_STATUS;
+ }
+ }, monitor, info);
+ }
+ };
+
+ try {
+ history.execute(operation, null, null);
+ } catch (ExecutionException e) {
+ Assertions.fail("Failed to execute test operation: " + e.getLocalizedMessage());
+ }
+
+ IUndoContext expected = new ResourceUndoContext(domain, testResource);
+ assertTrue(operation.hasContext(expected));
+ }
+
+ /**
+ * Tests that whatever operation is currently executing while changes occur in
+ * some resource, is tagged with an undo context for that resource.
+ */
+ @Test
public void test_nestedExecutionInAbstractOperation_244654() {
- AbstractOperation operation = new AbstractOperation("Test") { //$NON-NLS-1$
+ AbstractOperation operation = new AbstractOperation("Test") {
- private AbstractEMFOperation delegate = new AbstractEMFOperation(
- domain, "Delegate") { //$NON-NLS-1$
+ private AbstractEMFOperation delegate = new AbstractEMFOperation(domain, "Delegate") {
@Override
- protected IStatus doExecute(IProgressMonitor monitor,
- IAdaptable info)
- throws ExecutionException {
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- root.getBranches().add(
- EXTLibraryFactory.eINSTANCE.createLibrary());
+ root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
return Status.OK_STATUS;
}
};
@Override
- public IStatus execute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return delegate.execute(monitor, info);
}
@Override
- public IStatus redo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return delegate.redo(monitor, info);
}
@Override
- public IStatus undo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return delegate.undo(monitor, info);
}
};
@@ -810,32 +816,31 @@ public IStatus undo(IProgressMonitor monitor, IAdaptable info)
try {
history.execute(operation, null, null);
} catch (ExecutionException e) {
- fail("Unexpected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assertions.fail("Unexpected exception: " + e.getLocalizedMessage());
}
IUndoContext expected = new ResourceUndoContext(domain, testResource);
- assertTrue(
- "Operation missing expected context", operation.hasContext(expected)); //$NON-NLS-1$
+ assertTrue(operation.hasContext(expected), "Operation missing expected context");
}
-
+
//
// Fixture methods
//
-
+
@Override
protected void doSetUp() throws Exception {
super.doSetUp();
-
+
defaultContext = ((IWorkspaceCommandStack) getCommandStack()).getDefaultUndoContext();
}
-
+
@Override
protected void doTearDown() throws Exception {
defaultContext = null;
-
+
super.doTearDown();
}
-
+
ResourceUndoContext getResourceUndoContext(IUndoableOperation operation) {
ResourceUndoContext result = null;
IUndoContext[] contexts = operation.getContexts();
@@ -844,7 +849,7 @@ ResourceUndoContext getResourceUndoContext(IUndoableOperation operation) {
result = (ResourceUndoContext) contexts[i];
}
}
-
+
return result;
}
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/constraints/BookTitleConstraint.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/constraints/BookTitleConstraint.java
index 021b74ed..65fc6d89 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/constraints/BookTitleConstraint.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/constraints/BookTitleConstraint.java
@@ -17,27 +17,25 @@
import org.eclipse.emf.validation.IValidationContext;
/**
- * Constraint used for testing transaction validation scenarios.
- * Requires books to have non-null, non-empty titles.
+ * Constraint used for testing transaction validation scenarios. Requires books
+ * to have non-null, non-empty titles.
*
* @author Christian W. Damus (cdamus)
*/
-public class BookTitleConstraint
- extends AbstractModelConstraint {
+public class BookTitleConstraint extends AbstractModelConstraint {
@Override
public IStatus validate(IValidationContext ctx) {
EMFEventType eType = ctx.getEventType();
-
+
if (eType != EMFEventType.NULL) {
Object newValue = ctx.getFeatureNewValue();
-
- if (newValue == null
- || ((String)newValue).length() == 0) {
+
+ if (newValue == null || ((String) newValue).isEmpty()) {
return ctx.createFailureStatus();
}
}
-
+
return ctx.createSuccessStatus();
}
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/constraints/ClientSelector.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/constraints/ClientSelector.java
index c1dfbaf0..404f1ed0 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/constraints/ClientSelector.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/constraints/ClientSelector.java
@@ -19,9 +19,9 @@
*
* @author Christian W. Damus (cdamus)
*/
-public class ClientSelector
- implements IClientSelector {
-
+public class ClientSelector implements IClientSelector {
+
+ @Override
public boolean selects(Object object) {
return AbstractTest.validationEnabled;
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ContextAdder.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ContextAdder.java
index a86d37c5..4595e262 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ContextAdder.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ContextAdder.java
@@ -27,11 +27,12 @@ public class ContextAdder implements IOperationHistoryListener {
public ContextAdder(IUndoContext contextToAdd) {
context = contextToAdd;
}
-
+
/**
* Adds my context to an operation when it is done then removes me from the
* history.
*/
+ @Override
public void historyNotification(OperationHistoryEvent event) {
switch (event.getEventType()) {
case OperationHistoryEvent.DONE:
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ExternalDataCommand.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ExternalDataCommand.java
index 24f7ceae..1ad905e3 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ExternalDataCommand.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ExternalDataCommand.java
@@ -23,30 +23,32 @@ public class ExternalDataCommand extends AbstractCommand {
private String[] externalData;
private String oldValue;
private String newValue;
-
+
public ExternalDataCommand(String[] externalData, String newValue) {
- super("Change External Data"); //$NON-NLS-1$
-
+ super("Change External Data");
+
this.externalData = externalData;
this.newValue = newValue;
}
-
+
@Override
protected boolean prepare() {
return true;
}
-
+
+ @Override
public void execute() {
// change the external (non-EMF) data
oldValue = externalData[0];
externalData[0] = newValue;
}
-
+
@Override
public void undo() {
externalData[0] = oldValue;
}
-
+
+ @Override
public void redo() {
externalData[0] = newValue;
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ExternalDataOperation.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ExternalDataOperation.java
index 1b8238b9..39839211 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ExternalDataOperation.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ExternalDataOperation.java
@@ -27,34 +27,34 @@ public class ExternalDataOperation extends AbstractOperation {
private String[] externalData;
private String oldValue;
private String newValue;
-
+
public ExternalDataOperation(String[] externalData, String newValue) {
- super("Change External Data"); //$NON-NLS-1$
-
+ super("Change External Data");
+
this.externalData = externalData;
this.newValue = newValue;
}
-
+
@Override
public IStatus execute(IProgressMonitor monitor, IAdaptable info) {
// change the external (non-EMF) data
oldValue = externalData[0];
externalData[0] = newValue;
-
+
return Status.OK_STATUS;
}
-
+
@Override
public IStatus undo(IProgressMonitor monitor, IAdaptable info) {
externalData[0] = oldValue;
-
+
return Status.OK_STATUS;
}
-
+
@Override
public IStatus redo(IProgressMonitor monitor, IAdaptable info) {
externalData[0] = newValue;
-
+
return Status.OK_STATUS;
}
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ItemDefaultPublicationDateTrigger.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ItemDefaultPublicationDateTrigger.java
index 7cac29e6..bfa4123c 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ItemDefaultPublicationDateTrigger.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/ItemDefaultPublicationDateTrigger.java
@@ -27,25 +27,20 @@
*/
public class ItemDefaultPublicationDateTrigger extends TriggerListener {
public ItemDefaultPublicationDateTrigger() {
- super(NotificationFilter.createFeatureFilter(
- EXTLibraryPackage.eINSTANCE.getLibrary_Stock()).and(
- NotificationFilter.createEventTypeFilter(
- Notification.ADD)));
+ super(NotificationFilter.createFeatureFilter(EXTLibraryPackage.eINSTANCE.getLibrary_Stock())
+ .and(NotificationFilter.createEventTypeFilter(Notification.ADD)));
}
-
+
@Override
protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
Command result = null;
-
+
Item newItem = (Item) notification.getNewValue();
if (newItem.getPublicationDate() == null) {
- result= new SetCommand(
- domain,
- newItem,
- EXTLibraryPackage.eINSTANCE.getItem_PublicationDate(),
+ result = new SetCommand(domain, newItem, EXTLibraryPackage.eINSTANCE.getItem_PublicationDate(),
new java.util.Date());
}
-
+
return result;
}
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/LibraryDefaultBookTrigger.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/LibraryDefaultBookTrigger.java
index 9cedf80e..cf2f258e 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/LibraryDefaultBookTrigger.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/LibraryDefaultBookTrigger.java
@@ -29,37 +29,32 @@
*/
public class LibraryDefaultBookTrigger extends TriggerListener {
private final boolean isAggregate;
-
+
public LibraryDefaultBookTrigger() {
this(false);
}
-
+
public LibraryDefaultBookTrigger(boolean isAggregate) {
- super(NotificationFilter.createFeatureFilter(
- EXTLibraryPackage.eINSTANCE.getLibrary_Branches()).and(
- NotificationFilter.createEventTypeFilter(
- Notification.ADD)));
-
+ super(NotificationFilter.createFeatureFilter(EXTLibraryPackage.eINSTANCE.getLibrary_Branches())
+ .and(NotificationFilter.createEventTypeFilter(Notification.ADD)));
+
this.isAggregate = isAggregate;
}
-
+
@Override
protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
Command result = null;
-
+
Library newLibrary = (Library) notification.getNewValue();
if ((newLibrary.getBooks().isEmpty())) {
Book newBook = EXTLibraryFactory.eINSTANCE.createBook();
- newBook.setTitle("New Book"); //$NON-NLS-1$
- result = new AddCommand(
- domain,
- newLibrary.getBooks(),
- newBook);
+ newBook.setTitle("New Book");
+ result = new AddCommand(domain, newLibrary.getBooks(), newBook);
}
-
+
return result;
}
-
+
@Override
public boolean isAggregatePrecommitListener() {
return isAggregate;
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/LibraryDefaultNameTrigger.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/LibraryDefaultNameTrigger.java
index 829bf2f6..b9019c77 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/LibraryDefaultNameTrigger.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/LibraryDefaultNameTrigger.java
@@ -27,35 +27,29 @@
*/
public class LibraryDefaultNameTrigger extends TriggerListener {
private final boolean isAggregate;
-
+
public LibraryDefaultNameTrigger() {
this(false);
}
-
+
public LibraryDefaultNameTrigger(boolean isAggregate) {
- super(NotificationFilter.createFeatureFilter(
- EXTLibraryPackage.eINSTANCE.getLibrary_Branches()).and(
- NotificationFilter.createEventTypeFilter(
- Notification.ADD)));
+ super(NotificationFilter.createFeatureFilter(EXTLibraryPackage.eINSTANCE.getLibrary_Branches())
+ .and(NotificationFilter.createEventTypeFilter(Notification.ADD)));
this.isAggregate = isAggregate;
}
-
+
@Override
protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
Command result = null;
-
+
Library newLibrary = (Library) notification.getNewValue();
- if ((newLibrary.getName() == null) || (newLibrary.getName().length() == 0)) {
- result= new SetCommand(
- domain,
- newLibrary,
- EXTLibraryPackage.eINSTANCE.getLibrary_Name(),
- "New Library"); //$NON-NLS-1$
+ if ((newLibrary.getName() == null) || newLibrary.getName().isEmpty()) {
+ result = new SetCommand(domain, newLibrary, EXTLibraryPackage.eINSTANCE.getLibrary_Name(), "New Library");
}
-
+
return result;
}
-
+
@Override
public boolean isAggregatePrecommitListener() {
return isAggregate;
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/LogCapture.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/LogCapture.java
index 2c313bfe..57c51ee0 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/LogCapture.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/LogCapture.java
@@ -11,9 +11,9 @@
*/
package org.eclipse.emf.workspace.tests.fixtures;
-import java.util.List;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.Assert;
+import java.util.List;
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IStatus;
@@ -34,131 +34,131 @@
public class LogCapture {
private final Bundle targetBundle;
private final ILogListener listener = new ILogListener() {
+ @Override
public void logging(IStatus status, String plugin) {
if (status.getPlugin().equals(targetBundle.getSymbolicName())) {
record(status);
}
- }};
+ }
+ };
private final TransactionalCommandStack stack;
-
- private final List logs = new java.util.ArrayList();
+
+ private final List logs = new java.util.ArrayList<>();
private IStatus lastLog;
-
+
/**
* Initializes me to capture logs from the specified bundle.
- *
+ *
* @param targetBundle the bundle to listen to
*/
public LogCapture(Bundle targetBundle) {
this(null, targetBundle);
}
-
+
/**
- * Initializes me to capture logs from the specified command stack. The
- * implicit bundle to listen for logs is this test plug-in.
- *
+ * Initializes me to capture logs from the specified command stack. The implicit
+ * bundle to listen for logs is this test plug-in.
+ *
* @param stack the command stack to listen to
*/
public LogCapture(TransactionalCommandStack stack) {
this(stack, TestsPlugin.instance.getBundle());
}
-
+
/**
* Initializes me to capture logs from the specified bundle and attach an
* exception handler to the specified command stack.
- *
- * @param stack the command stack to handle
+ *
+ * @param stack the command stack to handle
* @param targetBundle the bundle for which to listen for logs
*/
public LogCapture(TransactionalCommandStack stack, Bundle targetBundle) {
this.targetBundle = targetBundle;
this.stack = stack;
-
+
if (stack != null) {
stack.setExceptionHandler(new ExceptionHandler() {
+ @Override
public void handleException(Exception e) {
if (e instanceof RollbackException) {
TestsPlugin.instance.getLog().log(((RollbackException) e).getStatus());
} else {
- TestsPlugin.instance.getLog().log(new Status(
- IStatus.ERROR,
- TestsPlugin.instance.getBundle().getSymbolicName(),
- 1,
- "Uncaught exception", //$NON-NLS-1$
- e));
+ TestsPlugin.instance.getLog().log(new Status(IStatus.ERROR,
+ TestsPlugin.instance.getBundle().getSymbolicName(), 1, "Uncaught exception", e));
}
- }});
+ }
+ });
}
-
+
Platform.addLogListener(listener);
}
-
+
/**
* Stops me, detaching my log listener from the platform.
*/
public void stop() {
Platform.removeLogListener(listener);
-
+
if (stack != null) {
stack.setExceptionHandler(null);
}
}
-
+
/**
* Gets the last log, if any, from my target bundle.
- *
+ *
* @return the last log, or null if none
*/
public IStatus getLastLog() {
return lastLog;
}
-
+
/**
* Obtains the list of logs from my target bundle.
- *
+ *
* @return a list (possibly empty) of {@link IStatus}es
*/
public List getLogs() {
return logs;
}
-
+
/**
* Asserts that I captured a status that logged the specified throwable.
- *
+ *
* @param throwable a throwable that should have been logged
*/
public void assertLogged(Throwable throwable) {
- IStatus log = getLastLog();
- Assert.assertNotNull(log);
- log = findStatus(log, throwable);
- Assert.assertNotNull(log);
+ IStatus log = getLastLog();
+ assertNotNull(log);
+ log = findStatus(log, throwable);
+ assertNotNull(log);
}
-
+
private void record(IStatus log) {
logs.add(log);
lastLog = log;
}
-
+
/**
- * Finds the status in a (potentially multi-) status that carries the
- * specified exception.
- *
- * @param status a status
+ * Finds the status in a (potentially multi-) status that carries the specified
+ * exception.
+ *
+ * @param status a status
* @param exception a throwable to look for
- *
+ *
* @return the matching status, or null if not found
*/
private IStatus findStatus(IStatus status, Throwable exception) {
- IStatus result = (status.getException() == exception)? status : null;
+ IStatus result = (status.getException() == exception) ? status : null;
if (status.isMultiStatus()) {
IStatus[] children = status.getChildren();
-
+
for (int i = 0; (result == null) && (i < children.length); i++) {
result = findStatus(children[i], exception);
}
}
-
+
return result;
}
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/NonEMFCompositeOperation.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/NonEMFCompositeOperation.java
index 376c9217..412a5abe 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/NonEMFCompositeOperation.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/NonEMFCompositeOperation.java
@@ -25,28 +25,24 @@
import org.eclipse.core.runtime.SubProgressMonitor;
/**
- * Example implementation of a non-EMF composite that might contain nested
- * EMF operations.
+ * Example implementation of a non-EMF composite that might contain nested EMF
+ * operations.
*
* @author Christian W. Damus (cdamus)
*/
-public class NonEMFCompositeOperation
- extends AbstractOperation
- implements ICompositeOperation {
-
- private final List children = new java.util.ArrayList();
-
+public class NonEMFCompositeOperation extends AbstractOperation implements ICompositeOperation {
+
+ private final List children = new java.util.ArrayList<>();
+
public NonEMFCompositeOperation() {
- super("Non-EMF Composite"); //$NON-NLS-1$
+ super("Non-EMF Composite");
}
-
- // Documentation copied from the inherited specification
+
@Override
- public IStatus execute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
monitor.beginTask(getLabel(), children.size());
-
+
try {
for (IUndoableOperation next : children) {
next.execute(new SubProgressMonitor(monitor, 1), info);
@@ -54,17 +50,15 @@ public IStatus execute(IProgressMonitor monitor, IAdaptable info)
} finally {
monitor.done();
}
-
+
return Status.OK_STATUS;
}
- // Documentation copied from the inherited specification
@Override
- public IStatus redo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
monitor.beginTask(getLabel(), children.size());
-
+
try {
for (IUndoableOperation next : children) {
next.redo(new SubProgressMonitor(monitor, 1), info);
@@ -72,33 +66,32 @@ public IStatus redo(IProgressMonitor monitor, IAdaptable info)
} finally {
monitor.done();
}
-
+
return Status.OK_STATUS;
}
- // Documentation copied from the inherited specification
@Override
- public IStatus undo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
monitor.beginTask(getLabel(), children.size());
-
+
try {
- for (ListIterator iter = children.listIterator(children.size());
- iter.hasPrevious();) {
+ for (ListIterator iter = children.listIterator(children.size()); iter.hasPrevious();) {
iter.previous().undo(new SubProgressMonitor(monitor, 1), info);
}
} finally {
monitor.done();
}
-
+
return Status.OK_STATUS;
}
+ @Override
public void add(IUndoableOperation operation) {
children.add(operation);
}
-
+
+ @Override
public void remove(IUndoableOperation operation) {
children.remove(operation);
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/NullCommand.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/NullCommand.java
index 2329e414..ca38c7a6 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/NullCommand.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/NullCommand.java
@@ -24,12 +24,13 @@ public class NullCommand extends AbstractCommand {
protected boolean prepare() {
return true;
}
-
+
/** Does nothing. */
+ @Override
public void execute() {
// nothing to do
}
-
+
/** Does nothing. */
@Override
public void undo() {
@@ -37,6 +38,7 @@ public void undo() {
}
/** Does nothing. */
+ @Override
public void redo() {
// nothing to do
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/NullOperation.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/NullOperation.java
index 88825efc..3d7329ea 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/NullOperation.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/NullOperation.java
@@ -27,60 +27,54 @@ public class NullOperation extends AbstractOperation {
private final boolean isExecutable;
private final boolean isUndoable;
private final boolean isRedoable;
-
+
public NullOperation() {
this(true, true, true);
}
-
+
public NullOperation(boolean isExecutable) {
this(isExecutable, true, true);
}
-
+
public NullOperation(boolean isExecutable, boolean isUndoable) {
this(isExecutable, isUndoable, true);
}
-
+
public NullOperation(boolean isExecutable, boolean isUndoable, boolean isRedoable) {
- super("Null"); //$NON-NLS-1$
+ super("Null");
this.isExecutable = isExecutable;
this.isUndoable = isUndoable;
this.isRedoable = isRedoable;
}
-
+
@Override
public boolean canExecute() {
return isExecutable;
}
-
+
@Override
public boolean canUndo() {
return isUndoable;
}
-
+
@Override
public boolean canRedo() {
return isRedoable;
}
-
- // Documentation copied from the inherited specification
+
@Override
- public IStatus execute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
- // Documentation copied from the inherited specification
@Override
- public IStatus redo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
- // Documentation copied from the inherited specification
@Override
- public IStatus undo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/SelfOpeningEMFCompositeOperation.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/SelfOpeningEMFCompositeOperation.java
index c14ebad1..74b7432f 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/SelfOpeningEMFCompositeOperation.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/SelfOpeningEMFCompositeOperation.java
@@ -31,98 +31,92 @@
* Example implementation of an EMF operation that implements the operation
* history's notion of an "open composite." This additionally has the property
* of being self-opening (it opens itself when it is executed).
- *
+ *
* @author Christian W. Damus (cdamus)
*/
-public class SelfOpeningEMFCompositeOperation
- extends AbstractEMFOperation
- implements ICompositeOperation {
-
- private final List children = new java.util.ArrayList();
-
- public SelfOpeningEMFCompositeOperation(TransactionalEditingDomain domain) {
- super(domain, "EMF Composite"); //$NON-NLS-1$
- }
-
- @Override
- protected final IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
- IStatus result;
-
- IOperationHistory history = ((IWorkspaceCommandStack) getEditingDomain()
- .getCommandStack()).getOperationHistory();
-
- // open myself
- history.openOperation(this, IOperationHistory.EXECUTE);
-
- try {
- result = doExecute(history, monitor, info);
-
- history.closeOperation(true, false, IOperationHistory.EXECUTE);
- } catch (RuntimeException e) {
- history.closeOperation(false, false, IOperationHistory.EXECUTE);
- throw e;
- }
-
- return result;
- }
-
- /**
- * Overridden by subclasses to do stuff, usually including nested executions
- * of operations on the supplied history.
- *
- * @param history
- * the history on which I am open and executing
- * @param monitor
- * a progress monitor
- * @param info
- * an info or null
- *
- * @return status of delegated execution
- * @throws ExecutionException
- * if necessary
- */
- protected IStatus doExecute(IOperationHistory history,
- IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
- return Status.OK_STATUS;
- }
-
- public void add(IUndoableOperation operation) {
- children.add(operation);
- updateContexts();
- }
-
- public void remove(IUndoableOperation operation) {
- children.remove(operation);
- updateContexts();
- }
-
- /**
- * Obtains the children that have been added to me by nested executions.
- *
- * @return my children
- */
- public List getChildren() {
- return children;
- }
-
- private void updateContexts() {
- IUndoContext[] current = getContexts();
- for (int i = 0; i < current.length; i++) {
- removeContext(current[i]);
- }
-
- Set newContexts = new java.util.HashSet();
- for (IUndoableOperation child : children) {
- IUndoContext[] next = child.getContexts();
- for (IUndoContext ctx : next) {
- if (!newContexts.add(ctx)) {
- addContext(ctx);
- }
- }
- }
- }
+public class SelfOpeningEMFCompositeOperation extends AbstractEMFOperation implements ICompositeOperation {
+
+ private final List children = new java.util.ArrayList<>();
+
+ public SelfOpeningEMFCompositeOperation(TransactionalEditingDomain domain) {
+ super(domain, "EMF Composite");
+ }
+
+ @Override
+ protected final IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ IStatus result;
+
+ IOperationHistory history = ((IWorkspaceCommandStack) getEditingDomain().getCommandStack())
+ .getOperationHistory();
+
+ // open myself
+ history.openOperation(this, IOperationHistory.EXECUTE);
+
+ try {
+ result = doExecute(history, monitor, info);
+
+ history.closeOperation(true, false, IOperationHistory.EXECUTE);
+ } catch (RuntimeException e) {
+ history.closeOperation(false, false, IOperationHistory.EXECUTE);
+ throw e;
+ }
+
+ return result;
+ }
+
+ /**
+ * Overridden by subclasses to do stuff, usually including nested executions of
+ * operations on the supplied history.
+ *
+ * @param history the history on which I am open and executing
+ * @param monitor a progress monitor
+ * @param info an info or null
+ *
+ * @return status of delegated execution
+ * @throws ExecutionException if necessary
+ */
+ protected IStatus doExecute(IOperationHistory history, IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+
+ return Status.OK_STATUS;
+ }
+
+ @Override
+ public void add(IUndoableOperation operation) {
+ children.add(operation);
+ updateContexts();
+ }
+
+ @Override
+ public void remove(IUndoableOperation operation) {
+ children.remove(operation);
+ updateContexts();
+ }
+
+ /**
+ * Obtains the children that have been added to me by nested executions.
+ *
+ * @return my children
+ */
+ public List getChildren() {
+ return children;
+ }
+
+ private void updateContexts() {
+ IUndoContext[] current = getContexts();
+ for (IUndoContext element : current) {
+ removeContext(element);
+ }
+
+ Set newContexts = new java.util.HashSet<>();
+ for (IUndoableOperation child : children) {
+ IUndoContext[] next = child.getContexts();
+ for (IUndoContext ctx : next) {
+ if (!newContexts.add(ctx)) {
+ addContext(ctx);
+ }
+ }
+ }
+ }
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestCommand.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestCommand.java
index d2650028..9d84a0f3 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestCommand.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestCommand.java
@@ -16,33 +16,31 @@
/**
* A simple abstract command requiring subclasses to implement only the
- * {@link org.eclipse.emf.common.command.Command#execute()} method.
- * Does not implement redo.
+ * {@link org.eclipse.emf.common.command.Command#execute()} method. Does not
+ * implement redo.
*
* @author Christian W. Damus (cdamus)
*/
-public abstract class TestCommand
- extends AbstractCommand {
+public abstract class TestCommand extends AbstractCommand {
@Override
protected boolean prepare() {
return true;
}
-
+
@Override
public void undo() {
// do nothing
}
-
+
+ @Override
public void redo() {
// do nothing
}
-
- public static abstract class Redoable
- extends TestCommand
- implements ConditionalRedoCommand {
-
-
+
+ public static abstract class Redoable extends TestCommand implements ConditionalRedoCommand {
+
+ @Override
public boolean canRedo() {
return true;
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestListener.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestListener.java
index 4a454cea..a3a6a620 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestListener.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestListener.java
@@ -26,10 +26,10 @@
public class TestListener extends ResourceSetListenerImpl {
/** The last pre-commit event received. */
public ResourceSetChangeEvent precommit;
-
+
/** The last post-commit event received. */
public ResourceSetChangeEvent postcommit;
-
+
public TestListener() {
super(NotificationFilter.ANY);
}
@@ -37,21 +37,20 @@ public TestListener() {
public TestListener(NotificationFilter filter) {
super(filter);
}
-
+
@Override
- public Command transactionAboutToCommit(ResourceSetChangeEvent event)
- throws RollbackException {
-
+ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
+
precommit = event;
-
+
return null;
}
-
+
@Override
public void resourceSetChanged(ResourceSetChangeEvent event) {
postcommit = event;
}
-
+
/**
* Clears the stored events.
*/
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestOperation.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestOperation.java
index ab1bb884..343af828 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestOperation.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestOperation.java
@@ -27,33 +27,32 @@
*
* @author Christian W. Damus (cdamus)
*/
-public abstract class TestOperation
- extends AbstractEMFOperation {
+public abstract class TestOperation extends AbstractEMFOperation {
private IStatus status = Status.OK_STATUS;
-
+
public TestOperation(TransactionalEditingDomain domain) {
- super(domain, "Testing"); //$NON-NLS-1$
+ super(domain, "Testing");
}
public TestOperation(TransactionalEditingDomain domain, Map, ?> options) {
- super(domain, "Testing", options); //$NON-NLS-1$
+ super(domain, "Testing", options);
}
@Override
protected final IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
doExecute();
-
+
return getStatus();
}
-
+
protected final IStatus getStatus() {
return status;
}
-
+
protected final void setStatus(IStatus status) {
this.status = status;
}
-
+
protected abstract void doExecute() throws ExecutionException;
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestPackageBuilder.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestPackageBuilder.java
index 78624b64..4f68f6ac 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestPackageBuilder.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestPackageBuilder.java
@@ -5,7 +5,7 @@
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* Christian W. Damus - Initial API and implementation
*/
@@ -25,10 +25,9 @@
* The package is a dynamically created EPackage, is registered with the package
* registry, and should be {@linkplain #dispose() disposed} at the conclusion of
* the test.
- *
+ *
* @author Christian W. Damus (cdamus)
*/
-@SuppressWarnings("nls")
public class TestPackageBuilder {
protected EPackage package_;
@@ -42,7 +41,7 @@ public TestPackageBuilder() {
/**
* Obtains my package, building it first if necessary.
- *
+ *
* @return my package
*/
public EPackage getPackage() {
@@ -52,15 +51,15 @@ public EPackage getPackage() {
return package_;
}
-
+
public EClass getA() {
return (EClass) getPackage().getEClassifier("A");
}
-
+
public EClass getB() {
return (EClass) getPackage().getEClassifier("B");
}
-
+
public EReference getA_b() {
return (EReference) getA().getEStructuralFeature("b");
}
@@ -73,8 +72,7 @@ public void dispose() {
EPackage.Registry.INSTANCE.remove(package_.getNsURI());
// dispose the package
- for (Iterator iter = package_.eAllContents(); iter
- .hasNext();) {
+ for (Iterator iter = package_.eAllContents(); iter.hasNext();) {
iter.next().eAdapters().clear();
}
package_.eAdapters().clear();
@@ -88,12 +86,12 @@ protected void buildPackage() {
package_.setName("emfwbtestpkg");
package_.setNsPrefix("wbtest");
package_.setNsURI("http://www.eclipse.org/emf/test/WorkbenchTestPackage");
-
+
EClass a = eClass("A");
EClass b = eClass("B");
-
+
crossReference(a, "b", b, true, true);
-
+
// register the package
EPackage.Registry.INSTANCE.put(package_.getNsURI(), package_);
}
@@ -105,23 +103,19 @@ protected EClass eClass(String name) {
return result;
}
- protected EReference crossReference(EClass owner, String name, EClass type,
- boolean isMany, boolean unsettable) {
+ protected EReference crossReference(EClass owner, String name, EClass type, boolean isMany, boolean unsettable) {
- return eReference(owner, name, type, 0,
- ETypedElement.UNBOUNDED_MULTIPLICITY, false, unsettable);
+ return eReference(owner, name, type, 0, ETypedElement.UNBOUNDED_MULTIPLICITY, false, unsettable);
}
- protected EReference containment(EClass owner, String name, EClass type,
- boolean isMany) {
+ protected EReference containment(EClass owner, String name, EClass type, boolean isMany) {
- return eReference(owner, name, type, 0,
- ETypedElement.UNBOUNDED_MULTIPLICITY, true, false);
+ return eReference(owner, name, type, 0, ETypedElement.UNBOUNDED_MULTIPLICITY, true, false);
}
- protected EReference eReference(EClass owner, String name, EClass type,
- int lower, int upper, boolean containment, boolean unsettable) {
-
+ protected EReference eReference(EClass owner, String name, EClass type, int lower, int upper, boolean containment,
+ boolean unsettable) {
+
EReference result = EcoreFactory.eINSTANCE.createEReference();
result.setName(name);
owner.getEStructuralFeatures().add(result);
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestUndoContext.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestUndoContext.java
index 769fb1ff..73fcca36 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestUndoContext.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/TestUndoContext.java
@@ -20,17 +20,12 @@
*/
public class TestUndoContext implements IUndoContext {
- /**
- * Initializes me.
- */
- public TestUndoContext() {
- super();
- }
-
+ @Override
public String getLabel() {
- return "Testing"; //$NON-NLS-1$
+ return "Testing";
}
+ @Override
public boolean matches(IUndoContext context) {
return context == this;
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/OperationChangeDescriptionTest.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/OperationChangeDescriptionTest.java
index 80a97df1..afdff971 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/OperationChangeDescriptionTest.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/OperationChangeDescriptionTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2005, 2007 IBM Corporation and others.
+ * Copyright (c) 2005, 2026 IBM Corporation and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
@@ -11,125 +11,123 @@
*/
package org.eclipse.emf.workspace.util.tests;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.workspace.tests.fixtures.ExternalDataOperation;
import org.eclipse.emf.workspace.util.OperationChangeDescription;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Tests the {@link OperationChangeDescription} class.
*
* @author Christian W. Damus (cdamus)
*/
-public class OperationChangeDescriptionTest extends TestCase {
-
- private String externalData[];
+public class OperationChangeDescriptionTest {
+
+ private String[] externalData;
private String initialValue;
private String newValue;
private IUndoableOperation operation;
private OperationChangeDescription change;
-
- public OperationChangeDescriptionTest(String name) {
- super(name);
- }
- public static Test suite() {
- return new TestSuite(OperationChangeDescriptionTest.class, "Operation Change Tests"); //$NON-NLS-1$
- }
-
/**
- * Tests that no EMF changes are provided, though the API contract of the
- * change description is satisfied.
+ * Tests that no EMF changes are provided, though the API contract of the change
+ * description is satisfied.
*/
+ @Test
public void test_emfChanges() {
assertTrue(change.getObjectChanges().isEmpty());
assertTrue(change.getResourceChanges().isEmpty());
assertTrue(change.getObjectsToAttach().isEmpty());
assertTrue(change.getObjectsToDetach().isEmpty());
}
-
+
/**
* Tests the canApply() method.
*/
+ @Test
public void test_canApply() {
assertTrue(change.canApply());
}
-
+
/**
* Tests the apply() method.
*/
+ @Test
public void test_apply() {
change.apply();
-
+
assertEquals(initialValue, externalData[0]);
-
+
// can no longer apply because we forgot our operation
assertFalse(change.canApply());
}
-
+
/**
* Tests the applyAndReverse() method.
*/
+ @Test
public void test_applyAndReverse() {
change.applyAndReverse();
-
+
assertEquals(initialValue, externalData[0]);
assertTrue(change.canApply());
-
+
change.applyAndReverse();
-
+
assertEquals(newValue, externalData[0]);
assertTrue(change.canApply());
-
+
change.applyAndReverse();
-
+
assertEquals(initialValue, externalData[0]);
assertTrue(change.canApply());
}
-
+
//
// Fixture methods
//
-
- @Override
- protected void setUp()
- throws Exception {
-
- initialValue = "Initial value"; //$NON-NLS-1$
- newValue = "New value"; //$NON-NLS-1$
- externalData = new String[] {initialValue};
+
+ @BeforeEach
+ public void setUp() throws Exception {
+
+ initialValue = "Initial value";
+ newValue = "New value";
+ externalData = new String[] { initialValue };
operation = new ExternalDataOperation(externalData, newValue);
operation.execute(new NullProgressMonitor(), null);
change = new OperationChangeDescription(operation, null);
-
+
assertEquals(newValue, externalData[0]);
}
-
- @Override
- protected void tearDown()
- throws Exception {
-
+
+ @AfterEach
+ public void tearDown() throws Exception {
+
externalData = null;
operation = null;
change = null;
initialValue = null;
newValue = null;
}
-
+
/**
* Records a failure due to an exception that should not have been thrown.
- *
+ *
* @param e the exception
*/
protected void fail(Exception e) {
e.printStackTrace();
- fail("Should not have thrown: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assertions.fail("Should not have thrown: " + e.getLocalizedMessage());
}
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/ResourceUndoContextTest.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/ResourceUndoContextTest.java
index bc96052a..1d866da5 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/ResourceUndoContextTest.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/ResourceUndoContextTest.java
@@ -12,14 +12,14 @@
*/
package org.eclipse.emf.workspace.util.tests;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.util.Collections;
import java.util.List;
import java.util.Set;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.eclipse.core.commands.operations.DefaultOperationHistory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.EList;
@@ -41,291 +41,286 @@
import org.eclipse.emf.workspace.ResourceUndoContext;
import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory;
import org.eclipse.emf.workspace.tests.fixtures.TestPackageBuilder;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Tests the {@link ResourceUndoContext} class.
*
* @author Christian W. Damus (cdamus)
*/
-public class ResourceUndoContextTest extends TestCase {
-
+public class ResourceUndoContextTest {
+
private ResourceUndoContext ctx1;
private ResourceUndoContext ctx2;
private ResourceUndoContext ctx3;
-
+
private Resource res1;
private Resource res2;
private Resource res3;
-
+
private Listener listener;
-
- private TestPackageBuilder packageBuilder;
-
- public ResourceUndoContextTest(String name) {
- super(name);
- }
- public static Test suite() {
- return new TestSuite(ResourceUndoContextTest.class, "Resource Undo Context Tests"); //$NON-NLS-1$
- }
+ private TestPackageBuilder packageBuilder;
/**
* Tests the matching of contexts.
*/
+ @Test
public void test_matches() {
assertFalse(ctx1.matches(ctx3));
assertTrue(ctx2.matches(ctx3));
}
-
+
/**
* Tests the analysis of an attribute.
*/
+ @Test
public void test_getAffectedResources_attribute() {
Library library = EXTLibraryFactory.eINSTANCE.createLibrary();
res1.getContents().add(library);
-
+
// forget the events so far
listener.notifications.clear();
-
- library.setName("Foo"); //$NON-NLS-1$
-
+
+ library.setName("Foo");
+
assertFalse(listener.notifications.isEmpty());
-
- Set affected = ResourceUndoContext.getAffectedResources(
- listener.notifications);
-
+
+ Set affected = ResourceUndoContext.getAffectedResources(listener.notifications);
+
assertEquals(Collections.singleton(res1), affected);
}
-
+
/**
* Tests the analysis of a unidirectional reference within the same resource.
*/
+ @Test
public void test_getAffectedResources_localRef() {
Library library = EXTLibraryFactory.eINSTANCE.createLibrary();
res1.getContents().add(library);
-
+
BookOnTape book = EXTLibraryFactory.eINSTANCE.createBookOnTape();
library.getStock().add(book);
-
+
Employee person = EXTLibraryFactory.eINSTANCE.createEmployee();
library.getEmployees().add(person);
-
+
// forget the events so far
listener.notifications.clear();
-
+
book.setReader(person);
-
+
assertFalse(listener.notifications.isEmpty());
-
- Set affected = ResourceUndoContext.getAffectedResources(
- listener.notifications);
-
+
+ Set affected = ResourceUndoContext.getAffectedResources(listener.notifications);
+
assertEquals(Collections.singleton(res1), affected);
}
-
+
/**
* Tests the analysis of a bidirectional reference across resources.
*/
+ @Test
public void test_getAffectedResources_remoteRef_bidirectional() {
Library library1 = EXTLibraryFactory.eINSTANCE.createLibrary();
res1.getContents().add(library1);
-
+
Library library2 = EXTLibraryFactory.eINSTANCE.createLibrary();
res2.getContents().add(library2);
-
+
Book book = EXTLibraryFactory.eINSTANCE.createBook();
library1.getStock().add(book);
-
+
Writer writer = EXTLibraryFactory.eINSTANCE.createWriter();
library2.getWriters().add(writer);
-
+
// forget the events so far
listener.notifications.clear();
-
+
book.setAuthor(writer);
-
+
assertFalse(listener.notifications.isEmpty());
-
- Set affected = ResourceUndoContext.getAffectedResources(
- listener.notifications);
-
- Set expected = new java.util.HashSet();
+
+ Set affected = ResourceUndoContext.getAffectedResources(listener.notifications);
+
+ Set expected = new java.util.HashSet<>();
expected.add(res1);
expected.add(res2);
-
+
assertEquals(expected, affected);
}
-
+
/**
* Tests the analysis of a unidirectional reference across resources.
*/
+ @Test
public void test_getAffectedResources_remoteRef_unidirectional() {
Library library1 = EXTLibraryFactory.eINSTANCE.createLibrary();
res1.getContents().add(library1);
-
+
Library library2 = EXTLibraryFactory.eINSTANCE.createLibrary();
res2.getContents().add(library2);
-
+
BookOnTape book = EXTLibraryFactory.eINSTANCE.createBookOnTape();
library1.getStock().add(book);
-
+
Employee person = EXTLibraryFactory.eINSTANCE.createEmployee();
library2.getEmployees().add(person);
-
+
// forget the events so far
listener.notifications.clear();
-
+
book.setReader(person);
-
+
assertFalse(listener.notifications.isEmpty());
-
- Set affected = ResourceUndoContext.getAffectedResources(
- listener.notifications);
-
- Set expected = new java.util.HashSet();
+
+ Set affected = ResourceUndoContext.getAffectedResources(listener.notifications);
+
+ Set expected = new java.util.HashSet<>();
expected.add(res1);
expected.add(res2);
-
+
assertEquals(expected, affected);
}
-
+
/**
- * Tests the analysis of notifications from detached objects, to avoid
- * adding resource contexts with null resources.
+ * Tests the analysis of notifications from detached objects, to avoid adding
+ * resource contexts with null resources.
*/
+ @Test
public void test_getAffectedResources_deletedElement_126113() {
Library library1 = EXTLibraryFactory.eINSTANCE.createLibrary();
res1.getContents().add(library1);
-
+
Library library2 = EXTLibraryFactory.eINSTANCE.createLibrary();
res2.getContents().add(library2);
-
+
BookOnTape book = EXTLibraryFactory.eINSTANCE.createBookOnTape();
library1.getStock().add(book);
-
+
Employee person = EXTLibraryFactory.eINSTANCE.createEmployee();
library2.getEmployees().add(person);
-
+
book.setReader(person);
-
+
// forget the events so far
listener.notifications.clear();
library2.getEmployees().remove(person);
- book.setReader(null); // this caused the null resource context
-
+ book.setReader(null); // this caused the null resource context
+
assertFalse(listener.notifications.isEmpty());
-
- Set affected = ResourceUndoContext.getAffectedResources(
- listener.notifications);
-
- Set expected = new java.util.HashSet();
+
+ Set affected = ResourceUndoContext.getAffectedResources(listener.notifications);
+
+ Set expected = new java.util.HashSet<>();
expected.add(res1);
expected.add(res2);
-
+
assertEquals(expected, affected);
assertFalse(affected.contains(null));
}
-
+
+ @Test
public void test_unsettableManyReference_264220() {
EFactory factory = packageBuilder.getPackage().getEFactoryInstance();
-
+
EObject anA = factory.create(packageBuilder.getA());
EObject aB = factory.create(packageBuilder.getB());
EObject anotherB = factory.create(packageBuilder.getB());
-
+
anA.eAdapters().add(listener);
res1.getContents().add(aB);
res2.getContents().add(anotherB);
-
+
// do some linking of objects
@SuppressWarnings("unchecked")
EList bs = (EList) anA.eGet(packageBuilder.getA_b());
bs.add(aB);
bs.add(anotherB);
-
+
// start over with the event gathering, on a clean slate
listener.notifications.clear();
// now, unset the unsettable reference
anA.eUnset(packageBuilder.getA_b());
-
+
try {
- Set expectedResources = new java.util.HashSet();
+ Set expectedResources = new java.util.HashSet<>();
expectedResources.add(res1);
expectedResources.add(res2);
- assertEquals(expectedResources, IResourceUndoContextPolicy.DEFAULT
- .getContextResources(null, listener.notifications));
+ assertEquals(expectedResources,
+ IResourceUndoContextPolicy.DEFAULT.getContextResources(null, listener.notifications));
} catch (ClassCastException e) {
- fail("Should not get CCE in the resource undo-context policy"); //$NON-NLS-1$
+ Assertions.fail("Should not get CCE in the resource undo-context policy");
}
}
-
+
//
// Fixture methods
//
-
- @Override
- protected void setUp()
- throws Exception {
-
- TransactionalEditingDomain domain =
- WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain(
- new DefaultOperationHistory());
-
+
+ @BeforeEach
+ public void setUp() {
+
+ TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE
+ .createEditingDomain(new DefaultOperationHistory());
+
res1 = new ResourceImpl();
res2 = new ResourceImpl();
res3 = new ResourceImpl();
-
+
ctx1 = new ResourceUndoContext(domain, res1);
ctx2 = new ResourceUndoContext(domain, res2);
ctx3 = new ResourceUndoContext(domain, res2); // not res3
-
+
ResourceSet rset = new ResourceSetImpl();
rset.getResources().add(res1);
rset.getResources().add(res2);
rset.getResources().add(res3);
-
+
listener = new Listener();
rset.eAdapters().add(listener);
-
+
packageBuilder = new TestPackageBuilder();
}
-
- @Override
- protected void tearDown()
- throws Exception {
-
+
+ @AfterEach
+ public void tearDown() {
+
packageBuilder.dispose();
-
+
listener = null;
-
+
res1 = null;
res2 = null;
res3 = null;
-
+
ctx1 = null;
ctx2 = null;
ctx3 = null;
}
-
+
/**
* Records a failure due to an exception that should not have been thrown.
- *
+ *
* @param e the exception
*/
protected void fail(Exception e) {
e.printStackTrace();
- fail("Should not have thrown: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assertions.fail("Should not have thrown: " + e.getLocalizedMessage());
}
-
+
private static class Listener extends EContentAdapter {
- final List notifications = new java.util.ArrayList();
-
+ final List notifications = new java.util.ArrayList<>();
+
@Override
public void notifyChanged(Notification notification) {
notifications.add(notification);
-
+
super.notifyChanged(notification);
}
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/ValidateEditTest.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/ValidateEditTest.java
index c7183410..c431c1f3 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/ValidateEditTest.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/ValidateEditTest.java
@@ -11,10 +11,12 @@
*/
package org.eclipse.emf.workspace.util.tests;
-import java.util.Collections;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import java.util.Collections;
import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.runtime.CoreException;
@@ -27,7 +29,8 @@
import org.eclipse.emf.workspace.tests.AbstractTest;
import org.eclipse.emf.workspace.tests.fixtures.TestCommand;
import org.eclipse.emf.workspace.util.WorkspaceValidateEditSupport;
-
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests validate-edit support.
@@ -35,126 +38,118 @@
* @author Christian W. Damus (cdamus)
*/
public class ValidateEditTest extends AbstractTest {
-
- private static final String newTitle = "New Title"; //$NON-NLS-1$
-
- private Book book;
-
- private final Command cmd = new TestCommand() {
- public void execute() {
- try {
- book.setTitle(newTitle);
- } catch (Exception e) {
- fail(e);
- }
- }};
-
- public ValidateEditTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(ValidateEditTest.class, "Validate-Edit Support Tests"); //$NON-NLS-1$
- }
+
+ private static final String newTitle = "New Title";
+
+ private Book book;
+
+ private final Command cmd = new TestCommand() {
+ public void execute() {
+ try {
+ book.setTitle(newTitle);
+ } catch (Exception e) {
+ fail(e);
+ }
+ }
+ };
/**
- * A control test for a scenario in which validateEdit will find all
- * resources to be modifiable.
+ * A control test for a scenario in which validateEdit will find all resources
+ * to be modifiable.
*/
+ @Test
public void test_noValidateEditRequired() {
- try {
- getCommandStack().execute(cmd, null);
-
- assertTitleChanged();
- assertResourceDirty();
- } catch (Exception e) {
- fail(e);
- }
+ try {
+ getCommandStack().execute(cmd, null);
+
+ assertTitleChanged();
+ assertResourceDirty();
+ } catch (Exception e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Simple unmodifiable resource scenario.
+ */
+ public void ignore_test_validateEditRollback() {
+ setResourceReadOnly();
+
+ try {
+ getCommandStack().execute(cmd, null);
+
+ Assertions.fail("Should have rolled back");
+ } catch (RollbackException e) {
+ // success
+ System.out.println("Got expected exception: " + e.getLocalizedMessage());
+ } catch (Exception e) {
+ fail(e);
+ }
+
+ assertTitleNotChanged();
+ assertResourceNotDirty();
}
- /**
- * Simple unmodifiable resource scenario.
- */
- public void ignore_test_validateEditRollback() {
- setResourceReadOnly();
-
- try {
- getCommandStack().execute(cmd, null);
-
- fail("Should have rolled back"); //$NON-NLS-1$
- } catch (RollbackException e) {
- // success
- System.out.println("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
- } catch (Exception e) {
- fail(e);
- }
-
- assertTitleNotChanged();
- assertResourceNotDirty();
- }
-
//
// Fixture methods
//
-
+
@Override
- protected void doSetUp()
- throws Exception {
-
+ protected void doSetUp() throws Exception {
+
super.doSetUp();
-
+
setValidateEdit();
-
+
// workspace validate-edit implementation depends on mod tracking
testResource.setTrackingModification(true);
-
- startReading();
- book = (Book) find("root/Root Book"); //$NON-NLS-1$
- commit();
- assertNotNull(book);
+
+ startReading();
+ book = (Book) find("root/Root Book");
+ commit();
+ assertNotNull(book);
}
-
+
@Override
- protected void doTearDown()
- throws Exception {
-
+ protected void doTearDown() throws Exception {
+
book = null;
-
+
super.doTearDown();
}
-
+
void setResourceReadOnly() {
- ResourceAttributes attr = new ResourceAttributes();
- attr.setReadOnly(true);
-
- try {
- file.setResourceAttributes(attr);
- } catch (CoreException e) {
- fail(e);
- }
+ ResourceAttributes attr = new ResourceAttributes();
+ attr.setReadOnly(true);
+
+ try {
+ file.setResourceAttributes(attr);
+ } catch (CoreException e) {
+ fail(e);
+ }
}
-
+
void setValidateEdit() {
- TransactionalEditingDomain.DefaultOptions defaults = TransactionUtil
- .getAdapter(domain, TransactionalEditingDomain.DefaultOptions.class);
-
- defaults.setDefaultTransactionOptions(Collections.singletonMap(
- Transaction.OPTION_VALIDATE_EDIT, new WorkspaceValidateEditSupport()));
+ TransactionalEditingDomain.DefaultOptions defaults = TransactionUtil.getAdapter(domain,
+ TransactionalEditingDomain.DefaultOptions.class);
+
+ defaults.setDefaultTransactionOptions(
+ Collections.singletonMap(Transaction.OPTION_VALIDATE_EDIT, new WorkspaceValidateEditSupport()));
}
-
+
void assertTitleChanged() {
- assertEquals(newTitle, book.getTitle());
+ assertEquals(newTitle, book.getTitle());
}
-
+
void assertTitleNotChanged() {
- assertFalse(newTitle.equals(book.getTitle()));
+ assertFalse(newTitle.equals(book.getTitle()));
}
-
+
void assertResourceDirty() {
- assertTrue("Resource not dirty", testResource.isModified()); //$NON-NLS-1$
+ assertTrue(testResource.isModified(), "Resource not dirty");
+ }
+
+ void assertResourceNotDirty() {
+ assertFalse(testResource.isModified(), "Resource is dirty");
}
-
- void assertResourceNotDirty() {
- assertFalse("Resource is dirty", testResource.isModified()); //$NON-NLS-1$
- }
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/WorkspaceSynchronizerTest.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/WorkspaceSynchronizerTest.java
index 322f132c..1d2abd74 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/WorkspaceSynchronizerTest.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/util/tests/WorkspaceSynchronizerTest.java
@@ -12,12 +12,14 @@
*/
package org.eclipse.emf.workspace.util.tests;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.util.List;
import java.util.Map;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResourceChangeEvent;
@@ -40,6 +42,8 @@
import org.eclipse.emf.workspace.internal.EMFWorkspacePlugin;
import org.eclipse.emf.workspace.tests.AbstractTest;
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests the {@link WorkspaceSynchronizer} class.
@@ -48,27 +52,20 @@
*/
@SuppressWarnings("nls")
public class WorkspaceSynchronizerTest extends AbstractTest {
-
+
private WorkspaceSynchronizer synch;
private TestDelegate delegate;
-
- public WorkspaceSynchronizerTest(String name) {
- super(name);
- }
- public static Test suite() {
- return new TestSuite(WorkspaceSynchronizerTest.class, "Workspace Synchronizer Tests"); //$NON-NLS-1$
- }
-
/**
* Tests the static getFile() utility method.
*/
+ @Test
public void test_getFile() {
IFile file = WorkspaceSynchronizer.getFile(testResource);
-
+
assertNotNull(file);
assertTrue(file.exists());
-
+
URI uri = testResource.getURI();
assertEquals(file.getName(), uri.segment(uri.segmentCount() - 1));
}
@@ -76,11 +73,12 @@ public void test_getFile() {
/**
* Tests the static getUnderlyingFile() utility method.
*/
+ @Test
public void test_getUnderlyingFile_163291() {
Resource archiveResource = new ResourceImpl();
archiveResource.setURI(URI.createURI("archive:platform:/resource" + RESOURCE_NAME + "!/foo"));
IFile file = WorkspaceSynchronizer.getUnderlyingFile(archiveResource);
-
+
assertNotNull(file);
assertTrue(file.exists());
assertEquals(file, this.file);
@@ -88,7 +86,7 @@ public void test_getUnderlyingFile_163291() {
archiveResource = new ResourceImpl();
archiveResource.setURI(URI.createURI("archive:platform:/resource" + RESOURCE_NAME + "!/foo.zip!/goo"));
file = WorkspaceSynchronizer.getUnderlyingFile(archiveResource);
-
+
assertNotNull(file);
assertTrue(file.exists());
assertEquals(file, this.file);
@@ -96,52 +94,53 @@ public void test_getUnderlyingFile_163291() {
archiveResource = new ResourceImpl();
archiveResource.setURI(URI.createURI("archive:archive:platform:/resource" + RESOURCE_NAME + "!/foo.zip!/goo"));
file = WorkspaceSynchronizer.getUnderlyingFile(archiveResource);
-
+
assertNotNull(file);
assertTrue(file.exists());
assertEquals(file, this.file);
}
-
+
/**
* Tests the getFile() with file: URI.
*/
+ @Test
public void test_getFile_fileURI_156772() {
String path = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(RESOURCE_NAME).toString();
-
+
testResource.setURI(URI.createFileURI(path));
IFile file = WorkspaceSynchronizer.getFile(testResource);
-
+
assertNotNull(file);
assertTrue(file.exists());
-
+
URI uri = testResource.getURI();
assertEquals(file.getName(), uri.segment(uri.segmentCount() - 1));
}
-
+
/**
* Tests the getFile() with URI that can be normalized to a platform URI.
*/
+ @Test
public void test_getFile_normalization_156772() {
- testResource.getResourceSet().getURIConverter().getURIMap().put(
- URI.createURI("pathmap://FOO"), //$NON-NLS-1$
+ testResource.getResourceSet().getURIConverter().getURIMap().put(URI.createURI("pathmap://FOO"),
testResource.getURI().trimSegments(1));
-
+
IFile file = WorkspaceSynchronizer.getFile(testResource);
-
+
assertNotNull(file);
assertTrue(file.exists());
-
+
URI uri = testResource.getURI();
assertEquals(file.getName(), uri.segment(uri.segmentCount() - 1));
}
-
+
/**
- * Tests that resource deletion is correctly reported to the delegate to
- * handle.
+ * Tests that resource deletion is correctly reported to the delegate to handle.
*/
+ @Test
public void test_deletion() {
IFile file = WorkspaceSynchronizer.getFile(testResource);
-
+
try {
synchronized (delegate) {
file.delete(true, null);
@@ -150,19 +149,19 @@ public void test_deletion() {
} catch (Exception e) {
fail(e);
}
-
+
assertTrue(delegate.deletedResources.contains(testResource));
assertFalse(delegate.changedResources.contains(testResource));
assertFalse(delegate.movedResources.containsKey(testResource));
}
-
+
/**
- * Tests that resource change is correctly reported to the delegate to
- * handle.
+ * Tests that resource change is correctly reported to the delegate to handle.
*/
+ @Test
public void test_change() {
IFile file = WorkspaceSynchronizer.getFile(testResource);
-
+
try {
synchronized (delegate) {
file.touch(null);
@@ -171,21 +170,21 @@ public void test_change() {
} catch (Exception e) {
fail(e);
}
-
+
assertTrue(delegate.changedResources.contains(testResource));
assertFalse(delegate.deletedResources.contains(testResource));
assertFalse(delegate.movedResources.containsKey(testResource));
}
-
+
/**
- * Tests that resource move is correctly reported to the delegate to
- * handle (this is actually a rename scenario).
+ * Tests that resource move is correctly reported to the delegate to handle
+ * (this is actually a rename scenario).
*/
+ @Test
public void test_move() {
IFile file = WorkspaceSynchronizer.getFile(testResource);
- IPath newPath = file.getFullPath().removeLastSegments(1).append(
- "moveDestination.extlibrary"); //$NON-NLS-1$
-
+ IPath newPath = file.getFullPath().removeLastSegments(1).append("moveDestination.extlibrary");
+
try {
synchronized (delegate) {
file.move(newPath, true, null);
@@ -194,107 +193,104 @@ public void test_move() {
} catch (Exception e) {
fail(e);
}
-
+
assertFalse(delegate.changedResources.contains(testResource));
assertFalse(delegate.deletedResources.contains(testResource));
assertTrue(delegate.movedResources.containsKey(testResource));
- assertEquals(
- URI.createPlatformResourceURI(newPath.toString(), true),
+ assertEquals(URI.createPlatformResourceURI(newPath.toString(), true),
delegate.movedResources.get(testResource));
}
-
+
/**
- * Tests that multiple changes in the same editing domain are reported
- * correctly to the delegate.
+ * Tests that multiple changes in the same editing domain are reported correctly
+ * to the delegate.
*/
+ @Test
public void test_multipleChanges() {
final IFile file = WorkspaceSynchronizer.getFile(testResource);
final IFile[] copies = new IFile[2];
-
- final IPath copy1 = file.getFullPath().removeLastSegments(1).append(
- "copy1.extlibrary"); //$NON-NLS-1$
- final IPath copy2 = file.getFullPath().removeLastSegments(1).append(
- "copy2.extlibrary"); //$NON-NLS-1$
- final IPath newPath = file.getFullPath().removeLastSegments(1).append(
- "moveDestination.extlibrary"); //$NON-NLS-1$
-
- Job job = new WorkspaceJob("Modify Workspace") { //$NON-NLS-1$
+
+ final IPath copy1 = file.getFullPath().removeLastSegments(1).append("copy1.extlibrary");
+ final IPath copy2 = file.getFullPath().removeLastSegments(1).append("copy2.extlibrary");
+ final IPath newPath = file.getFullPath().removeLastSegments(1).append("moveDestination.extlibrary");
+
+ Job job = new WorkspaceJob("Modify Workspace") {
@Override
- public IStatus runInWorkspace(IProgressMonitor monitor)
- throws CoreException {
+ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
// make two copies
file.copy(copy1, true, null);
file.copy(copy2, true, null);
-
+
// store the files
copies[0] = file.getWorkspace().getRoot().getFile(copy1);
copies[1] = file.getWorkspace().getRoot().getFile(copy2);
-
+
return Status.OK_STATUS;
- }};
+ }
+ };
job.schedule();
-
+
try {
job.join();
} catch (InterruptedException e) {
fail(e);
}
-
+
// load the copies
- Resource testResource2 = domain.getResourceSet().getResource(
- URI.createPlatformResourceURI(copy1.toString(), true), true);
- Resource testResource3 = domain.getResourceSet().getResource(
- URI.createPlatformResourceURI(copy2.toString(), true), true);
-
+ Resource testResource2 = domain.getResourceSet()
+ .getResource(URI.createPlatformResourceURI(copy1.toString(), true), true);
+ Resource testResource3 = domain.getResourceSet()
+ .getResource(URI.createPlatformResourceURI(copy2.toString(), true), true);
+
assertNotNull(testResource2);
assertTrue(testResource2.isLoaded());
assertNotNull(testResource3);
assertTrue(testResource3.isLoaded());
-
+
try {
// make the workspace changes in a single job so that all deltas
- // are fired in one batch
- job = new WorkspaceJob("Modify Workspace") { //$NON-NLS-1$
+ // are fired in one batch
+ job = new WorkspaceJob("Modify Workspace") {
@Override
- public IStatus runInWorkspace(IProgressMonitor monitor)
- throws CoreException {
+ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
// delete one file
file.delete(true, null);
-
+
// change another's contents
copies[0].touch(null);
-
+
// and move a third
copies[1].move(newPath, true, null);
-
+
return Status.OK_STATUS;
- }};
+ }
+ };
job.schedule();
job.join();
} catch (Exception e) {
fail(e);
}
-
+
waitForWorkspaceChanges();
-
+
assertTrue(delegate.deletedResources.contains(testResource));
assertTrue(delegate.changedResources.contains(testResource2));
assertTrue(delegate.movedResources.containsKey(testResource3));
- assertEquals(
- URI.createPlatformResourceURI(newPath.toString(), true),
+ assertEquals(URI.createPlatformResourceURI(newPath.toString(), true),
delegate.movedResources.get(testResource3));
}
-
+
/**
* Tests the default response to resource deletion.
*/
+ @Test
public void test_defaultDeleteBehaviour() {
IFile file = WorkspaceSynchronizer.getFile(testResource);
-
+
delegate.defaultBehaviour = true;
-
+
assertTrue(testResource.isLoaded());
-
+
try {
synchronized (delegate) {
file.delete(true, null);
@@ -305,21 +301,22 @@ public void test_defaultDeleteBehaviour() {
}
waitForWorkspaceChanges();
-
+
assertFalse(testResource.isLoaded());
}
-
+
/**
- * Tests the default response to resource change. Note that the default
- * test resource URI does not require any URI-encoding.
+ * Tests the default response to resource change. Note that the default test
+ * resource URI does not require any URI-encoding.
*/
+ @Test
public void test_defaultChangeBehaviour() {
IFile file = WorkspaceSynchronizer.getFile(testResource);
-
+
delegate.defaultBehaviour = true;
-
+
assertTrue(testResource.isLoaded());
-
+
try {
synchronized (delegate) {
file.touch(null);
@@ -330,25 +327,25 @@ public void test_defaultChangeBehaviour() {
}
waitForWorkspaceChanges();
-
+
// check that the resource is loaded but has different contents than
- // it had before
+ // it had before
assertTrue(testResource.isLoaded());
assertFalse(testResource.getContents().contains(root));
}
-
+
/**
* Tests the default response to a resource move.
*/
+ @Test
public void test_defaultMoveBehaviour() {
IFile file = WorkspaceSynchronizer.getFile(testResource);
- IPath newPath = file.getFullPath().removeLastSegments(1).append(
- "moveDestination.extlibrary"); //$NON-NLS-1$
-
+ IPath newPath = file.getFullPath().removeLastSegments(1).append("moveDestination.extlibrary");
+
delegate.defaultBehaviour = true;
-
+
assertTrue(testResource.isLoaded());
-
+
try {
synchronized (delegate) {
file.move(newPath, true, null);
@@ -359,304 +356,306 @@ public void test_defaultMoveBehaviour() {
}
waitForWorkspaceChanges();
-
+
assertFalse(testResource.isLoaded());
}
-
+
/**
* Checks that URIs are decoded when constructing file paths.
*/
+ @Test
public void test_getFileWithEncodedURI_128315() {
- final String filePath = "/My Project/some dir/file.foo"; //$NON-NLS-1$
- final String encoded = "platform:/resource/My%20Project/some%20dir/file.foo"; //$NON-NLS-1$
-
+ final String filePath = "/My Project/some dir/file.foo";
+ final String encoded = "platform:/resource/My%20Project/some%20dir/file.foo";
+
URI uri = URI.createPlatformResourceURI(filePath, true);
-
+
// URI does encodes itself
assertEquals(encoded, uri.toString());
-
+
Resource res = new ResourceImpl(uri);
-
+
IFile file = WorkspaceSynchronizer.getFile(res);
-
+
assertEquals(filePath, file.getFullPath().toString());
}
-
+
/**
- * Tests synchronization of an in-memory Resource with a change
- * in the workspace IResource when the Resource's
- * URI is not encoded but should have been.
+ * Tests synchronization of an in-memory Resource with a change in
+ * the workspace IResource when the Resource's URI is
+ * not encoded but should have been.
*/
+ @Test
public void test_synchResourceWithUnencodedURI_197291() {
- // don't encode the URI
- Resource res = createTestResource(TEST_RESOURCE_NAME,
- "name with spaces.extlibrary", false); //$NON-NLS-1$
- root = (Library) res.getContents().get(0);
-
- IFile file = WorkspaceSynchronizer.getFile(res);
-
- delegate.defaultBehaviour = true;
-
- assertTrue(testResource.isLoaded());
-
- try {
- synchronized (delegate) {
- file.touch(null);
- delegate.wait(100000L);
- }
- } catch (Exception e) {
- fail(e);
- }
-
- waitForWorkspaceChanges();
-
- // check that the resource is loaded but has different contents than
- // it had before
- assertTrue(res.isLoaded());
- assertFalse(res.getContents().contains(root));
+ // don't encode the URI
+ Resource res = createTestResource(TEST_RESOURCE_NAME, "name with spaces.extlibrary", false);
+ root = (Library) res.getContents().get(0);
+
+ IFile file = WorkspaceSynchronizer.getFile(res);
+
+ delegate.defaultBehaviour = true;
+
+ assertTrue(testResource.isLoaded());
+
+ try {
+ synchronized (delegate) {
+ file.touch(null);
+ delegate.wait(100000L);
+ }
+ } catch (Exception e) {
+ fail(e);
+ }
+
+ waitForWorkspaceChanges();
+
+ // check that the resource is loaded but has different contents than
+ // it had before
+ assertTrue(res.isLoaded());
+ assertFalse(res.getContents().contains(root));
+ }
+
+ /**
+ * Tests synchronization of an in-memory Resource with a change in
+ * the workspace IResource when the Resource's URI is
+ * encoded (and needed to be).
+ */
+ @Test
+ public void test_synchResourceWithEncodedURI_197291() {
+ // *do* encode the URI
+ Resource res = createTestResource(TEST_RESOURCE_NAME, "name with spaces.extlibrary", true);
+ root = (Library) res.getContents().get(0);
+
+ IFile file = WorkspaceSynchronizer.getFile(res);
+
+ delegate.defaultBehaviour = true;
+
+ assertTrue(testResource.isLoaded());
+
+ try {
+ synchronized (delegate) {
+ file.touch(null);
+ delegate.wait(10000L);
+ }
+ } catch (Exception e) {
+ fail(e);
+ }
+
+ waitForWorkspaceChanges();
+
+ // check that the resource is loaded but has different contents than
+ // it had before
+ assertTrue(res.isLoaded());
+ assertFalse(res.getContents().contains(root));
+ }
+
+ /**
+ * Tests synchronization of an in-memory Resource with a change in
+ * the workspace IResource when the Resource's URI is
+ * not encoded but should have been.
+ */
+ @Test
+ public void test_synchMovedResourceWithUnencodedURI_197291() {
+ // don't encode the URI
+ Resource res = createTestResource(TEST_RESOURCE_NAME, "name with spaces.extlibrary", false);
+ root = (Library) res.getContents().get(0);
+
+ IFile file = WorkspaceSynchronizer.getFile(res);
+
+ IPath path = file.getFullPath().removeLastSegments(1).append("new name.extlibrary");
+ Resource newRes = domain.createResource(URI.createPlatformResourceURI(path.toString(), false).toString());
+
+ delegate.defaultBehaviour = true;
+
+ assertTrue(testResource.isLoaded());
+
+ try {
+ synchronized (delegate) {
+ file.move(path, true, null);
+ delegate.wait(100000L);
+ }
+ } catch (Exception e) {
+ fail(e);
+ }
+
+ waitForWorkspaceChanges();
+
+ assertFalse(delegate.changedResources.contains(res));
+ assertFalse(delegate.deletedResources.contains(res));
+ assertTrue(delegate.movedResources.containsKey(res));
+ assertEquals(newRes.getURI(), delegate.movedResources.get(res));
+ }
+
+ /**
+ * Tests synchronization of an in-memory Resource with a change in
+ * the workspace IResource when the Resource's URI is
+ * encoded (and needed to be).
+ */
+ @Test
+ public void test_synchMoveResourceWithEncodedURI_197291() {
+ // do encode the URI
+ Resource res = createTestResource(TEST_RESOURCE_NAME, "name with spaces.extlibrary", false);
+ root = (Library) res.getContents().get(0);
+
+ IFile file = WorkspaceSynchronizer.getFile(res);
+
+ IPath path = file.getFullPath().removeLastSegments(1).append("new name.extlibrary");
+ Resource newRes = domain.createResource(URI.createPlatformResourceURI(path.toString(), true).toString());
+
+ delegate.defaultBehaviour = true;
+
+ assertTrue(testResource.isLoaded());
+
+ try {
+ synchronized (delegate) {
+ file.move(path, true, null);
+ delegate.wait(100000L);
+ }
+ } catch (Exception e) {
+ fail(e);
+ }
+
+ waitForWorkspaceChanges();
+
+ assertFalse(delegate.changedResources.contains(res));
+ assertFalse(delegate.deletedResources.contains(res));
+ assertTrue(delegate.movedResources.containsKey(res));
+ assertEquals(newRes.getURI(), delegate.movedResources.get(res));
}
-
- /**
- * Tests synchronization of an in-memory Resource with a change
- * in the workspace IResource when the Resource's
- * URI is encoded (and needed to be).
- */
- public void test_synchResourceWithEncodedURI_197291() {
- // *do* encode the URI
- Resource res = createTestResource(TEST_RESOURCE_NAME,
- "name with spaces.extlibrary", true); //$NON-NLS-1$
- root = (Library) res.getContents().get(0);
-
- IFile file = WorkspaceSynchronizer.getFile(res);
-
- delegate.defaultBehaviour = true;
-
- assertTrue(testResource.isLoaded());
-
- try {
- synchronized (delegate) {
- file.touch(null);
- delegate.wait(10000L);
- }
- } catch (Exception e) {
- fail(e);
- }
-
- waitForWorkspaceChanges();
-
- // check that the resource is loaded but has different contents than
- // it had before
- assertTrue(res.isLoaded());
- assertFalse(res.getContents().contains(root));
- }
-
- /**
- * Tests synchronization of an in-memory Resource with a change
- * in the workspace IResource when the Resource's
- * URI is not encoded but should have been.
- */
- public void test_synchMovedResourceWithUnencodedURI_197291() {
- // don't encode the URI
- Resource res = createTestResource(TEST_RESOURCE_NAME,
- "name with spaces.extlibrary", false); //$NON-NLS-1$
- root = (Library) res.getContents().get(0);
-
- IFile file = WorkspaceSynchronizer.getFile(res);
-
- IPath path = file.getFullPath().removeLastSegments(1).append(
- "new name.extlibrary"); //$NON-NLS-1$
- Resource newRes = domain.createResource(
- URI.createPlatformResourceURI(path.toString(), false).toString());
-
- delegate.defaultBehaviour = true;
-
- assertTrue(testResource.isLoaded());
-
- try {
- synchronized (delegate) {
- file.move(path, true, null);
- delegate.wait(100000L);
- }
- } catch (Exception e) {
- fail(e);
- }
-
- waitForWorkspaceChanges();
-
- assertFalse(delegate.changedResources.contains(res));
- assertFalse(delegate.deletedResources.contains(res));
- assertTrue(delegate.movedResources.containsKey(res));
- assertEquals(newRes.getURI(), delegate.movedResources.get(res));
- }
-
- /**
- * Tests synchronization of an in-memory Resource with a change
- * in the workspace IResource when the Resource's
- * URI is encoded (and needed to be).
- */
- public void test_synchMoveResourceWithEncodedURI_197291() {
- // do encode the URI
- Resource res = createTestResource(TEST_RESOURCE_NAME,
- "name with spaces.extlibrary", false); //$NON-NLS-1$
- root = (Library) res.getContents().get(0);
-
- IFile file = WorkspaceSynchronizer.getFile(res);
-
- IPath path = file.getFullPath().removeLastSegments(1).append(
- "new name.extlibrary"); //$NON-NLS-1$
- Resource newRes = domain.createResource(
- URI.createPlatformResourceURI(path.toString(), true).toString());
-
- delegate.defaultBehaviour = true;
-
- assertTrue(testResource.isLoaded());
-
- try {
- synchronized (delegate) {
- file.move(path, true, null);
- delegate.wait(100000L);
- }
- } catch (Exception e) {
- fail(e);
- }
-
- waitForWorkspaceChanges();
-
- assertFalse(delegate.changedResources.contains(res));
- assertFalse(delegate.deletedResources.contains(res));
- assertTrue(delegate.movedResources.containsKey(res));
- assertEquals(newRes.getURI(), delegate.movedResources.get(res));
- }
-
- /**
- * Tests the response to resource deletion when the deleted resource also
- * had markers.
- */
- public void test_resourceDeletedThatHadMarkers_207306() {
- IFile file = WorkspaceSynchronizer.getFile(testResource);
-
- try {
- IMarker marker = file.createMarker(MarkerUtil.VALIDATION_MARKER_TYPE);
- marker.setAttribute(MarkerUtil.RULE_ATTRIBUTE, "foo"); //$NON-NLS-1$
- } catch (CoreException e) {
- fail(e);
- }
-
- delegate.defaultBehaviour = true;
-
- assertTrue(testResource.isLoaded());
-
- try {
- synchronized (delegate) {
- file.delete(true, null);
- delegate.wait(20000);
- }
- } catch (Exception e) {
- fail(e);
- }
-
- waitForWorkspaceChanges();
-
- assertFalse(testResource.isLoaded());
- }
-
- public void test_deleteProjectAndDisposeSynchronizer_233004() {
- final IStatus[] logged = new IStatus[1];
-
- ILogListener log = new ILogListener() {
-
+
+ /**
+ * Tests the response to resource deletion when the deleted resource also had
+ * markers.
+ */
+ @Test
+ public void test_resourceDeletedThatHadMarkers_207306() {
+ IFile file = WorkspaceSynchronizer.getFile(testResource);
+
+ try {
+ IMarker marker = file.createMarker(MarkerUtil.VALIDATION_MARKER_TYPE);
+ marker.setAttribute(MarkerUtil.RULE_ATTRIBUTE, "foo");
+ } catch (CoreException e) {
+ fail(e);
+ }
+
+ delegate.defaultBehaviour = true;
+
+ assertTrue(testResource.isLoaded());
+
+ try {
+ synchronized (delegate) {
+ file.delete(true, null);
+ delegate.wait(20000);
+ }
+ } catch (Exception e) {
+ fail(e);
+ }
+
+ waitForWorkspaceChanges();
+
+ assertFalse(testResource.isLoaded());
+ }
+
+ @Test
+ public void test_deleteProjectAndDisposeSynchronizer_233004() {
+ final IStatus[] logged = new IStatus[1];
+
+ ILogListener log = new ILogListener() {
+
+ @Override
public void logging(IStatus status, String plugin) {
logged[0] = status;
- }};
-
- IResourceChangeListener listener = new IResourceChangeListener() {
- private boolean disposedSynch;
-
+ }
+ };
+
+ IResourceChangeListener listener = new IResourceChangeListener() {
+ private boolean disposedSynch;
+
+ @Override
public void resourceChanged(IResourceChangeEvent event) {
- if ((event.getType() == IResourceChangeEvent.POST_CHANGE)
- && !disposedSynch) {
+ if ((event.getType() == IResourceChangeEvent.POST_CHANGE) && !disposedSynch) {
disposedSynch = true;
synch.dispose();
}
- }};
-
+ }
+ };
+
try {
ResourcesPlugin.getWorkspace().addResourceChangeListener(listener);
EMFWorkspacePlugin.getPlugin().getLog().addLogListener(log);
-
+
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
-
- public void run(IProgressMonitor monitor)
- throws CoreException {
+
+ @Override
+ public void run(IProgressMonitor monitor) throws CoreException {
project.delete(true, null);
- }}, null);
-
+ }
+ }, null);
+
// give the synch-job a chance to run
Thread.sleep(1000);
-
+
if (logged[0] != null) {
- fail("Should not have logged: " + logged[0].getException());
+ Assertions.fail("Should not have logged: " + logged[0].getException());
}
} catch (CoreException e) {
- fail("Failed to delete project: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to delete project: " + e.getLocalizedMessage());
} catch (InterruptedException e) {
- fail("Test interrupted in sleep");
+ Assertions.fail("Test interrupted in sleep");
} finally {
EMFWorkspacePlugin.getPlugin().getLog().removeLogListener(log);
ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener);
}
- }
-
+ }
+
//
// Fixture methods
//
-
+
@Override
- protected void doSetUp()
- throws Exception {
-
+ protected void doSetUp() throws Exception {
+
super.doSetUp();
-
+
delegate = new TestDelegate();
synch = new WorkspaceSynchronizer(domain, delegate);
}
-
+
@Override
- protected void doTearDown()
- throws Exception {
-
+ protected void doTearDown() throws Exception {
+
synch.dispose();
synch = null;
delegate = null;
-
+
super.doTearDown();
}
-
+
/**
- * Waits for any pending workspace changes to finish by scheduling a job
- * on the workspace root and waiting for it to finish.
+ * Waits for any pending workspace changes to finish by scheduling a job on the
+ * workspace root and waiting for it to finish.
*/
void waitForWorkspaceChanges() {
final Object lock = new Object();
-
- Job job = new Job("Wait Job") { //$NON-NLS-1$
+
+ Job job = new Job("Wait Job") {
{
setRule(ResourcesPlugin.getWorkspace().getRoot());
setSystem(true);
}
-
+
@Override
protected IStatus run(IProgressMonitor monitor) {
synchronized (lock) {
lock.notify();
}
-
+
return Status.OK_STATUS;
- }};
-
+ }
+ };
+
synchronized (lock) {
job.schedule();
-
+
try {
lock.wait();
} catch (InterruptedException e) {
@@ -664,7 +663,7 @@ protected IStatus run(IProgressMonitor monitor) {
}
}
}
-
+
/**
* Delegate implementation for testing, basically tracking the call-backs
* received from the workspace synchronizer.
@@ -672,36 +671,40 @@ protected IStatus run(IProgressMonitor monitor) {
* @author Christian W. Damus (cdamus)
*/
static class TestDelegate implements WorkspaceSynchronizer.Delegate {
- final List deletedResources = new java.util.ArrayList();
- final Map movedResources = new java.util.LinkedHashMap();
- final List changedResources = new java.util.ArrayList();
-
+ final List deletedResources = new java.util.ArrayList<>();
+ final Map movedResources = new java.util.LinkedHashMap<>();
+ final List changedResources = new java.util.ArrayList<>();
+
boolean defaultBehaviour = false;
-
+
+ @Override
public synchronized boolean handleResourceDeleted(Resource resource) {
deletedResources.add(resource);
-
+
notify();
-
+
return !defaultBehaviour;
}
+ @Override
public synchronized boolean handleResourceMoved(Resource resource, URI newURI) {
movedResources.put(resource, newURI);
-
+
notify();
-
+
return !defaultBehaviour;
}
+ @Override
public synchronized boolean handleResourceChanged(Resource resource) {
changedResources.add(resource);
-
+
notify();
-
+
return !defaultBehaviour;
}
-
+
+ @Override
public void dispose() {
deletedResources.clear();
movedResources.clear();