From 632dfe34ab0afed43a9d3e8d0f37e002065c1369 Mon Sep 17 00:00:00 2001
From: Pierre-Charles David
Date: Sat, 7 Mar 2026 15:43:56 +0100
Subject: [PATCH 1/2] [41] Convert tests to JUnit 4
Bug: https://github.com/eclipse-emfservices/emf-transaction/issues/41
Signed-off-by: Pierre-Charles David
---
.../tests/AbstractMultithreadTest.java | 52 +-
.../multithread/tests/ReadOperationTest.java | 77 +-
.../tests/ReadWriteOperationTest.java | 136 +-
.../multithread/tests/WriteOperationTest.java | 31 +-
.../emf/transaction/tests/AbstractTest.java | 70 +-
.../tests/BasicTransactionTest.java | 64 +-
.../tests/ChangeDescriptionTest.java | 57 +-
.../tests/EditingDomainRegistryTest.java | 92 +-
.../transaction/tests/EditingDomainTest.java | 234 ++-
.../tests/EditingDomainValidatorTest.java | 18 +-
.../JobManagerSuspensionDeadlockTest.java | 14 +-
.../tests/LifecycleListenersTest.java | 108 +-
.../emf/transaction/tests/MemoryLeakTest.java | 675 ++++-----
.../tests/NotificationFilterTest.java | 190 ++-
.../transaction/tests/PerformanceTest.java | 360 +++--
.../tests/PrivilegedRunnableTest.java | 261 ++--
.../tests/RecordingCommandTest.java | 18 +-
.../tests/ResourceSetListenersTest.java | 65 +-
.../tests/TransactionChangeRecorderTest.java | 506 +++----
.../tests/TransactionOptionsTest.java | 652 ++++----
.../emf/transaction/tests/UndoRedoTest.java | 694 ++++-----
.../transaction/tests/ValidateEditTest.java | 377 +++--
.../tests/ValidationRollbackTest.java | 1312 +++++++++--------
.../tests/CompositeChangeDescriptionTest.java | 177 ++-
.../util/tests/InternalUtilTests.java | 39 -
.../emf/transaction/util/tests/LockTest.java | 76 +-
.../util/tests/TransactionUtilTests.java | 36 +-
.../tests/AbstractEMFOperationTest.java | 160 +-
.../emf/workspace/tests/AbstractTest.java | 456 +++---
.../workspace/tests/BasicWorkbenchTest.java | 43 +-
.../tests/CompositeEMFOperationTest.java | 48 +-
.../tests/EMFCommandOperationTest.java | 27 +-
.../tests/EMFOperationCommandTest.java | 35 +-
.../emf/workspace/tests/MemoryLeakTest.java | 46 +-
.../emf/workspace/tests/UndoContextTest.java | 17 +-
.../tests/WorkbenchCommandStackTest.java | 63 +-
.../constraints/BookTitleConstraint.java | 16 +-
.../tests/constraints/ClientSelector.java | 6 +-
.../tests/fixtures/ContextAdder.java | 3 +-
.../tests/fixtures/ExternalDataCommand.java | 16 +-
.../tests/fixtures/ExternalDataOperation.java | 18 +-
.../ItemDefaultPublicationDateTrigger.java | 17 +-
.../fixtures/LibraryDefaultBookTrigger.java | 27 +-
.../fixtures/LibraryDefaultNameTrigger.java | 26 +-
.../workspace/tests/fixtures/LogCapture.java | 89 +-
.../fixtures/NonEMFCompositeOperation.java | 55 +-
.../workspace/tests/fixtures/NullCommand.java | 6 +-
.../tests/fixtures/NullOperation.java | 30 +-
.../SelfOpeningEMFCompositeOperation.java | 178 ++-
.../workspace/tests/fixtures/TestCommand.java | 22 +-
.../tests/fixtures/TestListener.java | 17 +-
.../tests/fixtures/TestOperation.java | 17 +-
.../tests/fixtures/TestPackageBuilder.java | 40 +-
.../tests/fixtures/TestUndoContext.java | 11 +-
.../tests/OperationChangeDescriptionTest.java | 41 +-
.../util/tests/ResourceUndoContextTest.java | 229 ++-
.../util/tests/ValidateEditTest.java | 20 +-
.../util/tests/WorkspaceSynchronizerTest.java | 43 +-
58 files changed, 4070 insertions(+), 4143 deletions(-)
delete mode 100644 tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/util/tests/InternalUtilTests.java
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/AbstractMultithreadTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/AbstractMultithreadTest.java
index 0ba317e6..5ba8c06d 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/AbstractMultithreadTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/AbstractMultithreadTest.java
@@ -11,65 +11,37 @@
*/
package org.eclipse.emf.transaction.multithread.tests;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.tests.AbstractTest;
+import org.junit.After;
+import org.junit.Before;
/**
* Abstract JUnit test suite for the EMF-TX API multi-threading tests.
*
* @author Christian W. Damus (cdamus)
*/
-public class AbstractMultithreadTest
- extends TestCase {
+public class AbstractMultithreadTest {
private TransactionalEditingDomain domain = null;
-
- public AbstractMultithreadTest() {
- super(""); //$NON-NLS-1$
- }
-
- public static Test suite() {
- TestSuite suite = new TestSuite("Multi-threading Tests"); //$NON-NLS-1$
-
- suite.addTest(ReadOperationTest.suite());
- suite.addTest(WriteOperationTest.suite());
- suite.addTest(ReadWriteOperationTest.suite());
- suite.addTest(EMFTransansactionTest.suite());
- return suite;
- }
-
//
// Fixture methods
//
-
+
protected TransactionalEditingDomain getDomain() {
return domain;
}
-
- @Override
- protected void setUp()
- throws Exception {
-
- AbstractTest.trace("===> Begin : " + getName()); //$NON-NLS-1$
-
- super.setUp();
-
+
+ @Before
+ public void setUp() throws Exception {
+ AbstractTest.trace("===> Begin : " + this.getClass().getName());
domain = TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain();
}
-
- @Override
- protected void tearDown()
- throws Exception {
-
+
+ @After
+ public void tearDown() throws Exception {
domain = null;
-
- AbstractTest.trace("===> End : " + getName()); //$NON-NLS-1$
-
- super.tearDown();
+ AbstractTest.trace("===> End : " + this.getClass().getName());
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadOperationTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadOperationTest.java
index dd7c611c..5a4ad525 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadOperationTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadOperationTest.java
@@ -11,24 +11,22 @@
*/
package org.eclipse.emf.transaction.multithread.tests;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
/**
* Testcase for testing scheduling of Read operation scenarios
+ *
* @author mgoyal
*/
-public class ReadOperationTest
- extends AbstractMultithreadTest {
-
- public static Test suite() {
- return new TestSuite(ReadOperationTest.class, "Reader Thread Tests"); //$NON-NLS-1$
- }
+public class ReadOperationTest extends AbstractMultithreadTest {
/**
- * Tests scheduling of simple read operation
+ * Tests scheduling of simple read operation
*/
+ @Test
public void testReadOperation() {
ReadThread readThread1 = new ReadThread(getDomain());
@@ -50,8 +48,9 @@ public void testReadOperation() {
}
/**
- * Tests scheduling of simultaneous read operations.
+ * Tests scheduling of simultaneous read operations.
*/
+ @Test
public void testSimultaneousRead() {
Object notifier = new Object();
ReadThread readThread1 = new ReadThread(getDomain(), null, notifier);
@@ -90,12 +89,13 @@ public void testSimultaneousRead() {
assertTrue(readThread1.isExecuted());
assertTrue(readThread2.isExecuted());
assertTrue(Constants.occurredBefore(readThread2, readThread1)
- || Constants.occurredAfter(readThread2, readThread1));
+ || Constants.occurredAfter(readThread2, readThread1));
}
/**
- * Tests scheduling of nested read operations.
+ * Tests scheduling of nested read operations.
*/
+ @Test
public void testNestedReads() {
NestedReadThread readThread1 = new NestedReadThread(getDomain());
readThread1.start();
@@ -114,20 +114,17 @@ public void testNestedReads() {
assertFalse(readThread1.isFailed());
assertTrue(readThread1.isInnerExecuted());
assertTrue(readThread1.isExecuted());
- assertTrue(Constants.occurredDuring(readThread1.getStartTime(),
- readThread1.getEndTime(), readThread1.getInnerStartTime(),
- readThread1.getInnerEndTime()));
+ assertTrue(Constants.occurredDuring(readThread1.getStartTime(), readThread1.getEndTime(),
+ readThread1.getInnerStartTime(), readThread1.getInnerEndTime()));
}
/**
- * Tests scheduling of yielding read with other simultaneous read operations.
+ * Tests scheduling of yielding read with other simultaneous read operations.
*/
+ @Test
public void testLongRunningYieldingRead() {
Object runNotifier = new Object();
- LongRunningReadThread longReadThread = new LongRunningReadThread(
- getDomain(),
- null,
- runNotifier);
+ LongRunningReadThread longReadThread = new LongRunningReadThread(getDomain(), null, runNotifier);
ReadThread readThd1 = new ReadThread(getDomain(), null, runNotifier);
ReadThread readThd2 = new ReadThread(getDomain(), null, runNotifier);
ReadThread readThd3 = new ReadThread(getDomain(), null, runNotifier);
@@ -164,7 +161,7 @@ public void testLongRunningYieldingRead() {
// nothing
}
}
-
+
boolean done = false;
while (!done) {
try {
@@ -172,8 +169,7 @@ public void testLongRunningYieldingRead() {
} catch (InterruptedException e) {
// ignore this exception
}
- if (!longReadThread.isAlive() && !readThd1.isAlive()
- && !readThd2.isAlive() && !readThd3.isAlive())
+ if (!longReadThread.isAlive() && !readThd1.isAlive() && !readThd2.isAlive() && !readThd3.isAlive())
done = true;
}
@@ -199,26 +195,15 @@ public void testLongRunningYieldingRead() {
}
/**
- * Tests cooperative scheduling of multiple yielding readers.
+ * Tests cooperative scheduling of multiple yielding readers.
*/
+ @Test
public void testMultipleLongRunningYieldingReads() {
Object runNotifier = new Object();
- LongRunningReadThread longReadThread1 = new LongRunningReadThread(
- getDomain(),
- null,
- runNotifier);
- LongRunningReadThread longReadThread2 = new LongRunningReadThread(
- getDomain(),
- null,
- runNotifier);
- LongRunningReadThread longReadThread3 = new LongRunningReadThread(
- getDomain(),
- null,
- runNotifier);
- LongRunningReadThread longReadThread4 = new LongRunningReadThread(
- getDomain(),
- null,
- runNotifier);
+ LongRunningReadThread longReadThread1 = new LongRunningReadThread(getDomain(), null, runNotifier);
+ LongRunningReadThread longReadThread2 = new LongRunningReadThread(getDomain(), null, runNotifier);
+ LongRunningReadThread longReadThread3 = new LongRunningReadThread(getDomain(), null, runNotifier);
+ LongRunningReadThread longReadThread4 = new LongRunningReadThread(getDomain(), null, runNotifier);
synchronized (runNotifier) {
try {
@@ -246,10 +231,10 @@ public void testMultipleLongRunningYieldingReads() {
}
synchronized (runNotifier) {
// run this one directly in the UI thread to test that the UI-safe
- // acquiring actually causes the "UI blocked" dialog
+ // acquiring actually causes the "UI blocked" dialog
longReadThread4.run();
}
-
+
boolean done = false;
while (!done) {
try {
@@ -257,8 +242,8 @@ public void testMultipleLongRunningYieldingReads() {
} catch (InterruptedException e) {
// ignore this exception
}
- if (!longReadThread1.isAlive() && !longReadThread2.isAlive()
- && !longReadThread3.isAlive() && !longReadThread4.isAlive())
+ if (!longReadThread1.isAlive() && !longReadThread2.isAlive() && !longReadThread3.isAlive()
+ && !longReadThread4.isAlive())
done = true;
}
@@ -270,9 +255,9 @@ public void testMultipleLongRunningYieldingReads() {
assertTrue(longReadThread2.isExecuted());
assertTrue(longReadThread3.isExecuted());
assertTrue(longReadThread4.isExecuted());
-
+
// at least two of the threads should have yielded to other readers,
- // which is indicated by having yielded for at least a sleep time
+ // which is indicated by having yielded for at least a sleep time
int yielded = 0;
if (longReadThread1.timeYielded >= Constants.SLEEP_TIME) {
yielded++;
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadWriteOperationTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadWriteOperationTest.java
index 1eb240a7..eed5d0be 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadWriteOperationTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadWriteOperationTest.java
@@ -12,31 +12,25 @@
*/
package org.eclipse.emf.transaction.multithread.tests;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
/**
* Testcase for testing read and write operation scheduling scenarios
*
* @author mgoyal
*/
-public class ReadWriteOperationTest
- extends AbstractMultithreadTest {
-
- public static Test suite() {
- return new TestSuite(ReadWriteOperationTest.class, "Concurrent Reader and Writer Thread Tests"); //$NON-NLS-1$
- }
+public class ReadWriteOperationTest extends AbstractMultithreadTest {
/**
- * Tests scheduling of complex Read write scenarios.
+ * Tests scheduling of complex Read write scenarios.
*/
- public void testComplexSimultaneousReadsWrites() {
+ @Test public void testComplexSimultaneousReadsWrites() {
Object notifier = new Object();
- NestedReadInWriteThread readInWriteThread1 = new NestedReadInWriteThread(
- getDomain(), null, notifier);
- NestedReadInWriteThread readInWriteThread2 = new NestedReadInWriteThread(
- getDomain(), null, notifier);
+ NestedReadInWriteThread readInWriteThread1 = new NestedReadInWriteThread(getDomain(), null, notifier);
+ NestedReadInWriteThread readInWriteThread2 = new NestedReadInWriteThread(getDomain(), null, notifier);
synchronized (notifier) {
try {
@@ -62,8 +56,7 @@ public void testComplexSimultaneousReadsWrites() {
} catch (InterruptedException e) {
// ignore this exception
}
- if (!readInWriteThread1.isAlive()
- && !readInWriteThread2.isAlive())
+ if (!readInWriteThread1.isAlive() && !readInWriteThread2.isAlive())
done = true;
}
@@ -78,9 +71,9 @@ public void testComplexSimultaneousReadsWrites() {
}
/**
- * Tests scheduling of simultaneous read and write operation
+ * Tests scheduling of simultaneous read and write operation
*/
- public void testSimultaneousReadsWrites() {
+ @Test public void testSimultaneousReadsWrites() {
Object notifier = new Object();
WriteThread writeThread1 = new WriteThread(getDomain(), null, notifier);
WriteThread writeThread2 = new WriteThread(getDomain(), null, notifier);
@@ -130,8 +123,7 @@ public void testSimultaneousReadsWrites() {
} catch (InterruptedException e) {
// ignore this exception
}
- if (!writeThread1.isAlive() && !writeThread2.isAlive()
- && !readThread1.isAlive() && !readThread2.isAlive())
+ if (!writeThread1.isAlive() && !writeThread2.isAlive() && !readThread1.isAlive() && !readThread2.isAlive())
done = true;
}
@@ -144,23 +136,23 @@ public void testSimultaneousReadsWrites() {
assertTrue(writeThread1.isExecuted());
assertTrue(writeThread2.isExecuted());
assertTrue(Constants.occurredBefore(writeThread2, writeThread1)
- || Constants.occurredAfter(writeThread2, writeThread1));
+ || Constants.occurredAfter(writeThread2, writeThread1));
assertTrue(Constants.occurredBefore(writeThread2, readThread2)
- || Constants.occurredAfter(writeThread2, readThread2));
+ || Constants.occurredAfter(writeThread2, readThread2));
assertTrue(Constants.occurredBefore(writeThread2, readThread1)
- || Constants.occurredAfter(writeThread2, readThread1));
+ || Constants.occurredAfter(writeThread2, readThread1));
assertTrue(Constants.occurredBefore(readThread2, readThread1)
- || Constants.occurredAfter(readThread2, readThread1));
+ || Constants.occurredAfter(readThread2, readThread1));
assertTrue(Constants.occurredBefore(readThread2, writeThread1)
- || Constants.occurredAfter(readThread2, writeThread1));
+ || Constants.occurredAfter(readThread2, writeThread1));
assertTrue(Constants.occurredBefore(readThread1, writeThread1)
- || Constants.occurredAfter(readThread1, writeThread1));
+ || Constants.occurredAfter(readThread1, writeThread1));
}
/**
- * Tests Scheduling of Nested Read in Write Operation
+ * Tests Scheduling of Nested Read in Write Operation
*/
- public void testNestedReadInWrite() {
+ @Test public void testNestedReadInWrite() {
NestedReadInWriteThread readInWriteThd = new NestedReadInWriteThread(getDomain());
readInWriteThd.start();
@@ -179,22 +171,18 @@ public void testNestedReadInWrite() {
assertFalse(readInWriteThd.isFailed());
assertTrue(readInWriteThd.isInnerExecuted());
assertTrue(readInWriteThd.isExecuted());
-
+
// CWD: Cannot assert that the elapsed time was >= Constants.SLEEP_TIME
- // because the J9 VM always sleeps to short when SLEEP_TIME < 500
- assertTrue((readInWriteThd.getEndTime() - readInWriteThd
- .getInnerEndTime()) > 0);
+ // because the J9 VM always sleeps to short when SLEEP_TIME < 500
+ assertTrue((readInWriteThd.getEndTime() - readInWriteThd.getInnerEndTime()) > 0);
}
/**
- * Tests scheduling of long running read with write operation.
+ * Tests scheduling of long running read with write operation.
*/
- public void testLongRunningReadWithWrites() {
+ @Test public void testLongRunningReadWithWrites() {
Object notifier = new Object();
- LongRunningReadThread longReadThread = new LongRunningReadThread(
- getDomain(),
- null,
- notifier);
+ LongRunningReadThread longReadThread = new LongRunningReadThread(getDomain(), null, notifier);
ReadThread readThd1 = new ReadThread(getDomain(), null, notifier);
ReadThread readThd2 = new ReadThread(getDomain(), null, notifier);
WriteThread writeThd1 = new WriteThread(getDomain(), null, notifier);
@@ -252,9 +240,8 @@ public void testLongRunningReadWithWrites() {
} catch (InterruptedException e) {
// ignore this exception
}
- if (!longReadThread.isAlive() && !readThd1.isAlive()
- && !readThd2.isAlive() && !readThd3.isAlive()
- && !writeThd1.isAlive())
+ if (!longReadThread.isAlive() && !readThd1.isAlive() && !readThd2.isAlive() && !readThd3.isAlive()
+ && !writeThd1.isAlive())
done = true;
}
@@ -276,45 +263,42 @@ public void testLongRunningReadWithWrites() {
// running thread.
// Verify readThd1 and readThd2 didn't execute simultaneously
// Verify writeThd1 and readThd3 didn't execute simulatenously
- // System.out.println((readThd1.getStartTime() -
+ // System.out.println((readThd1.getStartTime() -
// longReadThread.getStartTime()));
- // System.out.println(readThd2.getStartTime() -
+ // System.out.println(readThd2.getStartTime() -
// longReadThread.getStartTime());
- // System.out.println(longReadThread.getEndTime() -
+ // System.out.println(longReadThread.getEndTime() -
// readThd1.getEndTime());
- // System.out.println(longReadThread.getEndTime() -
+ // System.out.println(longReadThread.getEndTime() -
// readThd2.getEndTime());
- // System.out.println(readThd1.getStartTime() -
+ // System.out.println(readThd1.getStartTime() -
// readThd2.getStartTime());
- // System.out.println(writeThd1.getStartTime() -
+ // System.out.println(writeThd1.getStartTime() -
// longReadThread.getEndTime());
- // System.out.println(readThd3.getStartTime() -
+ // System.out.println(readThd3.getStartTime() -
// longReadThread.getEndTime());
- // System.out.println(readThd3.getStartTime() -
+ // System.out.println(readThd3.getStartTime() -
// writeThd1.getStartTime());
assertTrue(!Constants.occurIntersect(longReadThread, readThd1));
assertTrue(!Constants.occurIntersect(longReadThread, readThd2));
- assertTrue(Constants.occurredAfter(readThd1, readThd2)
- || Constants.occurredBefore(readThd1, readThd2));
+ assertTrue(Constants.occurredAfter(readThd1, readThd2) || Constants.occurredBefore(readThd1, readThd2));
assertTrue("Read yielded to a write", //$NON-NLS-1$
- (Constants.occurredBefore(longReadThread, writeThd1) || Constants
- .occurredAfter(longReadThread, writeThd1))
- && !Constants.occurredDuring(longReadThread, writeThd1));
+ (Constants.occurredBefore(longReadThread, writeThd1)
+ || Constants.occurredAfter(longReadThread, writeThd1))
+ && !Constants.occurredDuring(longReadThread, writeThd1));
assertTrue(!Constants.occurIntersect(longReadThread, readThd3));
}
/**
- * Tests that the lock implementation does not allow interruption of the
- * UI thread during timed waits.
+ * Tests that the lock implementation does not allow interruption of the UI
+ * thread during timed waits.
*/
+ @Test
public void test_interruptionOfUIThread_149982() {
Object notifier = new Object();
- LongRunningReadThread longReadThread = new LongRunningReadThread(
- getDomain(),
- null,
- notifier);
+ LongRunningReadThread longReadThread = new LongRunningReadThread(getDomain(), null, notifier);
WriteThread writeThd1 = new WriteThread(getDomain());
-
+
synchronized (notifier) {
try {
longReadThread.start();
@@ -327,46 +311,48 @@ public void test_interruptionOfUIThread_149982() {
final Thread uiThread = Thread.currentThread();
class Interrupter implements Runnable {
private volatile boolean dead;
-
+
public void run() {
while (!dead) {
uiThread.interrupt();
-
+
try {
Thread.sleep(50L);
} catch (InterruptedException e) {
- // don't care. Just interrupt the UI again!
+ // don't care. Just interrupt the UI again!
}
}
}
-
+
void die() {
dead = true;
- }};
-
+ }
+ }
+ ;
+
Interrupter interrupter = new Interrupter();
Thread interrupterThread = new Thread(interrupter);
interrupterThread.setDaemon(true);
interrupterThread.start();
-
+
try {
// for good measure, interrupt the "UI thread" now
uiThread.interrupt();
-
- // run this one on the UI thread. It will have to wait, and while it is
- // waiting, the interrupter thread will try to interrupt it
+
+ // run this one on the UI thread. It will have to wait, and while it is
+ // waiting, the interrupter thread will try to interrupt it
writeThd1.run();
-
- // if the thread failed, assert that it was because it was interrupted not
+
+ // if the thread failed, assert that it was because it was interrupted not
// in the timed wait phase but in the beginning of the special job rule
if (writeThd1.isFailed()) {
assertTrue(writeThd1.failedIn("org.eclipse.core.internal.jobs.JobManager"));
} else {
assertTrue(writeThd1.isExecuted());
}
- } finally {
+ } finally {
interrupter.die();
- Thread.interrupted(); // don't interfere with the following tests
+ Thread.interrupted(); // don't interfere with the following tests
}
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/WriteOperationTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/WriteOperationTest.java
index ea988a3f..199f50eb 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/WriteOperationTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/WriteOperationTest.java
@@ -11,26 +11,23 @@
*/
package org.eclipse.emf.transaction.multithread.tests;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
/**
* Testcase for testing scheduling of Write Operation scenarios
+ *
* @author mgoyal
- *
+ *
*/
-public class WriteOperationTest
- extends AbstractMultithreadTest {
-
- public static Test suite() {
- return new TestSuite(WriteOperationTest.class, "Writer Thread Tests"); //$NON-NLS-1$
- }
+public class WriteOperationTest extends AbstractMultithreadTest {
/**
- * Tests scheduling of simple write operation.
+ * Tests scheduling of simple write operation.
*/
- public void testWriteOperation() {
+ @Test public void testWriteOperation() {
WriteThread writeThread1 = new WriteThread(getDomain());
writeThread1.start();
@@ -50,9 +47,9 @@ public void testWriteOperation() {
}
/**
- * Tests scheduling of two simultaneous write operations.
+ * Tests scheduling of two simultaneous write operations.
*/
- public void testSimultaneousWrites() {
+ @Test public void testSimultaneousWrites() {
Object notifier = new Object();
WriteThread writeThread1 = new WriteThread(getDomain(), null, notifier);
WriteThread writeThread2 = new WriteThread(getDomain(), null, notifier);
@@ -90,12 +87,13 @@ public void testSimultaneousWrites() {
assertTrue(writeThread1.isExecuted());
assertTrue(writeThread2.isExecuted());
assertTrue(Constants.occurredAfter(writeThread1, writeThread2)
- || Constants.occurredBefore(writeThread1, writeThread2));
+ || Constants.occurredBefore(writeThread1, writeThread2));
}
/**
* Tests scheduling of Nested Write Operations.
*/
+ @Test
public void testNestedWrites() {
NestedWriteThread writeThread1 = new NestedWriteThread(getDomain());
writeThread1.start();
@@ -114,9 +112,8 @@ public void testNestedWrites() {
assertFalse(writeThread1.isFailed());
assertTrue(writeThread1.isInnerExecuted());
assertTrue(writeThread1.isExecuted());
- assertTrue(Constants.occurredDuring(writeThread1.getStartTime(),
- writeThread1.getEndTime(), writeThread1.getInnerStartTime(),
- writeThread1.getInnerEndTime()));
+ assertTrue(Constants.occurredDuring(writeThread1.getStartTime(), writeThread1.getEndTime(),
+ writeThread1.getInnerStartTime(), writeThread1.getInnerEndTime()));
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/AbstractTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/AbstractTest.java
index 015bfd7e..181b31c5 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/AbstractTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/AbstractTest.java
@@ -11,6 +11,10 @@
*/
package org.eclipse.emf.transaction.tests;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
@@ -19,8 +23,6 @@
import java.util.Map;
import java.util.Set;
-import junit.framework.TestCase;
-
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.IFileStore;
@@ -51,6 +53,9 @@
import org.eclipse.emf.transaction.impl.InternalTransaction;
import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
import org.eclipse.emf.validation.model.IConstraintStatus;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
import org.osgi.framework.Bundle;
/**
@@ -58,8 +63,7 @@
*
* @author Christian W. Damus (cdamus)
*/
-public class AbstractTest
- extends TestCase {
+public class AbstractTest {
public static final boolean DEBUGGING = TestsPlugin.instance.isDebugging();
@@ -71,31 +75,23 @@ public class AbstractTest
protected Resource testResource;
protected Library root;
- protected static final String PROJECT_NAME = "emftxtests"; //$NON-NLS-1$
- protected static final String RESOURCE_NAME = "/" + PROJECT_NAME + "/testres.extlibrary"; //$NON-NLS-1$//$NON-NLS-2$
+ protected static final String PROJECT_NAME = "emftxtests";
+ protected static final String RESOURCE_NAME = "/" + PROJECT_NAME + "/testres.extlibrary";
private final List transactionStack =
new java.util.ArrayList();
private List tearDownActions;
- public AbstractTest() {
- super();
- }
-
- public AbstractTest(String name) {
- super(name);
- }
-
//
// Test configuration methods
//
- @Override
- protected final void setUp()
+ @Before
+ public void setUp()
throws Exception {
- trace("===> Begin : " + getName()); //$NON-NLS-1$
+ trace("===> Begin : " + this.getClass().getName());
doSetUp();
}
@@ -116,14 +112,14 @@ protected void doSetUp()
try {
Resource originalRes = rset.getResource(
URI.createURI(EmfTransactionTestsBundle.getEntry(
- "/test_models/test_model.extlibrary").toString()), //$NON-NLS-1$
+ "/test_models/test_model.extlibrary").toString()),
true);
originalRes.setURI(URI.createPlatformResourceURI(RESOURCE_NAME, true));
originalRes.save(Collections.EMPTY_MAP);
testResource = originalRes;
- root = (Library) find("root"); //$NON-NLS-1$
+ root = (Library) find("root");
} catch (IOException e) {
- fail("Failed to load test model: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Failed to load test model: " + e.getLocalizedMessage());
}
@@ -155,15 +151,15 @@ protected final void addTearDownAction(Runnable action) {
tearDownActions.add(action);
}
- @Override
- protected final void tearDown()
+ @After
+ public final void tearDown()
throws Exception {
try {
doTearDown();
} finally {
processTearDownActions();
- trace("===> End : " + getName()); //$NON-NLS-1$
+ trace("===> End : " + this.getClass().getName());
}
}
@@ -173,7 +169,7 @@ private void processTearDownActions() {
try {
action.run();
} catch (Exception e) {
- System.err.println("Exception in tear-down action:"); //$NON-NLS-1$
+ System.err.println("Exception in tear-down action:");
e.printStackTrace();
}
}
@@ -225,7 +221,7 @@ protected void delete(java.io.File file) {
info.setAttribute(EFS.ATTRIBUTE_ARCHIVE, false);
store.putInfo(info, EFS.SET_ATTRIBUTES, null);
} catch (Exception e) {
- fail("Failed to clean up test file: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Failed to clean up test file: " + e.getLocalizedMessage());
}
}
@@ -245,7 +241,7 @@ protected void delete(IFile file) {
}
file.delete(true, null);
} catch (Exception e) {
- fail("Failed to clean up test file: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Failed to clean up test file: " + e.getLocalizedMessage());
}
}
@@ -269,7 +265,7 @@ public boolean visit(IResource res)
project.delete(true, true, null);
} catch (Exception e) {
- fail("Failed to clean up test project: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Failed to clean up test project: " + e.getLocalizedMessage());
}
}
@@ -289,7 +285,7 @@ protected Resource createTestResource(String name) {
try {
InputStream input =
- EmfTransactionTestsBundle.getEntry("/test_models/" + name).openStream(); //$NON-NLS-1$
+ EmfTransactionTestsBundle.getEntry("/test_models/" + name).openStream();
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(
new Path(PROJECT_NAME + '/' + name));
@@ -299,7 +295,7 @@ protected Resource createTestResource(String name) {
URI.createPlatformResourceURI(file.getFullPath().toString(), true).toString());
} catch (Exception e) {
e.printStackTrace();
- fail("Exception creating test resource: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Exception creating test resource: " + e.getLocalizedMessage());
}
return result;
@@ -322,7 +318,7 @@ protected void unloadAndRemove(Resource res) {
*/
protected void fail(Exception e) {
e.printStackTrace();
- fail("Should not have thrown: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Should not have thrown: " + e.getLocalizedMessage());
}
/**
@@ -333,7 +329,7 @@ protected void fail(Exception e) {
* @see #find(String)
*/
protected void assertFound(String name) {
- assertNotNull("Did not find " + name, find(testResource, name)); //$NON-NLS-1$
+ assertNotNull("Did not find " + name, find(testResource, name));
}
/**
@@ -348,7 +344,7 @@ protected void assertFound(String name) {
* @see #find(Object, String)
*/
protected void assertFound(Object start, String name) {
- assertNotNull("Did not find " + name, find(testResource, name)); //$NON-NLS-1$
+ assertNotNull("Did not find " + name, find(testResource, name));
}
/**
@@ -359,7 +355,7 @@ protected void assertFound(Object start, String name) {
* @see #find(String)
*/
protected void assertNotFound(String name) {
- assertNull("Found " + name, find(testResource, name)); //$NON-NLS-1$
+ assertNull("Found " + name, find(testResource, name));
}
/**
@@ -374,7 +370,7 @@ protected void assertNotFound(String name) {
* @see #find(Object, String)
*/
protected void assertNotFound(Object start, String name) {
- assertNull("Found " + name, find(testResource, name)); //$NON-NLS-1$
+ assertNull("Found " + name, find(testResource, name));
}
/**
@@ -452,7 +448,7 @@ private List getContents(Object object) {
* @return the parts between the slashes
*/
private String[] tokenize(String qname) {
- return qname.split("/"); //$NON-NLS-1$
+ return qname.split("/");
}
/**
@@ -496,7 +492,7 @@ public String caseWriter(Writer object) {
public String casePerson(Person object) {
if (object.getFirstName() == null) {
if (object.getLastName() == null) {
- return ""; //$NON-NLS-1$
+ return "";
} else {
return object.getLastName();
}
@@ -514,7 +510,7 @@ public String casePerson(Person object) {
@Override
public String defaultCase(EObject object) {
- return ""; //$NON-NLS-1$
+ return "";
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/BasicTransactionTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/BasicTransactionTest.java
index ad5e91ec..a1ec2d7d 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/BasicTransactionTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/BasicTransactionTest.java
@@ -12,13 +12,16 @@
*/
package org.eclipse.emf.transaction.tests;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.notify.Notification;
@@ -43,23 +46,17 @@
import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
import org.eclipse.emf.transaction.internal.EMFTransactionStatusCodes;
import org.eclipse.emf.transaction.tests.fixtures.TestListener;
-
+import org.junit.Assert;
+import org.junit.Test;
public class BasicTransactionTest extends AbstractTest {
- public BasicTransactionTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(BasicTransactionTest.class, "Basic Transaction Tests"); //$NON-NLS-1$
- }
-
/**
* Tests that read transactions are not actually enforced for EList initialization,
* etc.
*/
+ @Test
public void test_read() {
try {
// should be able to read with running exclusive, as we cannot
@@ -73,6 +70,7 @@ public void test_read() {
/**
* Tests that we can read in a read-only transaction.
*/
+ @Test
public void test_read_readOnlyTransaction() {
// should be able to read in a read-only transaction
startReading();
@@ -85,6 +83,7 @@ public void test_read_readOnlyTransaction() {
/**
* Tests that we can read in a read-write transaction.
*/
+ @Test
public void test_read_readWriteTransaction() {
// should be able to read in a read/write transaction
startWriting();
@@ -97,6 +96,7 @@ public void test_read_readWriteTransaction() {
/**
* Tests that we can read in a runExclusive() runnable.
*/
+ @Test
public void test_read_exclusive() {
try {
// should be able to read exclusively
@@ -109,7 +109,7 @@ public void run() {
assertNotNull(book[0]);
} catch (InterruptedException e) {
- fail("Should not be interrupted"); //$NON-NLS-1$
+ Assert.fail("Should not be interrupted"); //$NON-NLS-1$
} catch (Exception e) {
fail(e);
}
@@ -119,6 +119,7 @@ public void run() {
* Tests that nested runExclusive() runnables do not open
* (superfluous) nested transactions.
*/
+ @Test
public void test_read_exclusive_nested() {
try {
domain.runExclusive(new Runnable() {
@@ -140,19 +141,19 @@ public void run() {
assertNull(active.getParent());
}});
} catch (InterruptedException e) {
- fail("Should not be interrupted"); //$NON-NLS-1$
+ Assert.fail("Should not be interrupted"); //$NON-NLS-1$
} catch (Exception e) {
fail(e);
}
}});
} catch (InterruptedException e) {
- fail("Should not be interrupted"); //$NON-NLS-1$
+ Assert.fail("Should not be interrupted"); //$NON-NLS-1$
} catch (Exception e) {
fail(e);
}
}});
} catch (InterruptedException e) {
- fail("Should not be interrupted"); //$NON-NLS-1$
+ Assert.fail("Should not be interrupted"); //$NON-NLS-1$
} catch (Exception e) {
fail(e);
}
@@ -161,6 +162,7 @@ public void run() {
/**
* Tests that we cannot write without a write transaction.
*/
+ @Test
public void test_write() {
startReading();
@@ -173,7 +175,7 @@ public void test_write() {
book.setTitle("New Title"); //$NON-NLS-1$
// should have thrown
- fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
} catch (IllegalStateException e) {
// success
trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
@@ -185,6 +187,7 @@ public void test_write() {
/**
* Tests that we cannot write in a read-only transaction.
*/
+ @Test
public void test_write_readOnlytransaction() {
try {
startReading();
@@ -195,7 +198,7 @@ public void test_write_readOnlytransaction() {
book.setTitle("New Title"); //$NON-NLS-1$
// should have thrown
- fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
} catch (IllegalStateException e) {
// success
trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
@@ -209,6 +212,7 @@ public void test_write_readOnlytransaction() {
/**
* Tests that we can write in a read-write transaction.
*/
+ @Test
public void test_write_readWritetransaction() {
try {
startWriting();
@@ -235,6 +239,7 @@ public void test_write_readWritetransaction() {
* currently has a write transaction open. Also tests that the thread that
* had the valid write transaction is aborted.
*/
+ @Test
public void test_write_wrongThread() {
final Object monitor = new Object();
@@ -256,7 +261,7 @@ public void run() {
// attempt commit. Should roll back because of abort
try {
xa.commit();
- fail("Should have thrown RollbackException"); //$NON-NLS-1$
+ Assert.fail("Should have thrown RollbackException"); //$NON-NLS-1$
} catch (RollbackException e) {
// success
trace("Got expected rollback: " + e.getLocalizedMessage()); //$NON-NLS-1$
@@ -287,7 +292,7 @@ public void run() {
book.setTitle("New Title"); //$NON-NLS-1$
// should have thrown
- fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
} catch (IllegalStateException e) {
// success
trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
@@ -304,6 +309,7 @@ public void run() {
/**
* Tests that we can use the command stack to execute a writing command.
*/
+ @Test
public void test_write_command() {
startReading();
@@ -335,6 +341,7 @@ public void test_write_command() {
* Tests that we can load and unload resources (having contents) without a write
* transaction.
*/
+ @Test
public void test_loadUnloadDuringRead() throws Exception {
// create a new domain that hasn't yet loaded the test resource
doTearDown();
@@ -423,6 +430,7 @@ public void test_loadUnloadDuringRead() throws Exception {
* Tests that changes to the contents of a loaded resource may not be performed
* in a read transaction.
*/
+ @Test
public void test_resourceContentsChanges_read() {
try {
startReading();
@@ -430,7 +438,7 @@ public void test_resourceContentsChanges_read() {
testResource.getContents().add(EXTLibraryFactory.eINSTANCE.createLibrary());
// should have thrown
- fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
} catch (IllegalStateException e) {
// success
trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
@@ -445,6 +453,7 @@ public void test_resourceContentsChanges_read() {
* Tests that changes to the contents of a loaded resource may be performed
* in a write transaction.
*/
+ @Test
public void test_resourceContentsChanges_write() {
try {
startWriting();
@@ -460,6 +469,7 @@ public void test_resourceContentsChanges_write() {
/**
* Tests that we cannot add a root to a newly created resource in a read transaction.
*/
+ @Test
public void test_newResourceContentsChanges_read() {
try {
startReading();
@@ -471,7 +481,7 @@ public void test_newResourceContentsChanges_read() {
res.getContents().add(EXTLibraryFactory.eINSTANCE.createLibrary());
// should have thrown
- fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
} catch (IllegalStateException e) {
// success
trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
@@ -485,6 +495,7 @@ public void test_newResourceContentsChanges_read() {
/**
* Tests that we can add a root to a newly created resource in a write transaction.
*/
+ @Test
public void test_newResourceContentsChanges_write() {
try {
startWriting();
@@ -505,6 +516,7 @@ public void test_newResourceContentsChanges_write() {
* Tests that a RunnableWithResult has its status set correctly when it is
* rolled back due to concurrent write.
*/
+ @Test
public void test_concurrentWrite_runnable() {
final Object monitor = new Object();
@@ -550,6 +562,7 @@ public void run() {
/**
* Tests that we cannot close a transaction that is already closed.
*/
+ @Test
public void test_closedTransaction_close() {
// should be able to read in a read-only transaction
startReading();
@@ -560,7 +573,7 @@ public void test_closedTransaction_close() {
tx.commit();
// should have thrown
- fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
} catch (IllegalStateException e) {
// success
trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
@@ -572,13 +585,14 @@ public void test_closedTransaction_close() {
tx.rollback();
// should have thrown
- fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
} catch (IllegalStateException e) {
// success
trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
}
+ @Test
public void test_readWrongThread_250498() {
final Object monitor = new Object();
final List readNotifications = new java.util.ArrayList();
@@ -657,7 +671,7 @@ public void run() {
try {
xa.commit();
} catch (RollbackException e) {
- fail("Should not have rolled back: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Should not have rolled back: " + e.getLocalizedMessage()); //$NON-NLS-1$
} finally {
xa = null;
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ChangeDescriptionTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ChangeDescriptionTest.java
index f6f357d3..557a94e3 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ChangeDescriptionTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ChangeDescriptionTest.java
@@ -12,13 +12,11 @@
*/
package org.eclipse.emf.transaction.tests;
+import static org.junit.Assert.assertEquals;
+
import java.io.File;
import java.util.Collections;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.eclipse.emf.common.command.BasicCommandStack;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.notify.AdapterFactory;
@@ -45,13 +43,16 @@
import org.eclipse.emf.transaction.ResourceSetListenerImpl;
import org.eclipse.emf.transaction.RollbackException;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* A test case for https://bugs.eclipse.org/bugs/show_bug.cgi?id=460206
*
* @author Esteban Dugueperoux
*/
-public class ChangeDescriptionTest extends TestCase {
+public class ChangeDescriptionTest {
private File tempFile;
@@ -61,13 +62,8 @@ public class ChangeDescriptionTest extends TestCase {
private EPackage rootEPackage1;
- public static Test suite() {
- return new TestSuite(ChangeDescriptionTest.class, "Change Description Tests"); //$NON-NLS-1$
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
resourceSet = new ResourceSetImpl();
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
tempFile = File.createTempFile("test", ".ecore");
@@ -77,10 +73,21 @@ protected void setUp() throws Exception {
resource.getContents().add(rootEPackage1);
}
+ @After
+ public void tearDown() {
+ rootEPackage1 = null;
+ resource = null;
+ resourceSet = null;
+ tempFile.delete();
+ tempFile = null;
+ }
+
+ @Test
public void testChangeDescriptionInNonEMFTEditingDomain1() {
testChangeDescriptionInNonEMFTEditingDomain(rootEPackage1);
}
+ @Test
public void testChangeDescriptionInNonEMFTEditingDomain2() {
EPackage rootEPackage2 = EcoreFactory.eINSTANCE.createEPackage();
resource.getContents().add(rootEPackage2);
@@ -88,7 +95,8 @@ public void testChangeDescriptionInNonEMFTEditingDomain2() {
}
private void testChangeDescriptionInNonEMFTEditingDomain(EPackage targetOfSecondEClass) {
- ComposedAdapterFactory.Descriptor.Registry registry = EMFEditPlugin.getComposedAdapterFactoryDescriptorRegistry();
+ ComposedAdapterFactory.Descriptor.Registry registry = EMFEditPlugin
+ .getComposedAdapterFactoryDescriptorRegistry();
AdapterFactory adapterFactory = new ComposedAdapterFactory(registry);
BasicCommandStack commandStack = new BasicCommandStack();
EditingDomain domain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, resourceSet);
@@ -99,7 +107,8 @@ private void testChangeDescriptionInNonEMFTEditingDomain(EPackage targetOfSecond
changeRecorder.beginRecording(changeDescription, Collections.singleton(resourceSet));
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
Command addCmd = AddCommand.create(domain, rootEPackage1, EcorePackage.Literals.EPACKAGE__ECLASSIFIERS, eClass);
- addCmd = addCmd.chain(AddCommand.create(domain, targetOfSecondEClass, EcorePackage.Literals.EPACKAGE__ECLASSIFIERS, EcoreFactory.eINSTANCE.createEClass()));
+ addCmd = addCmd.chain(AddCommand.create(domain, targetOfSecondEClass,
+ EcorePackage.Literals.EPACKAGE__ECLASSIFIERS, EcoreFactory.eINSTANCE.createEClass()));
domain.getCommandStack().execute(addCmd);
changeRecorder.endRecording();
@@ -110,10 +119,12 @@ private void testChangeDescriptionInNonEMFTEditingDomain(EPackage targetOfSecond
changeRecorder.dispose();
}
+ @Test
public void testChangeDescriptionInEMFTEditingDomain1() {
testChangeDescriptionInEMFTEditingDomain(rootEPackage1);
}
+ @Test
public void testChangeDescriptionInEMFTEditingDomain2() {
EPackage rootEPackage2 = EcoreFactory.eINSTANCE.createEPackage();
resource.getContents().add(rootEPackage2);
@@ -121,7 +132,8 @@ public void testChangeDescriptionInEMFTEditingDomain2() {
}
private void testChangeDescriptionInEMFTEditingDomain(EPackage targetOfPrecommit) {
- TransactionalEditingDomain domain = TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain(resourceSet);
+ TransactionalEditingDomain domain = TransactionalEditingDomain.Factory.INSTANCE
+ .createEditingDomain(resourceSet);
ChangeRecorder changeRecorder = new ChangeRecorder(resourceSet);
@@ -161,11 +173,12 @@ public boolean isAggregatePrecommitListener() {
@Override
public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
- if(!added) {
+ if (!added) {
added = true;
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("EClassFromPrecommit");
- return AddCommand.create(getTarget(), rootEPackage, EcorePackage.Literals.EPACKAGE__ECLASSIFIERS, eClass);
+ return AddCommand.create(getTarget(), rootEPackage, EcorePackage.Literals.EPACKAGE__ECLASSIFIERS,
+ eClass);
}
return null;
@@ -182,14 +195,4 @@ public void resourceSetChanged(ResourceSetChangeEvent event) {
}
- @Override
- protected void tearDown() throws Exception {
- rootEPackage1 = null;
- resource = null;
- resourceSet = null;
- tempFile.delete();
- tempFile = null;
- super.tearDown();
- }
-
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainRegistryTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainRegistryTest.java
index ce2dfbf3..ff835547 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainRegistryTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainRegistryTest.java
@@ -11,18 +11,24 @@
*/
package org.eclipse.emf.transaction.tests;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
import java.lang.ref.WeakReference;
import java.util.List;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.tests.fixtures.TestEditingDomain;
import org.eclipse.emf.transaction.tests.fixtures.TestListener;
+import org.junit.Assert;
+import org.junit.Test;
/**
@@ -31,22 +37,15 @@
* @author Christian W. Damus (cdamus)
*/
public class EditingDomainRegistryTest extends AbstractTest {
- private static final String TEST_DOMAIN1 = "org.eclipse.emf.transaction.tests.TestDomain1"; //$NON-NLS-1$
- private static final String TEST_DOMAIN2 = "org.eclipse.emf.transaction.tests.TestDomain2"; //$NON-NLS-1$
- private static final String TEST_DOMAIN3 = "org.eclipse.emf.transaction.tests.TestDomain3"; //$NON-NLS-1$
- private static final String TEST_DOMAIN4 = "org.eclipse.emf.transaction.tests.TestDomain4"; //$NON-NLS-1$
-
- public EditingDomainRegistryTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(EditingDomainRegistryTest.class, "Editing Domain Registry Tests"); //$NON-NLS-1$
- }
+ private static final String TEST_DOMAIN1 = "org.eclipse.emf.transaction.tests.TestDomain1";
+ private static final String TEST_DOMAIN2 = "org.eclipse.emf.transaction.tests.TestDomain2";
+ private static final String TEST_DOMAIN3 = "org.eclipse.emf.transaction.tests.TestDomain3";
+ private static final String TEST_DOMAIN4 = "org.eclipse.emf.transaction.tests.TestDomain4";
/**
* Tests dynamically adding and removing domains in the registry.
*/
+ @Test
public void test_dynamicAddRemove() {
assertNull(domain.getID());
@@ -86,9 +85,9 @@ public void ignore_test_staticRegistration() {
// cannot remove statically registered domains
try {
TransactionalEditingDomain.Registry.INSTANCE.remove(TEST_DOMAIN1);
- fail("Should have thrown IllegalArgumentException"); //$NON-NLS-1$
+ Assert.fail("Should have thrown IllegalArgumentException");
} catch (IllegalArgumentException e) {
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
}
// check that it is not recreated by another get call
@@ -101,90 +100,93 @@ public void ignore_test_staticRegistration() {
/**
* Tests the replacement of a domain under an ID with another.
*/
+ @Test
public void test_replaceDomain() {
TransactionalEditingDomain domain1 = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo"); //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.foo");
assertNull(domain1);
domain1 = new TestEditingDomain.FactoryImpl().createEditingDomain();
assertNotNull(domain1);
TransactionalEditingDomain.Registry.INSTANCE.add(
- "org.eclipse.emf.transaction.tests.foo", //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.foo",
domain1);
// check that we successfully registered domain1
assertSame(
domain1,
TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo")); //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.foo"));
// create another domain and register it under the same ID
TransactionalEditingDomain domain2 = new TestEditingDomain.FactoryImpl().createEditingDomain();
TransactionalEditingDomain.Registry.INSTANCE.add(
- "org.eclipse.emf.transaction.tests.foo", //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.foo",
domain2);
// check that we successfully replaced domain1
assertSame(
domain2,
TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo")); //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.foo"));
- TransactionalEditingDomain.Registry.INSTANCE.remove("org.eclipse.emf.transaction.tests.foo"); //$NON-NLS-1$
+ TransactionalEditingDomain.Registry.INSTANCE.remove("org.eclipse.emf.transaction.tests.foo");
}
/**
* Tests the automatic re-registration of a domain when its ID is changed.
*/
+ @Test
public void test_changeDomainId() {
TransactionalEditingDomain domain1 = new TestEditingDomain.FactoryImpl().createEditingDomain();
assertNotNull(domain1);
- domain1.setID("org.eclipse.emf.transaction.tests.foo"); //$NON-NLS-1$
+ domain1.setID("org.eclipse.emf.transaction.tests.foo");
// not yet registered
assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo")); //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.foo"));
assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.bar")); //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.bar"));
// register it
TransactionalEditingDomain.Registry.INSTANCE.add(
- "org.eclipse.emf.transaction.tests.foo", //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.foo",
domain1);
assertNotNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo")); //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.foo"));
assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.bar")); //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.bar"));
// change the ID
- domain1.setID("org.eclipse.emf.transaction.tests.bar"); //$NON-NLS-1$
+ domain1.setID("org.eclipse.emf.transaction.tests.bar");
// automatically re-registered
assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo")); //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.foo"));
assertNotNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.bar")); //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.bar"));
// remove
TransactionalEditingDomain.Registry.INSTANCE.remove(domain1.getID());
assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo")); //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.foo"));
assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.bar")); //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.bar"));
// change the ID back
- domain1.setID("org.eclipse.emf.transaction.tests.foo"); //$NON-NLS-1$
+ domain1.setID("org.eclipse.emf.transaction.tests.foo");
// didn't re-register itself this time
assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.bar")); //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.bar"));
assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo")); //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.foo"));
}
/**
* Tests the attachment and detachment of registered listeners to editing domains.
*/
+ @Test
public void test_listenerRegistration_singleDomain_multipleListeners() {
TransactionalEditingDomain domain3 = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
TEST_DOMAIN3);
@@ -203,7 +205,7 @@ public void test_listenerRegistration_singleDomain_multipleListeners() {
domain3.runExclusive(new Runnable() {
public void run() {
finalDomain3.getResourceSet().createResource(
- URI.createFileURI("/tmp/dummy.extlibrary")); //$NON-NLS-1$
+ URI.createFileURI("/tmp/dummy.extlibrary"));
}});
} catch (Exception e) {
fail(e);
@@ -244,6 +246,7 @@ public void run() {
/**
* Tests the attachment and detachment of registered listeners to editing domains.
*/
+ @Test
public void test_listenerRegistration_multiDomains_singleListener() {
TransactionalEditingDomain domain3 = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
TEST_DOMAIN3);
@@ -269,7 +272,7 @@ public void test_listenerRegistration_multiDomains_singleListener() {
domain3.runExclusive(new Runnable() {
public void run() {
finalDomain3.getResourceSet().createResource(
- URI.createFileURI("/tmp/dummy.extlibrary")); //$NON-NLS-1$
+ URI.createFileURI("/tmp/dummy.extlibrary"));
}});
} catch (Exception e) {
fail(e);
@@ -292,7 +295,7 @@ public void run() {
domain4.runExclusive(new Runnable() {
public void run() {
finalDomain4.getResourceSet().createResource(
- URI.createFileURI("/tmp/dummy.extlibrary")); //$NON-NLS-1$
+ URI.createFileURI("/tmp/dummy.extlibrary"));
}});
} catch (Exception e) {
fail(e);
@@ -327,6 +330,7 @@ public void run() {
/**
* Tests the attachment and detachment of registered listeners to editing domains.
*/
+ @Test
public void test_listenerRegistration_universalListener() {
TransactionalEditingDomain domain3 = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
TEST_DOMAIN3);
@@ -352,7 +356,7 @@ public void test_listenerRegistration_universalListener() {
domain3.runExclusive(new Runnable() {
public void run() {
finalDomain3.getResourceSet().createResource(
- URI.createFileURI("/tmp/dummy.extlibrary")); //$NON-NLS-1$
+ URI.createFileURI("/tmp/dummy.extlibrary"));
}});
} catch (Exception e) {
fail(e);
@@ -375,7 +379,7 @@ public void run() {
domain4.runExclusive(new Runnable() {
public void run() {
finalDomain4.getResourceSet().createResource(
- URI.createFileURI("/tmp/dummy.extlibrary")); //$NON-NLS-1$
+ URI.createFileURI("/tmp/dummy.extlibrary"));
}});
} catch (Exception e) {
fail(e);
@@ -403,10 +407,11 @@ public void run() {
* Tests that we can omit the factory class in the editing domain
* registration to use the default shared factory instance.
*/
+ @Test
public void test_registerDefaultFactory_136674() {
TransactionalEditingDomain defaultDomain =
TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.TestDefaultFactoryDomain1"); //$NON-NLS-1$
+ "org.eclipse.emf.transaction.tests.TestDefaultFactoryDomain1");
assertNotNull(defaultDomain);
}
@@ -454,3 +459,4 @@ public static TestListener3 getInstance() {
}
}
+
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainTest.java
index 4f2cfa48..637c0525 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainTest.java
@@ -11,6 +11,11 @@
*/
package org.eclipse.emf.transaction.tests;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -24,11 +29,10 @@
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.junit.Assert;
+import org.junit.Test;
import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
/**
* Tests some basic editing domain life-cycle API.
@@ -36,35 +40,27 @@
* @author Christian W. Damus (cdamus)
*/
public class EditingDomainTest extends AbstractTest {
-
- public EditingDomainTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(EditingDomainTest.class, "Editing Domain Life-Cycle Tests"); //$NON-NLS-1$
- }
/**
- * Tests that the unmapping of the resourceset-domain link works as expected
- * and that it is performed when disposing the editing domain.
+ * Tests that the unmapping of the resourceset-domain link works as expected and
+ * that it is performed when disposing the editing domain.
*/
+ @Test
public void test_factoryUnmapResourceSet_161168() {
// ReferenceQueue q = new ReferenceQueue();
-
- TransactionalEditingDomain domain =
- TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain();
+
+ TransactionalEditingDomain domain = TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain();
ResourceSet rset = domain.getResourceSet();
-
+
// WeakReference ref = new WeakReference(domain, q);
-
+
// check initial conditions
assertSame(domain, TransactionUtil.getEditingDomain(rset));
-
+
// dispose and forget the editing domain
domain.dispose();
domain = null;
-
+
// verify that the resource set has forgotten its editing domain
assertNull(TransactionUtil.getEditingDomain(rset));
@@ -74,103 +70,103 @@ public void test_factoryUnmapResourceSet_161168() {
// // verify that the domain was reclaimed
// assertSame(ref, q.poll());
}
-
- /**
- * Tests the support for read-only resources in the workspace.
- */
- public void ignore_test_readOnlyResourceMap_workspace_bug156428() {
- IWorkspace ws = ResourcesPlugin.getWorkspace();
-
- final IProject proj = ws.getRoot().getProject("read_only_test"); //$NON-NLS-1$
-
- addTearDownAction(new Runnable() {
- public void run() {
- delete(proj);
- }});
-
- try {
- proj.create(null);
- proj.open(null);
- } catch (Exception e) {
- fail("Failed to create project: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
-
- IFile file = proj.getFile("testResource.xmi"); //$NON-NLS-1$
-
- // a resource that doesn't exist should be writable
- Resource res = domain.getResourceSet().createResource(
- URI.createPlatformResourceURI(file.getFullPath().toString(), true));
- assertFalse(domain.isReadOnly(res));
-
- domain.getResourceSet().getResources().remove(res);
-
- try {
- file.create(new ByteArrayInputStream(new byte[0]), false, null);
- } catch (Exception e) {
- fail("Failed to create file: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
-
- // a resource that does exist and is writable should be writable
- res = domain.getResourceSet().createResource(
- URI.createPlatformResourceURI(file.getFullPath().toString(), true));
- assertFalse(domain.isReadOnly(res));
-
- domain.getResourceSet().getResources().remove(res);
-
- ResourceAttributes attribs = new ResourceAttributes();
- attribs.setReadOnly(true);
- try {
- file.setResourceAttributes(attribs);
- } catch (Exception e) {
- fail("Failed to set file read-only: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
-
- // a resource that does exist and is not writable should be read-only
- res = domain.getResourceSet().createResource(
- URI.createPlatformResourceURI(file.getFullPath().toString(), true));
- assertTrue(domain.isReadOnly(res));
- }
-
- /**
- * Tests the support for read-only resources in the file system (outside
- * of the workspace).
- */
- public void test_readOnlyResourceMap_filesystem_bug156428() {
- final File file;
-
- try {
- file = File.createTempFile("testReadOnly", ".xmi"); //$NON-NLS-1$ //$NON-NLS-2$
- } catch (Exception e) {
- fail("Failed to create temporary file: " + e.getLocalizedMessage()); //$NON-NLS-1$
-
- // compiler doesn't know that fail() throws
- throw new AssertionFailedError();
- }
-
- addTearDownAction(new Runnable() {
- public void run() {
- delete(file);
- }});
-
- // a resource that doesn't exist should be writable
- Resource res = domain.getResourceSet().createResource(
- URI.createFileURI(file.getAbsolutePath() + "2")); //$NON-NLS-1$
- assertFalse(domain.isReadOnly(res));
-
- domain.getResourceSet().getResources().remove(res);
-
- // a resource that does exist and is writable should be writable
- res = domain.getResourceSet().createResource(
- URI.createFileURI(file.getAbsolutePath()));
- assertFalse(domain.isReadOnly(res));
-
- domain.getResourceSet().getResources().remove(res);
-
- file.setReadOnly();
-
- // a resource that does exist and is not writable should be read-only
- res = domain.getResourceSet().createResource(
- URI.createFileURI(file.getAbsolutePath()));
- assertTrue(domain.isReadOnly(res));
- }
+
+ /**
+ * Tests the support for read-only resources in the workspace.
+ */
+ public void ignore_test_readOnlyResourceMap_workspace_bug156428() {
+ IWorkspace ws = ResourcesPlugin.getWorkspace();
+
+ final IProject proj = ws.getRoot().getProject("read_only_test");
+
+ addTearDownAction(new Runnable() {
+ public void run() {
+ delete(proj);
+ }
+ });
+
+ try {
+ proj.create(null);
+ proj.open(null);
+ } catch (Exception e) {
+ Assert.fail("Failed to create project: " + e.getLocalizedMessage());
+ }
+
+ IFile file = proj.getFile("testResource.xmi");
+
+ // a resource that doesn't exist should be writable
+ Resource res = domain.getResourceSet()
+ .createResource(URI.createPlatformResourceURI(file.getFullPath().toString(), true));
+ assertFalse(domain.isReadOnly(res));
+
+ domain.getResourceSet().getResources().remove(res);
+
+ try {
+ file.create(new ByteArrayInputStream(new byte[0]), false, null);
+ } catch (Exception e) {
+ Assert.fail("Failed to create file: " + e.getLocalizedMessage());
+ }
+
+ // a resource that does exist and is writable should be writable
+ res = domain.getResourceSet()
+ .createResource(URI.createPlatformResourceURI(file.getFullPath().toString(), true));
+ assertFalse(domain.isReadOnly(res));
+
+ domain.getResourceSet().getResources().remove(res);
+
+ ResourceAttributes attribs = new ResourceAttributes();
+ attribs.setReadOnly(true);
+ try {
+ file.setResourceAttributes(attribs);
+ } catch (Exception e) {
+ Assert.fail("Failed to set file read-only: " + e.getLocalizedMessage());
+ }
+
+ // a resource that does exist and is not writable should be read-only
+ res = domain.getResourceSet()
+ .createResource(URI.createPlatformResourceURI(file.getFullPath().toString(), true));
+ assertTrue(domain.isReadOnly(res));
+ }
+
+ /**
+ * Tests the support for read-only resources in the file system (outside of the
+ * workspace).
+ */
+ @Test
+ public void test_readOnlyResourceMap_filesystem_bug156428() {
+ final File file;
+
+ try {
+ file = File.createTempFile("testReadOnly", ".xmi");
+ } catch (Exception e) {
+ Assert.fail("Failed to create temporary file: " + e.getLocalizedMessage());
+
+ // compiler doesn't know that fail() throws
+ throw new AssertionFailedError();
+ }
+
+ addTearDownAction(new Runnable() {
+ public void run() {
+ delete(file);
+ }
+ });
+
+ // a resource that doesn't exist should be writable
+ Resource res = domain.getResourceSet().createResource(URI.createFileURI(file.getAbsolutePath() + "2"));
+ assertFalse(domain.isReadOnly(res));
+
+ domain.getResourceSet().getResources().remove(res);
+
+ // a resource that does exist and is writable should be writable
+ res = domain.getResourceSet().createResource(URI.createFileURI(file.getAbsolutePath()));
+ assertFalse(domain.isReadOnly(res));
+
+ domain.getResourceSet().getResources().remove(res);
+
+ file.setReadOnly();
+
+ // a resource that does exist and is not writable should be read-only
+ res = domain.getResourceSet().createResource(URI.createFileURI(file.getAbsolutePath()));
+ assertTrue(domain.isReadOnly(res));
+ }
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainValidatorTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainValidatorTest.java
index 8886d3a8..6cce2f35 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainValidatorTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainValidatorTest.java
@@ -11,13 +11,13 @@
*/
package org.eclipse.emf.transaction.tests;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import static org.junit.Assert.assertEquals;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.examples.extlibrary.Book;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.tests.fixtures.TestValidationEditingDomain;
+import org.junit.Test;
/**
* Tests validator creation during transaction editing domain commit
@@ -26,17 +26,10 @@
*/
public class EditingDomainValidatorTest extends AbstractTest {
- private static final String TEST_DOMAIN1 = "org.eclipse.emf.transaction.tests.TestValidationDomain1"; //$NON-NLS-1$
+ private static final String TEST_DOMAIN1 = "org.eclipse.emf.transaction.tests.TestValidationDomain1";
private static final TransactionalEditingDomain myDomain = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(TEST_DOMAIN1);
- public EditingDomainValidatorTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(EditingDomainValidatorTest.class, "Editing Domain Validator Tests"); //$NON-NLS-1$
- }
/** May be overridden by subclasses to create non-default editing domains. */
@Override
@@ -52,13 +45,14 @@ protected ResourceSet createResourceSet() {
/**
* Tests overriding of validators in editing domain
*/
+ @Test
public void test_createValidators_177643() {
TestValidationEditingDomain.enableCustomValidator.set(true);
int initialCount = TestValidationEditingDomain.readWriteValidatorHitCount.get();
startWriting();
- Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
- book.setTitle("New Title"); //$NON-NLS-1$
+ Book book = (Book) find("root/Root Book");
+ book.setTitle("New Title");
commit();
assertEquals(initialCount + 1, TestValidationEditingDomain.readWriteValidatorHitCount.get());
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/JobManagerSuspensionDeadlockTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/JobManagerSuspensionDeadlockTest.java
index 8fd7aa5d..18134a29 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/JobManagerSuspensionDeadlockTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/JobManagerSuspensionDeadlockTest.java
@@ -12,27 +12,23 @@
*/
package org.eclipse.emf.transaction.tests;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl;
+import org.junit.Test;
/**
* Tests that transactions do not dead-lock when the Eclipse Job Manager is
* suspended.
*/
@SuppressWarnings("nls")
-public class JobManagerSuspensionDeadlockTest extends TestCase {
-
- public static Test suite() {
- return new TestSuite(JobManagerSuspensionDeadlockTest.class,
- "JobManager Suspension Dead-lock Tests");
- }
+public class JobManagerSuspensionDeadlockTest {
+ @Test
public void testDeadlock()
throws Exception {
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/LifecycleListenersTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/LifecycleListenersTest.java
index 3775deb9..d8f319d2 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/LifecycleListenersTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/LifecycleListenersTest.java
@@ -11,78 +11,63 @@
*/
package org.eclipse.emf.transaction.tests;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.util.Arrays;
import java.util.List;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.eclipse.emf.examples.extlibrary.Book;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.TransactionalEditingDomainEvent;
import org.eclipse.emf.transaction.TransactionalEditingDomainListener;
import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.junit.Test;
/**
* Tests the dispatching of life-cycle events to listeners.
*
* @author Christian W. Damus (cdamus)
*/
-@SuppressWarnings("nls")
-public class LifecycleListenersTest
- extends AbstractTest {
+public class LifecycleListenersTest extends AbstractTest {
private LifecycleListener listener;
- public LifecycleListenersTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(LifecycleListenersTest.class,
- "Editing Domain Life-cycle Event Tests");
- }
-
/**
- * Tests that we get events in the right sequence in a normal commit
- * scenario.
+ * Tests that we get events in the right sequence in a normal commit scenario.
*/
+ @Test
public void test_eventSequence_commit() {
final Book book = (Book) find("root/Root Book");
assertNotNull(book);
startWriting();
-
book.setTitle("New Title");
-
startWriting();
-
book.setTitle("Another Title");
-
commit();
-
commit();
- List expected = Arrays.asList(
- TransactionalEditingDomainEvent.TRANSACTION_STARTING,
- TransactionalEditingDomainEvent.TRANSACTION_STARTED,
- TransactionalEditingDomainEvent.TRANSACTION_CLOSING,
- // the transaction for post-commit notifications is a root
- TransactionalEditingDomainEvent.TRANSACTION_STARTING,
- TransactionalEditingDomainEvent.TRANSACTION_STARTED,
- TransactionalEditingDomainEvent.TRANSACTION_CLOSING,
- TransactionalEditingDomainEvent.TRANSACTION_CLOSED,
- // the original root transaction is closed after post-commit
- TransactionalEditingDomainEvent.TRANSACTION_CLOSED);
-
- assertEquals("Wrong event sequence", expected,
- listener.eventTypesReceived);
+ List expected = Arrays.asList(TransactionalEditingDomainEvent.TRANSACTION_STARTING,
+ TransactionalEditingDomainEvent.TRANSACTION_STARTED,
+ TransactionalEditingDomainEvent.TRANSACTION_CLOSING,
+ // the transaction for post-commit notifications is a root
+ TransactionalEditingDomainEvent.TRANSACTION_STARTING,
+ TransactionalEditingDomainEvent.TRANSACTION_STARTED,
+ TransactionalEditingDomainEvent.TRANSACTION_CLOSING, TransactionalEditingDomainEvent.TRANSACTION_CLOSED,
+ // the original root transaction is closed after post-commit
+ TransactionalEditingDomainEvent.TRANSACTION_CLOSED);
+
+ assertEquals("Wrong event sequence", expected, listener.eventTypesReceived);
}
/**
- * Tests that we get events in the right sequence in a normal commit
- * scenario.
+ * Tests that we get events in the right sequence in a normal commit scenario.
*/
+ @Test
public void test_eventSequence_rollback() {
final Book book = (Book) find("root/Root Book");
assertNotNull(book);
@@ -90,25 +75,23 @@ public void test_eventSequence_rollback() {
startWriting();
book.setTitle("New Title");
-
+
startWriting();
-
+
book.setTitle("Another Title");
-
+
commit();
-
+
rollback();
- List expected = Arrays.asList(
- TransactionalEditingDomainEvent.TRANSACTION_STARTING,
- TransactionalEditingDomainEvent.TRANSACTION_STARTED,
- TransactionalEditingDomainEvent.TRANSACTION_CLOSING,
- // without any notifications to send, there is no additional
- // transaction for post-commit
- TransactionalEditingDomainEvent.TRANSACTION_CLOSED);
+ List expected = Arrays.asList(TransactionalEditingDomainEvent.TRANSACTION_STARTING,
+ TransactionalEditingDomainEvent.TRANSACTION_STARTED,
+ TransactionalEditingDomainEvent.TRANSACTION_CLOSING,
+ // without any notifications to send, there is no additional
+ // transaction for post-commit
+ TransactionalEditingDomainEvent.TRANSACTION_CLOSED);
- assertEquals("Wrong event sequence", expected,
- listener.eventTypesReceived);
+ assertEquals("Wrong event sequence", expected, listener.eventTypesReceived);
}
//
@@ -116,31 +99,22 @@ public void test_eventSequence_rollback() {
//
@Override
- protected void doSetUp()
- throws Exception {
-
+ protected void doSetUp() throws Exception {
super.doSetUp();
-
listener = new LifecycleListener();
- TransactionUtil.getAdapter(domain,
- TransactionalEditingDomain.Lifecycle.class)
- .addTransactionalEditingDomainListener(listener);
+ TransactionUtil.getAdapter(domain, TransactionalEditingDomain.Lifecycle.class)
+ .addTransactionalEditingDomainListener(listener);
}
@Override
- protected void doTearDown()
- throws Exception {
-
- TransactionUtil.getAdapter(domain,
- TransactionalEditingDomain.Lifecycle.class)
- .removeTransactionalEditingDomainListener(listener);
+ protected void doTearDown() throws Exception {
+ TransactionUtil.getAdapter(domain, TransactionalEditingDomain.Lifecycle.class)
+ .removeTransactionalEditingDomainListener(listener);
listener = null;
-
super.doTearDown();
}
- private class LifecycleListener
- implements TransactionalEditingDomainListener {
+ private class LifecycleListener implements TransactionalEditingDomainListener {
List eventTypesReceived = new java.util.ArrayList();
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/MemoryLeakTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/MemoryLeakTest.java
index 643d1be0..deae6ed9 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/MemoryLeakTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/MemoryLeakTest.java
@@ -11,6 +11,11 @@
*/
package org.eclipse.emf.transaction.tests;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
@@ -20,9 +25,6 @@
import java.util.List;
import java.util.Map;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.BasicEList;
@@ -42,7 +44,8 @@
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.TriggerListener;
import org.eclipse.emf.transaction.util.CompositeChangeDescription;
-
+import org.junit.Assert;
+import org.junit.Test;
/**
* Tests to check for memory leaks.
@@ -50,438 +53,440 @@
* @author Christian W. Damus (cdamus)
*/
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 unloading a resource allows its root(s) to be reclaimed.
*/
+ @Test
public void test_unloadResource() {
ReferenceQueue q = new ReferenceQueue();
Reference ref = new WeakReference(root, q);
-
+
// make some change, causing a transaction to record a change description
startWriting();
root.setName("foo"); //$NON-NLS-1$
commit();
-
+
startReading();
testResource.unload();
commit();
-
+
root = null; // forget our only other reference to this object
System.gc();
-
+
idle(2000);
-
+
System.gc();
-
+
assertSame(ref, q.poll());
}
/**
- * Tests that an editing domain can be reclaimed if we forget all references
- * to it and its resource set's contents.
+ * Tests that an editing domain can be reclaimed if we forget all references to
+ * it and its resource set's contents.
*/
+ @Test
public void test_reclaimEditingDomain() {
- ReferenceQueue q =
- new ReferenceQueue();
- Reference ref =
- new WeakReference(domain, q);
-
+ ReferenceQueue q = new ReferenceQueue();
+ Reference ref = new WeakReference(domain, q);
+
// make some change, causing a transaction to record a change description
startWriting();
root.setName("foo"); //$NON-NLS-1$
commit();
-
- domain = null; // forget the domain
- testResource = null; // forget a resource in the domain
- root = null; // forget an object in the domain
-
+
+ domain = null; // forget the domain
+ testResource = null; // forget a resource in the domain
+ root = null; // forget an object in the domain
+
System.gc();
-
+
idle(2000);
-
+
System.gc();
-
+
assertSame(ref, q.poll());
}
-
+
/**
* Tests that a child transaction does not cause any interruption in the
* recording of the parent transaction's change description if the child is
- * unrecorded. The result is that we do not retain empty change
- * descriptions and the parent has a single, seamless change description.
+ * unrecorded. The result is that we do not retain empty change descriptions and
+ * the parent has a single, seamless change description.
*/
+ @Test
public void test_nonRecordingChildTransactions_153908() {
// report initial heap size
long initialUsedHeap = usedHeap();
-
+
startWriting();
-
+
final String oldName = root.getName();
-
+
// make a change in the root-level transaction
root.setName("foo"); //$NON-NLS-1$
-
+
// now, create 1000 nested transactions, each doing a change, *but* unrecorded
- Map
*/
+ @Test
public void test_crossReferenceAdapter_undoredo_recordingCommands() {
// attach a cross-reference adapter to the resource set
ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
@@ -197,6 +194,7 @@ protected void doExecute() {
* history directly.
*
*/
+ @Test
public void test_crossReferenceAdapter_undoredo_normalTriggerCommands() {
// attach a cross-reference adapter to the resource set
ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
@@ -277,6 +275,7 @@ protected Command trigger(TransactionalEditingDomain domain,
* history directly.
*
*/
+ @Test
public void test_crossReferenceAdapter_undoredo_recordingTriggerCommands() {
// attach a cross-reference adapter to the resource set
ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
@@ -341,6 +340,7 @@ protected Command trigger(TransactionalEditingDomain domain,
* flushed.
*
*/
+ @Test
public void test_crossReferenceAdapter_undoredo_operations() {
// attach a cross-reference adapter to the resource set
ECrossReferenceAdapter xrefAdapter = new ECrossReferenceAdapter();
@@ -369,7 +369,7 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
try {
history.execute(oper, null, null);
} catch (ExecutionException e) {
- fail("Failed to execute operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Failed to execute operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
// remove the resource undo context so that flush will dispose
@@ -383,12 +383,12 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
try {
history.undo(ctx, null, null);
} catch (ExecutionException e) {
- fail("Failed to undo operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.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$
+ Assert.fail("Failed to redo operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
assertTrue(level1.eAdapters().contains(xrefAdapter));
@@ -411,6 +411,7 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
* 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();
@@ -457,7 +458,7 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
try {
history.execute(oper, null, null);
} catch (ExecutionException e) {
- fail("Failed to execute operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Failed to execute operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
// remove the resource undo context so that flush will dispose
@@ -471,12 +472,12 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
try {
history.undo(ctx, null, null);
} catch (ExecutionException e) {
- fail("Failed to undo operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.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$
+ Assert.fail("Failed to redo operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
assertTrue(level1.eAdapters().contains(xrefAdapter));
@@ -499,6 +500,7 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
* 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();
@@ -550,7 +552,7 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
try {
history.execute(oper, null, null);
} catch (ExecutionException e) {
- fail("Failed to execute operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Failed to execute operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
// remove the resource undo context so that flush will dispose
@@ -564,12 +566,12 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
try {
history.undo(ctx, null, null);
} catch (ExecutionException e) {
- fail("Failed to undo operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.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$
+ Assert.fail("Failed to redo operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
assertTrue(level1.eAdapters().contains(xrefAdapter));
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..f2f32f17 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.Assert.assertEquals;
+import static org.junit.Assert.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.Test;
/**
@@ -39,18 +40,11 @@
*/
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();
@@ -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();
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..b01c7a71 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.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;import org.junit.Test;
+
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,6 +69,7 @@
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.Assert;
/**
@@ -74,18 +80,11 @@
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();
@@ -105,6 +104,7 @@ public void test_execute() {
/**
* Tests undo/redo support.
*/
+ @Test
public void test_undo_redo() {
Command cmd = new NullCommand();
@@ -136,6 +136,7 @@ public void test_undo_redo() {
/**
* Tests most-recent-command support.
*/
+ @Test
public void test_mostRecentCommand() {
Command cmd = new NullCommand();
@@ -173,6 +174,7 @@ public void test_mostRecentCommand() {
/**
* Tests flush support.
*/
+ @Test
public void test_flush() {
getCommandStack().execute(new NullCommand());
getCommandStack().execute(new NullCommand());
@@ -190,6 +192,7 @@ public void test_flush() {
assertEquals(0, operations.length);
}
+ @Test
public void test_flushingOnResourceUnload() {
Command cmd = new SetCommand(
domain,
@@ -224,6 +227,7 @@ public void test_flushingOnResourceUnload() {
assertEquals(0, operations.length);
}
+ @Test
public void testUndoContextPropagationFromTriggerListeners() {
final TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
final IUndoContext undoContext = new UndoContext();
@@ -285,7 +289,7 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
op.execute(new NullProgressMonitor(), null);
} catch (ExecutionException e) {
e.printStackTrace();
- fail();
+ Assert.fail();
}
assertNotNull(op.getContexts());
@@ -300,7 +304,7 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
OperationHistoryFactory.getOperationHistory().execute(op, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
e.printStackTrace();
- fail();
+ Assert.fail();
}
assertNotNull(op.getContexts());
@@ -312,6 +316,7 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
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$
@@ -358,7 +363,8 @@ protected void doExecute() {
assertTrue(stack.isSaveNeeded());
}
- public void test_isSaveNeeded_214325() {
+ @Test
+ public void test_isSaveNeeded_214325() {
TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
final Resource r = domain.getResourceSet().createResource(URI.createURI("file://foo.xml")); //$NON-NLS-1$
@@ -398,7 +404,8 @@ protected void doExecute() {
* Test that run-time exceptions in a trigger command cause rollback of
* the whole transaction.
*/
- public void test_triggerRollback_146853() {
+ @Test
+ public void test_triggerRollback_146853() {
final RuntimeException error = new RuntimeException();
ResourceSetListener testListener = new TriggerListener() {
@@ -443,6 +450,7 @@ protected void doExecute() {
* 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();
@@ -488,6 +496,7 @@ protected void doExecute() {
* 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();
@@ -517,7 +526,7 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) {
assertEquals(IStatus.ERROR, status.getSeverity());
} catch (ExecutionException e) {
- fail("Execution failed: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Execution failed: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
// verify that rollback occurred
@@ -534,6 +543,7 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) {
* 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();
@@ -563,7 +573,7 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) {
assertEquals(IStatus.CANCEL, status.getSeverity());
} catch (ExecutionException e) {
- fail("Execution failed: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Execution failed: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
// verify that rollback occurred
@@ -580,6 +590,7 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) {
* 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() {
@@ -618,7 +629,7 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) {
// 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$
+ Assert.fail("Failed to execute test operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
startReading();
@@ -630,7 +641,7 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) {
try {
history.undo(ctx, null, null);
} catch (ExecutionException e) {
- fail("Failed to undo test operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Failed to undo test operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
assertFalse(root.getBranches().contains(newLibrary[0]));
@@ -640,7 +651,7 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) {
try {
history.redo(ctx, null, null);
} catch (ExecutionException e) {
- fail("Failed to redo test operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Failed to redo test operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
assertTrue(root.getBranches().contains(newLibrary[0]));
@@ -652,7 +663,8 @@ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) {
* listeners are notified again that the stack is changed, so that they
* will correctly update themselves if necessary.
*/
- public void test_rollbackNotifiesCommandStackListeners_175725() {
+ @Test
+ public void test_rollbackNotifiesCommandStackListeners_175725() {
class TestCSL implements CommandStackListener {
int invocationCount = 0;
public void commandStackChanged(EventObject event) {
@@ -684,6 +696,7 @@ public void commandStackChanged(EventObject event) {
assertFalse("Should not have an undo command", stack.canUndo()); //$NON-NLS-1$
}
+ @Test
public void test_undoRedoNotifyListeners_173839() {
class TestCSL implements CommandStackListener {
int invocationCount = 0;
@@ -730,6 +743,7 @@ public void commandStackChanged(EventObject event) {
* 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) {
@@ -757,7 +771,7 @@ protected IStatus doExecute(IProgressMonitor monitor,
try {
history.execute(operation, null, null);
} catch (ExecutionException e) {
- fail("Failed to execute test operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Failed to execute test operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
IUndoContext expected = new ResourceUndoContext(domain, testResource);
@@ -768,6 +782,7 @@ protected IStatus doExecute(IProgressMonitor monitor,
* 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$
@@ -810,7 +825,7 @@ public IStatus undo(IProgressMonitor monitor, IAdaptable info)
try {
history.execute(operation, null, null);
} catch (ExecutionException e) {
- fail("Unexpected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.fail("Unexpected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
IUndoContext expected = new ResourceUndoContext(domain, testResource);
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..220deab4 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
@@ -13,8 +13,6 @@
import java.util.List;
-import org.junit.Assert;
-
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
@@ -23,6 +21,7 @@
import org.eclipse.emf.transaction.RollbackException;
import org.eclipse.emf.transaction.TransactionalCommandStack;
import org.eclipse.emf.workspace.tests.TestsPlugin;
+import org.junit.Assert;
import org.osgi.framework.Bundle;
/**
@@ -34,131 +33,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();
+ Assert.assertNotNull(log);
+ log = findStatus(log, throwable);
+ Assert.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..b08c98c5 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,40 +11,38 @@
*/
package org.eclipse.emf.workspace.util.tests;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.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.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests the {@link OperationChangeDescription} class.
*
* @author Christian W. Damus (cdamus)
*/
-public class OperationChangeDescriptionTest extends TestCase {
+public class OperationChangeDescriptionTest {
- private String externalData[];
+ 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.
*/
+ @Test
public void test_emfChanges() {
assertTrue(change.getObjectChanges().isEmpty());
assertTrue(change.getResourceChanges().isEmpty());
@@ -55,6 +53,7 @@ public void test_emfChanges() {
/**
* Tests the canApply() method.
*/
+ @Test
public void test_canApply() {
assertTrue(change.canApply());
}
@@ -62,6 +61,7 @@ public void test_canApply() {
/**
* Tests the apply() method.
*/
+ @Test
public void test_apply() {
change.apply();
@@ -74,6 +74,7 @@ public void test_apply() {
/**
* Tests the applyAndReverse() method.
*/
+ @Test
public void test_applyAndReverse() {
change.applyAndReverse();
@@ -98,12 +99,12 @@ public void test_applyAndReverse() {
// Fixture methods
//
- @Override
- protected void setUp()
+ @Before
+ public void setUp()
throws Exception {
- initialValue = "Initial value"; //$NON-NLS-1$
- newValue = "New value"; //$NON-NLS-1$
+ initialValue = "Initial value";
+ newValue = "New value";
externalData = new String[] {initialValue};
operation = new ExternalDataOperation(externalData, newValue);
operation.execute(new NullProgressMonitor(), null);
@@ -112,8 +113,8 @@ protected void setUp()
assertEquals(newValue, externalData[0]);
}
- @Override
- protected void tearDown()
+ @After
+ public void tearDown()
throws Exception {
externalData = null;
@@ -130,6 +131,6 @@ protected void tearDown()
*/
protected void fail(Exception e) {
e.printStackTrace();
- fail("Should not have thrown: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assert.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..d6b04448 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.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.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.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.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$
+ Assert.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());
-
+
+ @Before
+ public void setUp() throws Exception {
+
+ 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 {
-
+
+ @After
+ public void tearDown() throws Exception {
+
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$
+ Assert.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..62b8a5b2 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
@@ -10,12 +10,13 @@
* IBM - Initial API and implementation
*/
package org.eclipse.emf.workspace.util.tests;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.util.Collections;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.common.command.Command;
@@ -27,6 +28,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.Assert;
+import org.junit.Test;
/**
@@ -48,19 +51,12 @@ public void execute() {
fail(e);
}
}};
-
- public ValidateEditTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(ValidateEditTest.class, "Validate-Edit Support Tests"); //$NON-NLS-1$
- }
/**
* 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);
@@ -81,7 +77,7 @@ public void ignore_test_validateEditRollback() {
try {
getCommandStack().execute(cmd, null);
- fail("Should have rolled back"); //$NON-NLS-1$
+ Assert.fail("Should have rolled back"); //$NON-NLS-1$
} catch (RollbackException e) {
// success
System.out.println("Got expected exception: " + e.getLocalizedMessage()); //$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..ea0fee4d 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.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.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.Assert;
+import org.junit.Test;
/**
* Tests the {@link WorkspaceSynchronizer} class.
@@ -51,18 +55,10 @@ 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);
@@ -76,6 +72,7 @@ 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"));
@@ -105,6 +102,7 @@ public void test_getUnderlyingFile_163291() {
/**
* Tests the getFile() with file: URI.
*/
+ @Test
public void test_getFile_fileURI_156772() {
String path = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(RESOURCE_NAME).toString();
@@ -121,6 +119,7 @@ public void test_getFile_fileURI_156772() {
/**
* 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$
@@ -139,6 +138,7 @@ public void test_getFile_normalization_156772() {
* Tests that resource deletion is correctly reported to the delegate to
* handle.
*/
+ @Test
public void test_deletion() {
IFile file = WorkspaceSynchronizer.getFile(testResource);
@@ -160,6 +160,7 @@ public void test_deletion() {
* Tests that resource change is correctly reported to the delegate to
* handle.
*/
+ @Test
public void test_change() {
IFile file = WorkspaceSynchronizer.getFile(testResource);
@@ -181,6 +182,7 @@ public void test_change() {
* 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(
@@ -207,6 +209,7 @@ public void test_move() {
* 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];
@@ -288,6 +291,7 @@ public IStatus runInWorkspace(IProgressMonitor monitor)
/**
* Tests the default response to resource deletion.
*/
+ @Test
public void test_defaultDeleteBehaviour() {
IFile file = WorkspaceSynchronizer.getFile(testResource);
@@ -313,6 +317,7 @@ public void test_defaultDeleteBehaviour() {
* 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);
@@ -340,6 +345,7 @@ public void test_defaultChangeBehaviour() {
/**
* 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(
@@ -366,6 +372,7 @@ public void test_defaultMoveBehaviour() {
/**
* 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$
@@ -387,6 +394,7 @@ public void test_getFileWithEncodedURI_128315() {
* 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,
@@ -421,6 +429,7 @@ public void test_synchResourceWithUnencodedURI_197291() {
* 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,
@@ -455,6 +464,7 @@ public void test_synchResourceWithEncodedURI_197291() {
* 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,
@@ -494,6 +504,7 @@ public void test_synchMovedResourceWithUnencodedURI_197291() {
* 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,
@@ -532,6 +543,7 @@ public void test_synchMoveResourceWithEncodedURI_197291() {
* Tests the response to resource deletion when the deleted resource also
* had markers.
*/
+ @Test
public void test_resourceDeletedThatHadMarkers_207306() {
IFile file = WorkspaceSynchronizer.getFile(testResource);
@@ -560,6 +572,7 @@ public void test_resourceDeletedThatHadMarkers_207306() {
assertFalse(testResource.isLoaded());
}
+ @Test
public void test_deleteProjectAndDisposeSynchronizer_233004() {
final IStatus[] logged = new IStatus[1];
@@ -595,12 +608,12 @@ public void run(IProgressMonitor monitor)
Thread.sleep(1000);
if (logged[0] != null) {
- fail("Should not have logged: " + logged[0].getException());
+ Assert.fail("Should not have logged: " + logged[0].getException());
}
} catch (CoreException e) {
- fail("Failed to delete project: " + e.getLocalizedMessage());
+ Assert.fail("Failed to delete project: " + e.getLocalizedMessage());
} catch (InterruptedException e) {
- fail("Test interrupted in sleep");
+ Assert.fail("Test interrupted in sleep");
} finally {
EMFWorkspacePlugin.getPlugin().getLog().removeLogListener(log);
ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener);
From ce7f2d802b4958383f3c6a428c23f58c8925cbba Mon Sep 17 00:00:00 2001
From: Pierre-Charles David
Date: Tue, 7 Apr 2026 21:21:42 +0200
Subject: [PATCH 2/2] [41] Upgrade tests to JUnit 5
Bug: https://github.com/eclipse-emfservices/emf-transaction/issues/41
Signed-off-by: Pierre-Charles David
---
.../META-INF/MANIFEST.MF | 7 +-
.../tests/AbstractMultithreadTest.java | 10 +-
.../multithread/tests/Constants.java | 20 +-
.../tests/EMFTransansactionTest.java | 31 +-
.../tests/LongRunningReadThread.java | 7 +-
.../tests/NestedOperationThread.java | 12 +-
.../tests/NestedReadInWriteThread.java | 9 +-
.../multithread/tests/NestedReadThread.java | 9 +-
.../multithread/tests/NestedWriteThread.java | 28 +-
.../multithread/tests/ReadOperationTest.java | 23 +-
.../multithread/tests/ReadThread.java | 9 +-
.../tests/ReadWriteOperationTest.java | 41 +-
.../tests/SimpleOperationThread.java | 14 +-
.../multithread/tests/WriteOperationTest.java | 25 +-
.../multithread/tests/WriteThread.java | 5 +-
.../emf/transaction/tests/AbstractTest.java | 430 +++---
.../tests/BasicTransactionTest.java | 361 +++--
.../tests/ChangeDescriptionTest.java | 14 +-
.../tests/EditingDomainRegistryTest.java | 367 +++--
.../transaction/tests/EditingDomainTest.java | 64 +-
.../tests/EditingDomainValidatorTest.java | 24 +-
.../JobManagerSuspensionDeadlockTest.java | 24 +-
.../tests/LifecycleListenersTest.java | 28 +-
.../emf/transaction/tests/MemoryLeakTest.java | 60 +-
.../tests/NotificationFilterTest.java | 10 +-
.../transaction/tests/PerformanceTest.java | 33 +-
.../tests/PrivilegedRunnableTest.java | 39 +-
.../tests/RecordingCommandTest.java | 8 +-
.../tests/ResourceSetListenersTest.java | 1029 +++++++-------
.../emf/transaction/tests/TestsPlugin.java | 8 +-
.../tests/TransactionChangeRecorderTest.java | 48 +-
.../tests/TransactionOptionsTest.java | 123 +-
.../emf/transaction/tests/UndoRedoTest.java | 46 +-
.../transaction/tests/ValidateEditTest.java | 28 +-
.../tests/ValidationRollbackTest.java | 62 +-
.../constraints/BookTitleConstraint.java | 6 +-
.../tests/constraints/ClientSelector.java | 1 +
.../ItemDefaultPublicationDateTrigger.java | 6 +-
.../tests/fixtures/JobListener.java | 32 +-
.../fixtures/LibraryDefaultBookTrigger.java | 8 +-
.../fixtures/LibraryDefaultNameTrigger.java | 8 +-
.../tests/fixtures/LogCapture.java | 90 +-
.../tests/fixtures/TestCommand.java | 12 +-
.../tests/fixtures/TestEditingDomain.java | 8 +-
.../tests/fixtures/TestListener.java | 22 +-
.../fixtures/TestValidationEditingDomain.java | 17 +-
.../tests/CompositeChangeDescriptionTest.java | 12 +-
.../emf/transaction/util/tests/LockTest.java | 648 ++++-----
.../util/tests/TransactionUtilTests.java | 7 +-
.../META-INF/MANIFEST.MF | 7 +-
.../tests/AbstractEMFOperationTest.java | 903 +++++++------
.../emf/workspace/tests/AbstractTest.java | 50 +-
.../workspace/tests/BasicWorkbenchTest.java | 267 ++--
.../tests/CompositeEMFOperationTest.java | 1190 ++++++++---------
.../tests/EMFCommandOperationTest.java | 487 ++++---
.../tests/EMFOperationCommandTest.java | 618 +++++----
.../emf/workspace/tests/MemoryLeakTest.java | 1117 ++++++++--------
.../emf/workspace/tests/UndoContextTest.java | 16 +-
.../tests/WorkbenchCommandStackTest.java | 1090 ++++++++-------
.../workspace/tests/fixtures/LogCapture.java | 7 +-
.../tests/OperationChangeDescriptionTest.java | 75 +-
.../util/tests/ResourceUndoContextTest.java | 26 +-
.../util/tests/ValidateEditTest.java | 185 ++-
.../util/tests/WorkspaceSynchronizerTest.java | 670 +++++-----
64 files changed, 5308 insertions(+), 5333 deletions(-)
diff --git a/tests/org.eclipse.emf.transaction.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.emf.transaction.tests/META-INF/MANIFEST.MF
index 5656e6de..b82967f9 100644
--- a/tests/org.eclipse.emf.transaction.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.emf.transaction.tests/META-INF/MANIFEST.MF
@@ -8,7 +8,12 @@ Bundle-Localization: plugin
Require-Bundle: org.eclipse.emf.transaction;bundle-version="1.9.0",
org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.emf.examples.library.edit;bundle-version="[2.3.0,3.0.0)",
- org.junit;bundle-version="[4.0.0,5.0.0)",
+ junit-jupiter-api;bundle-version="5.11.3",
+ junit-jupiter-engine;bundle-version="5.11.3",
+ junit-vintage-engine;bundle-version="5.11.3",
+ junit-platform-commons;bundle-version="1.11.3",
+ junit-platform-engine;bundle-version="1.11.3",
+ junit-platform-runner;bundle-version="1.11.3",
org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.filesystem;bundle-version="[1.2.0,2.0.0)",
org.eclipse.emf.workspace;bundle-version="1.5.2"
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/AbstractMultithreadTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/AbstractMultithreadTest.java
index 5ba8c06d..e8bc015f 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/AbstractMultithreadTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/AbstractMultithreadTest.java
@@ -13,12 +13,12 @@
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.tests.AbstractTest;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
/**
* Abstract JUnit test suite for the EMF-TX API multi-threading tests.
- *
+ *
* @author Christian W. Damus (cdamus)
*/
public class AbstractMultithreadTest {
@@ -33,13 +33,13 @@ protected TransactionalEditingDomain getDomain() {
return domain;
}
- @Before
+ @BeforeEach
public void setUp() throws Exception {
AbstractTest.trace("===> Begin : " + this.getClass().getName());
domain = TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain();
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
domain = null;
AbstractTest.trace("===> End : " + this.getClass().getName());
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/Constants.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/Constants.java
index ba88c269..7b847a27 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/Constants.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/Constants.java
@@ -14,16 +14,16 @@
/**
* Constants and comparison utilities for the multi-threading tests.
- *
+ *
* @author mgoyal
*/
public class Constants {
public static final int SLEEP_TIME = 100;
-
+
/**
* Returns true if the testedTask started after mainTask.
* and finished before mainTask.
- *
+ *
* @param mainTask Main Task
* @param testedTask Tested Task
* @return true if the condition is met.
@@ -31,11 +31,11 @@ public class Constants {
public static final boolean occurredDuring(SimpleOperationThread mainTask, SimpleOperationThread testedTask) {
return occurredDuring(mainTask.getStartTime(), mainTask.getEndTime(), testedTask.getStartTime(), testedTask.getEndTime());
}
-
+
/**
* Returns true if the testedStartTime is after mainStartTime.
* and testedEndTime is before mainEndTime.
- *
+ *
* @param mainStartTime
* @param mainEndTime
* @param testedStartTime
@@ -46,10 +46,10 @@ public static final boolean occurredDuring(long mainStartTime, long mainEndTime,
return (testedStartTime - mainStartTime > 0 && testedStartTime - mainEndTime < 0) &&
(testedEndTime - mainStartTime > 0 && testedEndTime - mainEndTime < 0);
}
-
+
/**
* Returns true if the testedTask started and finished before the mainTask
- *
+ *
* @param mainTask
* @param testedTask
* @return true if the condition is met.
@@ -60,7 +60,7 @@ public static final boolean occurredBefore(SimpleOperationThread mainTask, Simpl
/**
* Returns true if the testedTask started and finished after the mainTask.
- *
+ *
* @param mainTask
* @param testedTask
* @return true if the condition is met.
@@ -68,11 +68,11 @@ public static final boolean occurredBefore(SimpleOperationThread mainTask, Simpl
public static final boolean occurredAfter(SimpleOperationThread mainTask, SimpleOperationThread testedTask) {
return testedTask.getStartTime() - mainTask.getEndTime() >= 0 && testedTask.getEndTime() - mainTask.getEndTime() > 0;
}
-
+
/**
* Returns true if the testedTask started before the mainTask and finished during the mainTask
* Also returns true if the testedTask started during the mainTask and finished after the mainTask
- *
+ *
* @param mainTask
* @param testedTask
* @return true if the condition is met.
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/EMFTransansactionTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/EMFTransansactionTest.java
index 5d7736de..8703ac14 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/EMFTransansactionTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/EMFTransansactionTest.java
@@ -11,6 +11,8 @@
*/
package org.eclipse.emf.transaction.multithread.tests;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.io.File;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.ArrayList;
@@ -37,17 +39,15 @@
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.internal.EMFTransactionPlugin;
import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* This class contains a test case for EMF transaction.
- *
+ *
* @author mchauvin
*/
-public class EMFTransansactionTest extends TestCase {
+public class EMFTransansactionTest {
private TransactionalEditingDomain editingDomain;
@@ -57,14 +57,10 @@ public class EMFTransansactionTest extends TestCase {
private AtomicBoolean errorDetected = new AtomicBoolean();
- public static Test suite() {
- return new TestSuite(EMFTransansactionTest.class, "Concurrent Transaction Tests"); //$NON-NLS-1$
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @BeforeEach
+ public void setUp() throws Exception {
exceptionHandler = new UncaughtExceptionHandler() {
+ @Override
public void uncaughtException(Thread t, Throwable e) {
errorDetected.set(true);
}
@@ -74,9 +70,10 @@ public void uncaughtException(Thread t, Throwable e) {
/**
* Due to threads synchronization complexity, this test may succeed. It should
* be run several times (at least 4) to be sure than the bug is not present.
- *
+ *
* @throws Exception
*/
+ @Test
public void testSynchronizationBug() throws Exception {
/* create a resource set */
final ResourceSet rset = new ResourceSetImpl();
@@ -88,7 +85,7 @@ public void testSynchronizationBug() throws Exception {
final EClass eClass = EcoreFactory.eINSTANCE.createEClass();
ePackage.getEClassifiers().add(eClass);
final EReference eReference = EcoreFactory.eINSTANCE.createEReference();
- eClass.getEReferences().add(eReference);
+ eClass.getEStructuralFeatures().add(eReference);
/* create resource and and add it initialized model */
final URI fileUri = URI.createFileURI(new File("test.ecore").getAbsolutePath());
@@ -105,7 +102,7 @@ protected void doExecute() {
final EClass eClass2 = EcoreFactory.eINSTANCE.createEClass();
ePackage2.getEClassifiers().add(eClass2);
final EReference eReference2 = EcoreFactory.eINSTANCE.createEReference();
- eClass2.getEReferences().add(eReference2);
+ eClass2.getEStructuralFeatures().add(eReference2);
/* create resource and and add it initialized model */
final URI file2Uri = URI.createFileURI(new File("test2.ecore").getAbsolutePath());
@@ -135,7 +132,7 @@ protected void doExecute() {
EMFTransactionPlugin.getPlugin().getLog().addLogListener(listener);
- final Collection threads = new ArrayList();
+ final Collection threads = new ArrayList<>();
/* Launch a unload and a resolution */
for (int i = 0; i < 100; i++) {
threads.add(launchNotificationInANewThread(eReference, eReference2));
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/LongRunningReadThread.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/LongRunningReadThread.java
index 98fa6c0c..18582698 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/LongRunningReadThread.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/LongRunningReadThread.java
@@ -20,7 +20,7 @@
*/
class LongRunningReadThread extends ReadThread {
long timeYielded = 0L;
-
+
/**
* Constructor
* @param waitObject
@@ -37,6 +37,7 @@ public LongRunningReadThread(TransactionalEditingDomain domain, Object waitObjec
public void run() {
try {
getDomain().runExclusive(new Runnable() {
+ @Override
public void run() {
if(notifyObject != null) {
synchronized(notifyObject) {
@@ -53,12 +54,12 @@ public void run() {
}
}
}
-
+
startTime = System.currentTimeMillis();
for(int i = 0; i < 10; i++) {
try {
sleep(Constants.SLEEP_TIME);
-
+
long startYield = System.currentTimeMillis();
getDomain().yield();
timeYielded += System.currentTimeMillis() - startYield;
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedOperationThread.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedOperationThread.java
index dc25b824..cba5251b 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedOperationThread.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedOperationThread.java
@@ -15,7 +15,7 @@
/**
* Thread representing nested Operations.
- *
+ *
* @author mgoyal
*/
class NestedOperationThread
@@ -35,7 +35,7 @@ class NestedOperationThread
/**
* Constructor
- *
+ *
* @param waitObject
* @param notifyObject
*/
@@ -45,7 +45,7 @@ public NestedOperationThread(TransactionalEditingDomain domain, Object waitObjec
/**
* Returns the start time for the inner operation
- *
+ *
* @return innerStartTime
*/
public long getInnerStartTime() {
@@ -54,7 +54,7 @@ public long getInnerStartTime() {
/**
* Returns the end time for the inner operation
- *
+ *
* @return innerEndTime
*/
public long getInnerEndTime() {
@@ -63,7 +63,7 @@ public long getInnerEndTime() {
/**
* Returns true if the inner operation was successful
- *
+ *
* @return isInnerExecuted
*/
public boolean isInnerExecuted() {
@@ -72,7 +72,7 @@ public boolean isInnerExecuted() {
/**
* Returns true if the inner operation failed.
- *
+ *
* @return isInnerFailed
*/
public boolean isInnerFailed() {
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedReadInWriteThread.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedReadInWriteThread.java
index d48d3f28..70156356 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedReadInWriteThread.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedReadInWriteThread.java
@@ -16,7 +16,7 @@
/**
* Thread representing Read Operation nested in Write Operation.
- *
+ *
* @author mgoyal
*/
class NestedReadInWriteThread
@@ -24,7 +24,7 @@ class NestedReadInWriteThread
/**
* Constructor
- *
+ *
* @param waitObject
* @param notifyObject
*/
@@ -63,11 +63,13 @@ public void run() {
try {
getCommandStack().execute(new TestCommand() {
+ @Override
public void execute() {
startTime = System.currentTimeMillis();
final boolean bWriting = true;
try {
getDomain().runExclusive(new Runnable() {
+ @Override
public void run() {
innerStartTime = System
.currentTimeMillis();
@@ -76,8 +78,9 @@ public void run() {
} catch (InterruptedException e) {
// ignore this.
}
- if (bWriting && !isExecuted)
+ if (bWriting && !isExecuted) {
isInnerExecuted = true;
+ }
innerEndTime = System
.currentTimeMillis();
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedReadThread.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedReadThread.java
index a0b95a50..9532abf5 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedReadThread.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedReadThread.java
@@ -15,7 +15,7 @@
/**
* Thread representing read operation nested in a read operation.
- *
+ *
* @author mgoyal
*/
class NestedReadThread
@@ -23,7 +23,7 @@ class NestedReadThread
/**
* Constructor
- *
+ *
* @param waitObject
* @param notifyObject
*/
@@ -60,6 +60,7 @@ public void run() {
}
getDomain().runExclusive(new Runnable() {
+ @Override
public void run() {
startTime = System.currentTimeMillis();
final boolean bReading = true;
@@ -70,6 +71,7 @@ public void run() {
}
try {
getDomain().runExclusive(new Runnable() {
+ @Override
public void run() {
innerStartTime = System.currentTimeMillis();
try {
@@ -77,8 +79,9 @@ public void run() {
} catch (InterruptedException e) {
// ignore this.
}
- if (bReading && !isExecuted)
+ if (bReading && !isExecuted) {
isInnerExecuted = true;
+ }
innerEndTime = System.currentTimeMillis();
}
});
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedWriteThread.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedWriteThread.java
index 19163f36..2e8395d7 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedWriteThread.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/NestedWriteThread.java
@@ -11,14 +11,14 @@
*/
package org.eclipse.emf.transaction.multithread.tests;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.Transaction;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
import org.eclipse.emf.transaction.tests.fixtures.TestCommand;
/**
* Thread representing write operation nested in a write operation.
- *
+ *
* @author mgoyal
*/
class NestedWriteThread
@@ -26,7 +26,7 @@ class NestedWriteThread
/**
* Constructor
- *
+ *
* @param waitObject
* @param notifyObject
*/
@@ -35,13 +35,13 @@ public NestedWriteThread(TransactionalEditingDomain domain, Object waitObject, O
}
/**
- * Default Constructor
+ * Default Constructor
*/
public NestedWriteThread(TransactionalEditingDomain domain) {
this(domain, null, null);
}
- /**
+ /**
* @see java.lang.Runnable#run()
*/
@Override
@@ -66,7 +66,7 @@ public void run() {
try {
tx = ((InternalTransactionalEditingDomain) getDomain()).startTransaction(
false, null);
-
+
startTime = System.currentTimeMillis();
try {
sleep(Constants.SLEEP_TIME);
@@ -74,29 +74,31 @@ public void run() {
// ignore this.
}
final boolean bWriting = true;
-
+
try {
getCommandStack().execute(new TestCommand() {
-
+
+ @Override
public void execute() {
innerStartTime = System.currentTimeMillis();
-
+
try {
sleep(Constants.SLEEP_TIME);
} catch (InterruptedException e) {
// ignore this.
}
-
- if (bWriting && !isExecuted)
+
+ if (bWriting && !isExecuted) {
isInnerExecuted = true;
+ }
innerEndTime = System.currentTimeMillis();
}
-
+
});
} catch (Exception e1) {
isInnerFailed = true;
}
-
+
try {
sleep(Constants.SLEEP_TIME);
} catch (InterruptedException e) {
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadOperationTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadOperationTest.java
index 5a4ad525..4d68ff64 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadOperationTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadOperationTest.java
@@ -11,14 +11,14 @@
*/
package org.eclipse.emf.transaction.multithread.tests;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Testcase for testing scheduling of Read operation scenarios
- *
+ *
* @author mgoyal
*/
public class ReadOperationTest extends AbstractMultithreadTest {
@@ -39,8 +39,9 @@ public void testReadOperation() {
} catch (InterruptedException e) {
// ignore this exception
}
- if (!readThread1.isAlive())
+ if (!readThread1.isAlive()) {
done = true;
+ }
}
assertFalse(readThread1.isFailed());
@@ -80,8 +81,9 @@ public void testSimultaneousRead() {
} catch (InterruptedException e) {
// ignore this exception
}
- if (!readThread1.isAlive() && !readThread2.isAlive())
+ if (!readThread1.isAlive() && !readThread2.isAlive()) {
done = true;
+ }
}
assertFalse(readThread1.isFailed());
@@ -106,8 +108,9 @@ public void testNestedReads() {
} catch (InterruptedException e) {
// ignore this exception
}
- if (!readThread1.isAlive())
+ if (!readThread1.isAlive()) {
done = true;
+ }
}
assertFalse(readThread1.isInnerFailed());
@@ -169,8 +172,9 @@ public void testLongRunningYieldingRead() {
} catch (InterruptedException e) {
// ignore this exception
}
- if (!longReadThread.isAlive() && !readThd1.isAlive() && !readThd2.isAlive() && !readThd3.isAlive())
+ if (!longReadThread.isAlive() && !readThd1.isAlive() && !readThd2.isAlive() && !readThd3.isAlive()) {
done = true;
+ }
}
assertFalse(longReadThread.isFailed());
@@ -243,8 +247,9 @@ public void testMultipleLongRunningYieldingReads() {
// ignore this exception
}
if (!longReadThread1.isAlive() && !longReadThread2.isAlive() && !longReadThread3.isAlive()
- && !longReadThread4.isAlive())
+ && !longReadThread4.isAlive()) {
done = true;
+ }
}
assertFalse(longReadThread1.isFailed());
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadThread.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadThread.java
index c9d5bcbb..51a8cecd 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadThread.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadThread.java
@@ -16,7 +16,7 @@
/**
* Thread for a simple read operation
- *
+ *
* @author mgoyal
*/
class ReadThread extends SimpleOperationThread {
@@ -28,14 +28,14 @@ class ReadThread extends SimpleOperationThread {
public ReadThread(TransactionalEditingDomain domain, Object waitObject, Object notifyObject) {
super(domain, waitObject, notifyObject);
}
-
+
/**
- * Default constructor
+ * Default constructor
*/
public ReadThread(TransactionalEditingDomain domain) {
this(domain, null, null);
}
-
+
/**
* @see java.lang.Runnable#run()
*/
@@ -58,6 +58,7 @@ public void run() {
}
getDomain().runExclusive(new Runnable() {
+ @Override
public void run() {
startTime = System.currentTimeMillis();
try {
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadWriteOperationTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadWriteOperationTest.java
index eed5d0be..106632c4 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadWriteOperationTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/ReadWriteOperationTest.java
@@ -12,14 +12,14 @@
*/
package org.eclipse.emf.transaction.multithread.tests;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Testcase for testing read and write operation scheduling scenarios
- *
+ *
* @author mgoyal
*/
public class ReadWriteOperationTest extends AbstractMultithreadTest {
@@ -27,7 +27,8 @@ public class ReadWriteOperationTest extends AbstractMultithreadTest {
/**
* Tests scheduling of complex Read write scenarios.
*/
- @Test public void testComplexSimultaneousReadsWrites() {
+ @Test
+ public void testComplexSimultaneousReadsWrites() {
Object notifier = new Object();
NestedReadInWriteThread readInWriteThread1 = new NestedReadInWriteThread(getDomain(), null, notifier);
NestedReadInWriteThread readInWriteThread2 = new NestedReadInWriteThread(getDomain(), null, notifier);
@@ -56,8 +57,9 @@ public class ReadWriteOperationTest extends AbstractMultithreadTest {
} catch (InterruptedException e) {
// ignore this exception
}
- if (!readInWriteThread1.isAlive() && !readInWriteThread2.isAlive())
+ if (!readInWriteThread1.isAlive() && !readInWriteThread2.isAlive()) {
done = true;
+ }
}
assertFalse(readInWriteThread1.isFailed());
@@ -73,7 +75,8 @@ public class ReadWriteOperationTest extends AbstractMultithreadTest {
/**
* Tests scheduling of simultaneous read and write operation
*/
- @Test public void testSimultaneousReadsWrites() {
+ @Test
+ public void testSimultaneousReadsWrites() {
Object notifier = new Object();
WriteThread writeThread1 = new WriteThread(getDomain(), null, notifier);
WriteThread writeThread2 = new WriteThread(getDomain(), null, notifier);
@@ -123,8 +126,9 @@ public class ReadWriteOperationTest extends AbstractMultithreadTest {
} catch (InterruptedException e) {
// ignore this exception
}
- if (!writeThread1.isAlive() && !writeThread2.isAlive() && !readThread1.isAlive() && !readThread2.isAlive())
+ if (!writeThread1.isAlive() && !writeThread2.isAlive() && !readThread1.isAlive() && !readThread2.isAlive()) {
done = true;
+ }
}
assertFalse(readThread1.isFailed());
@@ -152,7 +156,8 @@ public class ReadWriteOperationTest extends AbstractMultithreadTest {
/**
* Tests Scheduling of Nested Read in Write Operation
*/
- @Test public void testNestedReadInWrite() {
+ @Test
+ public void testNestedReadInWrite() {
NestedReadInWriteThread readInWriteThd = new NestedReadInWriteThread(getDomain());
readInWriteThd.start();
@@ -163,8 +168,9 @@ public class ReadWriteOperationTest extends AbstractMultithreadTest {
} catch (InterruptedException e) {
// ignore this exception
}
- if (!readInWriteThd.isAlive())
+ if (!readInWriteThd.isAlive()) {
done = true;
+ }
}
assertFalse(readInWriteThd.isInnerFailed());
@@ -180,7 +186,8 @@ public class ReadWriteOperationTest extends AbstractMultithreadTest {
/**
* Tests scheduling of long running read with write operation.
*/
- @Test public void testLongRunningReadWithWrites() {
+ @Test
+ public void testLongRunningReadWithWrites() {
Object notifier = new Object();
LongRunningReadThread longReadThread = new LongRunningReadThread(getDomain(), null, notifier);
ReadThread readThd1 = new ReadThread(getDomain(), null, notifier);
@@ -241,8 +248,9 @@ public class ReadWriteOperationTest extends AbstractMultithreadTest {
// ignore this exception
}
if (!longReadThread.isAlive() && !readThd1.isAlive() && !readThd2.isAlive() && !readThd3.isAlive()
- && !writeThd1.isAlive())
+ && !writeThd1.isAlive()) {
done = true;
+ }
}
assertFalse(longReadThread.isFailed());
@@ -282,10 +290,9 @@ public class ReadWriteOperationTest extends AbstractMultithreadTest {
assertTrue(!Constants.occurIntersect(longReadThread, readThd1));
assertTrue(!Constants.occurIntersect(longReadThread, readThd2));
assertTrue(Constants.occurredAfter(readThd1, readThd2) || Constants.occurredBefore(readThd1, readThd2));
- assertTrue("Read yielded to a write", //$NON-NLS-1$
- (Constants.occurredBefore(longReadThread, writeThd1)
- || Constants.occurredAfter(longReadThread, writeThd1))
- && !Constants.occurredDuring(longReadThread, writeThd1));
+ assertTrue((Constants.occurredBefore(longReadThread, writeThd1)
+ || Constants.occurredAfter(longReadThread, writeThd1))
+ && !Constants.occurredDuring(longReadThread, writeThd1), "Read yielded to a write");
assertTrue(!Constants.occurIntersect(longReadThread, readThd3));
}
@@ -312,6 +319,7 @@ public void test_interruptionOfUIThread_149982() {
class Interrupter implements Runnable {
private volatile boolean dead;
+ @Override
public void run() {
while (!dead) {
uiThread.interrupt();
@@ -328,7 +336,6 @@ void die() {
dead = true;
}
}
- ;
Interrupter interrupter = new Interrupter();
Thread interrupterThread = new Thread(interrupter);
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/SimpleOperationThread.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/SimpleOperationThread.java
index 8d5e6f1f..827e7838 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/SimpleOperationThread.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/SimpleOperationThread.java
@@ -17,7 +17,7 @@
/**
* Thread representing a simple model operation.
- *
+ *
* @author mgoyal
*/
class SimpleOperationThread
@@ -48,7 +48,7 @@ class SimpleOperationThread
/**
* Constructor
- *
+ *
* @param waitObject
* Object to wait on
* @param notifyObject
@@ -62,7 +62,7 @@ public SimpleOperationThread(TransactionalEditingDomain domain, Object waitObjec
/**
* Returns the start time of this operation
- *
+ *
* @return startTime
*/
public long getStartTime() {
@@ -71,7 +71,7 @@ public long getStartTime() {
/**
* Returns the end time of this operation.
- *
+ *
* @return endTime
*/
public long getEndTime() {
@@ -80,7 +80,7 @@ public long getEndTime() {
/**
* Returns true if the execution succeeded
- *
+ *
* @return isExecuted
*/
public boolean isExecuted() {
@@ -89,7 +89,7 @@ public boolean isExecuted() {
/**
* Returns true if the execution failed.
- *
+ *
* @return isFailed
*/
public synchronized boolean isFailed() {
@@ -98,7 +98,7 @@ public synchronized boolean isFailed() {
/**
* Queries whether the thread failed due to an exception in the given class.
- *
+ *
* @param className
* a class name
* @return {@code true} if execution failed in some method of the named class;
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/WriteOperationTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/WriteOperationTest.java
index 199f50eb..5ea8a883 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/WriteOperationTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/WriteOperationTest.java
@@ -11,23 +11,24 @@
*/
package org.eclipse.emf.transaction.multithread.tests;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Testcase for testing scheduling of Write Operation scenarios
- *
+ *
* @author mgoyal
- *
+ *
*/
public class WriteOperationTest extends AbstractMultithreadTest {
/**
* Tests scheduling of simple write operation.
*/
- @Test public void testWriteOperation() {
+ @Test
+ public void testWriteOperation() {
WriteThread writeThread1 = new WriteThread(getDomain());
writeThread1.start();
@@ -38,8 +39,9 @@ public class WriteOperationTest extends AbstractMultithreadTest {
} catch (InterruptedException e) {
// ignore this exception
}
- if (!writeThread1.isAlive())
+ if (!writeThread1.isAlive()) {
done = true;
+ }
}
assertFalse(writeThread1.isFailed());
@@ -49,7 +51,8 @@ public class WriteOperationTest extends AbstractMultithreadTest {
/**
* Tests scheduling of two simultaneous write operations.
*/
- @Test public void testSimultaneousWrites() {
+ @Test
+ public void testSimultaneousWrites() {
Object notifier = new Object();
WriteThread writeThread1 = new WriteThread(getDomain(), null, notifier);
WriteThread writeThread2 = new WriteThread(getDomain(), null, notifier);
@@ -78,8 +81,9 @@ public class WriteOperationTest extends AbstractMultithreadTest {
} catch (InterruptedException e) {
// ignore this exception
}
- if (!writeThread1.isAlive() && !writeThread2.isAlive())
+ if (!writeThread1.isAlive() && !writeThread2.isAlive()) {
done = true;
+ }
}
assertFalse(writeThread1.isFailed());
@@ -104,8 +108,9 @@ public void testNestedWrites() {
} catch (InterruptedException e) {
// ignore this exception
}
- if (!writeThread1.isAlive())
+ if (!writeThread1.isAlive()) {
done = true;
+ }
}
assertFalse(writeThread1.isInnerFailed());
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/WriteThread.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/WriteThread.java
index ae40d095..8b98a24b 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/WriteThread.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/multithread/tests/WriteThread.java
@@ -29,9 +29,9 @@ class WriteThread extends SimpleOperationThread {
public WriteThread(TransactionalEditingDomain domain, Object waitObject, Object notifyObject) {
super(domain, waitObject, notifyObject);
}
-
+
/**
- * Constructor
+ * Constructor
*/
public WriteThread(TransactionalEditingDomain domain) {
this(domain, null, null);
@@ -60,6 +60,7 @@ public void run() {
try {
getCommandStack().execute(new TestCommand() {
+ @Override
public void execute() {
startTime = System.currentTimeMillis();
try {
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/AbstractTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/AbstractTest.java
index 181b31c5..5c7ec690 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/AbstractTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/AbstractTest.java
@@ -11,9 +11,8 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.io.IOException;
import java.io.InputStream;
@@ -40,7 +39,6 @@
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.examples.extlibrary.AudioVisualItem;
import org.eclipse.emf.examples.extlibrary.Book;
import org.eclipse.emf.examples.extlibrary.Library;
import org.eclipse.emf.examples.extlibrary.Periodical;
@@ -53,76 +51,72 @@
import org.eclipse.emf.transaction.impl.InternalTransaction;
import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
import org.eclipse.emf.validation.model.IConstraintStatus;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
import org.osgi.framework.Bundle;
/**
* Abstract test framework for the transaction unit tests.
- *
+ *
* @author Christian W. Damus (cdamus)
*/
public class AbstractTest {
-
+
public static final boolean DEBUGGING = TestsPlugin.instance.isDebugging();
-
- static final Bundle EmfTransactionTestsBundle = TestsPlugin.instance.getBundle();
+
+ static final Bundle EmfTransactionTestsBundle = TestsPlugin.instance.getBundle();
protected IProject project;
protected IFile file;
protected TransactionalEditingDomain domain;
protected Resource testResource;
protected Library root;
-
- protected static final String PROJECT_NAME = "emftxtests";
- protected static final String RESOURCE_NAME = "/" + PROJECT_NAME + "/testres.extlibrary";
-
- private final List transactionStack =
- new java.util.ArrayList();
-
- private List tearDownActions;
-
+
+ protected static final String PROJECT_NAME = "emftxtests";
+ protected static final String RESOURCE_NAME = "/" + PROJECT_NAME + "/testres.extlibrary";
+
+ private final List transactionStack = new java.util.ArrayList<>();
+
+ private List tearDownActions;
+
//
// Test configuration methods
//
-
- @Before
- public void setUp()
- throws Exception {
-
- trace("===> Begin : " + this.getClass().getName());
-
+
+ @BeforeEach
+ public void setUp() throws Exception {
+
+ trace("===> Begin : " + this.getClass().getName());
+
doSetUp();
}
-
- protected void doSetUp()
- throws Exception {
-
+
+ protected void doSetUp() throws Exception {
+
project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME);
if (!project.exists()) {
project.create(null);
}
-
+
project.open(null);
file = project.getParent().getFile(new Path(RESOURCE_NAME));
-
+
ResourceSet rset = createResourceSet();
-
+
try {
Resource originalRes = rset.getResource(
- URI.createURI(EmfTransactionTestsBundle.getEntry(
- "/test_models/test_model.extlibrary").toString()),
+ URI.createURI(EmfTransactionTestsBundle.getEntry("/test_models/test_model.extlibrary").toString()),
true);
originalRes.setURI(URI.createPlatformResourceURI(RESOURCE_NAME, true));
originalRes.save(Collections.EMPTY_MAP);
testResource = originalRes;
- root = (Library) find("root");
+ root = (Library) find("root");
} catch (IOException e) {
- Assert.fail("Failed to load test model: " + e.getLocalizedMessage());
-
+ Assertions.fail("Failed to load test model: " + e.getLocalizedMessage());
+
}
-
+
domain = createEditingDomain(rset);
}
@@ -130,55 +124,53 @@ protected void doSetUp()
protected TransactionalEditingDomain createEditingDomain(ResourceSet rset) {
return TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain(rset);
}
-
+
/** May be overridden by subclasses to create non-default resource set. */
protected ResourceSet createResourceSet() {
return new ResourceSetImpl();
}
- /**
- * Adds an action to perform some clean-up following completion of the test.
- * The test framework guarantees that it will at least attempt to execute
- * this action.
- *
- * @param action the tear-down action to run
- */
- protected final void addTearDownAction(Runnable action) {
- if (tearDownActions == null) {
- tearDownActions = new java.util.ArrayList();
- }
-
- tearDownActions.add(action);
- }
-
- @After
- public final void tearDown()
- throws Exception {
-
+ /**
+ * Adds an action to perform some clean-up following completion of the test. The
+ * test framework guarantees that it will at least attempt to execute this
+ * action.
+ *
+ * @param action the tear-down action to run
+ */
+ protected final void addTearDownAction(Runnable action) {
+ if (tearDownActions == null) {
+ tearDownActions = new java.util.ArrayList<>();
+ }
+
+ tearDownActions.add(action);
+ }
+
+ @AfterEach
+ public final void tearDown() throws Exception {
+
try {
doTearDown();
} finally {
- processTearDownActions();
- trace("===> End : " + this.getClass().getName());
- }
- }
-
- private void processTearDownActions() {
- if (tearDownActions != null) {
- for (Runnable action : tearDownActions) {
- try {
- action.run();
- } catch (Exception e) {
- System.err.println("Exception in tear-down action:");
- e.printStackTrace();
- }
- }
- }
- }
-
- protected void doTearDown()
- throws Exception {
-
+ processTearDownActions();
+ trace("===> End : " + this.getClass().getName());
+ }
+ }
+
+ private void processTearDownActions() {
+ if (tearDownActions != null) {
+ for (Runnable action : tearDownActions) {
+ try {
+ action.run();
+ } catch (Exception e) {
+ System.err.println("Exception in tear-down action:");
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ protected void doTearDown() throws Exception {
+
while (!transactionStack.isEmpty()) {
// unwind the current transaction stack
if (getActiveTransaction().isActive()) {
@@ -192,27 +184,27 @@ protected void doTearDown()
transactionStack.remove(transactionStack.size() - 1);
}
}
-
+
root = null;
if (testResource != null) {
unloadAndRemove(testResource);
testResource = null;
}
-
+
project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME);
-
+
delete(project);
-
+
project = null;
file = null;
domain = null;
}
-
+
protected void delete(java.io.File file) {
if (!file.exists()) {
return;
}
-
+
try {
IFileStore store = EFS.getLocalFileSystem().fromLocalFile(file);
IFileInfo info = store.fetchInfo();
@@ -221,15 +213,15 @@ protected void delete(java.io.File file) {
info.setAttribute(EFS.ATTRIBUTE_ARCHIVE, false);
store.putInfo(info, EFS.SET_ATTRIBUTES, null);
} catch (Exception e) {
- Assert.fail("Failed to clean up test file: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to clean up test file: " + e.getLocalizedMessage());
}
}
-
+
protected void delete(IFile file) {
if (!file.exists()) {
return;
}
-
+
try {
if (file.isReadOnly()) {
// on Mac, it can become read-only in certain tests
@@ -241,193 +233,192 @@ protected void delete(IFile file) {
}
file.delete(true, null);
} catch (Exception e) {
- Assert.fail("Failed to clean up test file: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to clean up test file: " + e.getLocalizedMessage());
}
}
-
+
protected void delete(IProject project) {
if (!project.exists()) {
return;
}
-
+
try {
project.refreshLocal(IResource.DEPTH_INFINITE, null);
-
+
project.accept(new IResourceVisitor() {
- public boolean visit(IResource res)
- throws CoreException {
+ @Override
+ public boolean visit(IResource res) throws CoreException {
if (res.getType() == IResource.FILE) {
delete((IFile) res);
}
-
+
return true;
- }});
-
+ }
+ });
+
project.delete(true, true, null);
- } catch (Exception e) {
- Assert.fail("Failed to clean up test project: " + e.getLocalizedMessage());
+ } catch (Exception e) {
+ Assertions.fail("Failed to clean up test project: " + e.getLocalizedMessage());
}
}
//
// Other framework methods
//
-
+
public static void trace(String message) {
if (DEBUGGING) {
System.out.println(message);
System.out.flush();
}
}
-
+
protected Resource createTestResource(String name) {
Resource result = null;
-
+
try {
- InputStream input =
- EmfTransactionTestsBundle.getEntry("/test_models/" + name).openStream();
-
- IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(
- new Path(PROJECT_NAME + '/' + name));
+ InputStream input = EmfTransactionTestsBundle.getEntry("/test_models/" + name).openStream();
+
+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(PROJECT_NAME + '/' + name));
file.create(input, true, null);
-
- result = domain.createResource(
- URI.createPlatformResourceURI(file.getFullPath().toString(), true).toString());
+
+ result = domain
+ .createResource(URI.createPlatformResourceURI(file.getFullPath().toString(), true).toString());
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Exception creating test resource: " + e.getLocalizedMessage());
+ Assertions.fail("Exception creating test resource: " + e.getLocalizedMessage());
}
-
+
return result;
}
-
+
protected void unloadAndRemove(Resource res) {
if (res.isLoaded()) {
res.unload();
}
-
+
if (res.getResourceSet() != null) {
res.getResourceSet().getResources().remove(res);
}
}
-
+
/**
* Records a failure due to an exception that should not have been thrown.
- *
+ *
* @param e the exception
*/
protected void fail(Exception e) {
e.printStackTrace();
- Assert.fail("Should not have thrown: " + e.getLocalizedMessage());
+ Assertions.fail("Should not have thrown: " + e.getLocalizedMessage());
}
-
+
/**
* Asserts that we can find an object having the specified name.
- *
+ *
* @param name the name to seek
- *
+ *
* @see #find(String)
*/
protected void assertFound(String name) {
- assertNotNull("Did not find " + name, find(testResource, name));
+ assertNotNull(find(testResource, name), "Did not find " + name);
}
-
+
/**
- * Asserts that we can find an object having the specified name, relative
- * to the specified starting object.
- *
+ * Asserts that we can find an object having the specified name, relative to the
+ * specified starting object.
+ *
* @param start the object from which to start looking (to which the
- * name is relative). This can be a resource or an
- * element
- * @param name the name to seek
- *
+ * name is relative). This can be a resource or an
+ * element
+ * @param name the name to seek
+ *
* @see #find(Object, String)
*/
protected void assertFound(Object start, String name) {
- assertNotNull("Did not find " + name, find(testResource, name));
+ assertNotNull(find(testResource, name), "Did not find " + name); // FIXME: use start instead of testResource
}
-
+
/**
* Asserts that we cannot find an object having the specified name.
- *
+ *
* @param name the name to (not) seek
- *
+ *
* @see #find(String)
*/
protected void assertNotFound(String name) {
- assertNull("Found " + name, find(testResource, name));
+ assertNull(find(testResource, name), "Found " + name);
}
-
+
/**
- * Asserts that we cannot find an object having the specified name, relative
- * to the specified starting object.
- *
+ * Asserts that we cannot find an object having the specified name, relative to
+ * the specified starting object.
+ *
* @param start the object from which to start looking (to which the
- * name is relative). This can be a resource or an
- * element
- * @param name the name to (not) seek
- *
+ * name is relative). This can be a resource or an
+ * element
+ * @param name the name to (not) seek
+ *
* @see #find(Object, String)
*/
protected void assertNotFound(Object start, String name) {
- assertNull("Found " + name, find(testResource, name));
+ assertNull(find(testResource, name), "Found " + name);
}
-
+
/**
* Finds the object in the test model having the specified qualified name.
- *
+ *
* @param qname a slash-delimited qualified name
* @return the matching object, or null if not found
*/
protected EObject find(String qname) {
return find(testResource, qname);
}
-
+
/**
* Finds the object in the test model having the specified qualified name,
* starting from some object.
- *
+ *
* @param object the starting object (resource or element)
- * @param qname a slash-delimited qualified name, relative to the
- * provided object
+ * @param qname a slash-delimited qualified name, relative to the provided
+ * object
* @return the matching object, or null if not found
*/
protected EObject find(Object start, String qname) {
EObject result = null;
Object current = start;
-
+
String[] names = tokenize(qname);
-
+
for (int i = 0; (current != null) && (i < names.length); i++) {
String name = names[i];
result = null;
-
+
for (EObject child : getContents(current)) {
if (name.equals(getName(child))) {
result = child;
break;
}
}
-
+
current = result;
}
-
+
return result;
}
/**
* Gets the name of a library object.
- *
+ *
* @param object the object
* @return its name
*/
protected String getName(EObject object) {
return GetName.INSTANCE.doSwitch(object);
}
-
+
/**
* Gets the contents of an object.
- *
+ *
* @param object an object, which may be a resource or an element
* @return its immediate contents (children)
*/
@@ -440,17 +431,17 @@ private List getContents(Object object) {
return Collections.emptyList();
}
}
-
+
/**
* Tokenizes a qualified name on the slashes.
- *
+ *
* @param qname a qualified name
* @return the parts between the slashes
*/
private String[] tokenize(String qname) {
- return qname.split("/");
+ return qname.split("/");
}
-
+
/**
* Switch to compute the names of library objects.
*
@@ -458,15 +449,10 @@ private String[] tokenize(String qname) {
*/
private static final class GetName extends EXTLibrarySwitch {
static final GetName INSTANCE = new GetName();
-
+
private GetName() {
super();
}
-
- @SuppressWarnings("unused")
- public Object caseAudoVisualItem(AudioVisualItem object) {
- return object.getTitle();
- }
@Override
public String caseBook(Book object) {
@@ -482,7 +468,7 @@ public String caseLibrary(Library object) {
public String casePeriodical(Periodical object) {
return object.getTitle();
}
-
+
@Override
public String caseWriter(Writer object) {
return object.getName();
@@ -492,7 +478,7 @@ public String caseWriter(Writer object) {
public String casePerson(Person object) {
if (object.getFirstName() == null) {
if (object.getLastName() == null) {
- return "";
+ return "";
} else {
return object.getLastName();
}
@@ -501,8 +487,7 @@ public String casePerson(Person object) {
} else {
StringBuffer result = new StringBuffer();
- result.append(object.getFirstName()).append(' ').append(
- object.getLastName());
+ result.append(object.getFirstName()).append(' ').append(object.getLastName());
return result.toString();
}
@@ -510,169 +495,163 @@ public String casePerson(Person object) {
@Override
public String defaultCase(EObject object) {
- return "";
+ return "";
}
}
-
+
/**
* Gets the current domain's command stack.
- *
+ *
* @return the command stack
*/
protected TransactionalCommandStack getCommandStack() {
return (TransactionalCommandStack) domain.getCommandStack();
}
-
+
/**
* Opens a read-write transaction without options.
*/
protected void startWriting() {
try {
- transactionStack.add(
- ((InternalTransactionalEditingDomain) domain).startTransaction(false, null));
+ transactionStack.add(((InternalTransactionalEditingDomain) domain).startTransaction(false, null));
} catch (Exception e) {
fail(e);
}
}
-
+
/**
* Opens a read-write transaction with one option.
- *
+ *
* @param option the option
*/
protected void startWriting(String option) {
startWriting(makeOptions(option));
}
-
+
/**
* Opens a read-write transaction with the specified options.
- *
+ *
* @param options the options
*/
protected void startWriting(Map, ?> options) {
try {
- transactionStack.add(
- ((InternalTransactionalEditingDomain) domain).startTransaction(false, options));
+ transactionStack.add(((InternalTransactionalEditingDomain) domain).startTransaction(false, options));
} catch (Exception e) {
fail(e);
}
}
-
+
/**
* Opens a read-only transaction without any options.
*/
protected void startReading() {
try {
- transactionStack.add(
- ((InternalTransactionalEditingDomain) domain).startTransaction(true, null));
+ transactionStack.add(((InternalTransactionalEditingDomain) domain).startTransaction(true, null));
} catch (Exception e) {
fail(e);
}
}
-
+
/**
* Opens a read-only transaction with one option.
- *
+ *
* @param option the option
*/
protected void startReading(String option) {
startReading(makeOptions(option));
}
-
+
/**
* Opens a read-only transaction with the specified options.
- *
+ *
* @param options the options
*/
protected void startReading(Map, ?> options) {
try {
- transactionStack.add(
- ((InternalTransactionalEditingDomain) domain).startTransaction(true, options));
+ transactionStack.add(((InternalTransactionalEditingDomain) domain).startTransaction(true, options));
} catch (Exception e) {
fail(e);
}
}
-
+
/**
* Commits the most recently-opened transaction.
*/
protected Transaction commit() {
Transaction result = null;
-
+
try {
result = transactionStack.remove(transactionStack.size() - 1);
result.commit();
} catch (Exception e) {
fail(e);
}
-
+
return result;
}
-
+
/**
* Rolls back the most recently-opened transaction.
*/
protected Transaction rollback() {
Transaction result = null;
-
+
try {
result = transactionStack.remove(transactionStack.size() - 1);
result.rollback();
} catch (Exception e) {
fail(e);
}
-
+
return result;
}
-
+
/**
* Obtains the most recently-opened transaction (the "active" transaction).
- *
+ *
* @return the current transaction, or null if none is active
*/
protected InternalTransaction getActiveTransaction() {
- return transactionStack.isEmpty()
- ? null
- : (InternalTransaction) transactionStack.get(transactionStack.size() - 1);
+ return transactionStack.isEmpty() ? null
+ : (InternalTransaction) transactionStack.get(transactionStack.size() - 1);
}
-
+
/**
* Makes a map from one option.
- *
+ *
* @param option the option to enable
- *
+ *
* @return the map
*/
protected Map makeOptions(String option) {
return Collections.singletonMap(option, Boolean.TRUE);
}
-
+
/**
- * Gets the validation statuses having the specified severity within
- * the specified status object.
- *
- * @param status a status (often a multi-status)
+ * Gets the validation statuses having the specified severity within the
+ * specified status object.
+ *
+ * @param status a status (often a multi-status)
* @param severity the severity of status to look for
- *
+ *
* @return the matching statuses, or an empty collection if none found
*/
protected Collection findValidationStatuses(IStatus status, int severity) {
Set result;
-
+
if (status.isMultiStatus()) {
- result = new java.util.HashSet();
+ result = new java.util.HashSet<>();
IStatus[] children = status.getChildren();
-
+
for (IStatus element : children) {
result.addAll(findValidationStatuses(element, severity));
}
- } else if ((status instanceof IConstraintStatus)
- && (status.matches(severity))) {
+ } else if ((status instanceof IConstraintStatus) && (status.matches(severity))) {
result = Collections.singleton(status);
} else {
result = Collections.emptySet();
}
-
+
return result;
}
@@ -686,15 +665,10 @@ protected void idle(long millis) {
protected void runGC() {
System.gc();
-
+
idle(2000);
-
+
System.gc();
}
-
- public void test_DoNothing() {
- // see Bugzilla 493963
- String why = "Maven wants to find a test to run in this abstract class";
- assertTrue(why.contains("Maven"));
- }
+
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/BasicTransactionTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/BasicTransactionTest.java
index a1ec2d7d..686cb773 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/BasicTransactionTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/BasicTransactionTest.java
@@ -12,11 +12,11 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+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.assertTrue;
import java.util.Collections;
import java.util.Iterator;
@@ -46,22 +46,21 @@
import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
import org.eclipse.emf.transaction.internal.EMFTransactionStatusCodes;
import org.eclipse.emf.transaction.tests.fixtures.TestListener;
-import org.junit.Assert;
-import org.junit.Test;
-
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
public class BasicTransactionTest extends AbstractTest {
/**
- * Tests that read transactions are not actually enforced for EList initialization,
- * etc.
+ * Tests that read transactions are not actually enforced for EList
+ * initialization, etc.
*/
@Test
public void test_read() {
try {
// should be able to read with running exclusive, as we cannot
- // actually enforce the protocol
- assertNotNull(find("root/Root Book")); //$NON-NLS-1$
+ // actually enforce the protocol
+ assertNotNull(find("root/Root Book"));
} catch (Exception e) {
fail(e);
}
@@ -74,9 +73,9 @@ public void test_read() {
public void test_read_readOnlyTransaction() {
// should be able to read in a read-only transaction
startReading();
-
- assertNotNull(find("root/Root Book")); //$NON-NLS-1$
-
+
+ assertNotNull(find("root/Root Book"));
+
commit();
}
@@ -87,9 +86,9 @@ public void test_read_readOnlyTransaction() {
public void test_read_readWriteTransaction() {
// should be able to read in a read/write transaction
startWriting();
-
- assertNotNull(find("root/Root Book")); //$NON-NLS-1$
-
+
+ assertNotNull(find("root/Root Book"));
+
commit();
}
@@ -101,15 +100,17 @@ public void test_read_exclusive() {
try {
// should be able to read exclusively
final Book book[] = new Book[1];
-
+
domain.runExclusive(new Runnable() {
+ @Override
public void run() {
- book[0] = (Book) find("root/Root Book"); //$NON-NLS-1$
- }});
-
+ book[0] = (Book) find("root/Root Book");
+ }
+ });
+
assertNotNull(book[0]);
} catch (InterruptedException e) {
- Assert.fail("Should not be interrupted"); //$NON-NLS-1$
+ Assertions.fail("Should not be interrupted");
} catch (Exception e) {
fail(e);
}
@@ -123,67 +124,73 @@ public void run() {
public void test_read_exclusive_nested() {
try {
domain.runExclusive(new Runnable() {
+ @Override
public void run() {
try {
domain.runExclusive(new Runnable() {
+ @Override
public void run() {
try {
domain.runExclusive(new Runnable() {
+ @Override
public void run() {
// there should be an active transaction
- Transaction active =
- ((InternalTransactionalEditingDomain) domain).getActiveTransaction();
+ Transaction active = ((InternalTransactionalEditingDomain) domain)
+ .getActiveTransaction();
assertNotNull(active);
-
+
assertTrue(active.isReadOnly());
-
+
// the transaction is not nested
assertNull(active.getParent());
- }});
+ }
+ });
} catch (InterruptedException e) {
- Assert.fail("Should not be interrupted"); //$NON-NLS-1$
+ Assertions.fail("Should not be interrupted");
} catch (Exception e) {
fail(e);
}
- }});
+ }
+ });
} catch (InterruptedException e) {
- Assert.fail("Should not be interrupted"); //$NON-NLS-1$
+ Assertions.fail("Should not be interrupted");
} catch (Exception e) {
fail(e);
}
- }});
+ }
+ });
} catch (InterruptedException e) {
- Assert.fail("Should not be interrupted"); //$NON-NLS-1$
+ Assertions.fail("Should not be interrupted");
} catch (Exception e) {
fail(e);
}
}
-
+
/**
* Tests that we cannot write without a write transaction.
*/
@Test
public void test_write() {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
commit();
-
+
try {
// try to modify it
- book.setTitle("New Title"); //$NON-NLS-1$
-
+ book.setTitle("New Title");
+
// should have thrown
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (IllegalStateException e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
} catch (Exception e) {
fail(e);
}
}
-
+
/**
* Tests that we cannot write in a read-only transaction.
*/
@@ -191,24 +198,24 @@ public void test_write() {
public void test_write_readOnlytransaction() {
try {
startReading();
-
- Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
-
+
+ Book book = (Book) find("root/Root Book");
+
// try to modify it in a read/write transaction
- book.setTitle("New Title"); //$NON-NLS-1$
-
+ book.setTitle("New Title");
+
// should have thrown
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (IllegalStateException e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
} catch (Exception e) {
fail(e);
} finally {
rollback();
}
}
-
+
/**
* Tests that we can write in a read-write transaction.
*/
@@ -216,15 +223,15 @@ public void test_write_readOnlytransaction() {
public void test_write_readWritetransaction() {
try {
startWriting();
-
- Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
-
+
+ Book book = (Book) find("root/Root Book");
+
// try to modify it in a read/write transaction
- book.setTitle("New Title"); //$NON-NLS-1$
-
+ book.setTitle("New Title");
+
commit();
-
- assertEquals("New Title", book.getTitle()); //$NON-NLS-1$
+
+ assertEquals("New Title", book.getTitle());
} catch (Exception e) {
fail(e);
} finally {
@@ -233,38 +240,39 @@ public void test_write_readWritetransaction() {
}
}
}
-
+
/**
* Tests that we cannot write from a different thread than the thread that
- * currently has a write transaction open. Also tests that the thread that
- * had the valid write transaction is aborted.
+ * currently has a write transaction open. Also tests that the thread that had
+ * the valid write transaction is aborted.
*/
@Test
public void test_write_wrongThread() {
final Object monitor = new Object();
-
+
Thread t = new Thread(new Runnable() {
-
+
+ @Override
public void run() {
Transaction xa = null;
-
+
try {
synchronized (monitor) {
xa = ((InternalTransactionalEditingDomain) domain).startTransaction(true, null);
-
+
// wake up the main thread
monitor.notifyAll();
-
+
// wait for the main thread to continue
monitor.wait();
-
- // attempt commit. Should roll back because of abort
+
+ // attempt commit. Should roll back because of abort
try {
xa.commit();
- Assert.fail("Should have thrown RollbackException"); //$NON-NLS-1$
+ Assertions.fail("Should have thrown RollbackException");
} catch (RollbackException e) {
// success
- trace("Got expected rollback: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected rollback: " + e.getLocalizedMessage());
} finally {
xa = null;
}
@@ -276,26 +284,27 @@ public void run() {
xa.rollback();
}
}
- }});
-
+ }
+ });
+
try {
synchronized (monitor) {
t.start();
-
+
// wait for the thread to start its transaction
monitor.wait();
}
-
- Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
-
+
+ Book book = (Book) find("root/Root Book");
+
// try to modify it in a read/write transaction
- book.setTitle("New Title"); //$NON-NLS-1$
-
+ book.setTitle("New Title");
+
// should have thrown
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (IllegalStateException e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
} catch (Exception e) {
fail(e);
} finally {
@@ -305,32 +314,28 @@ public void run() {
}
}
}
-
+
/**
* Tests that we can use the command stack to execute a writing command.
*/
@Test
public void test_write_command() {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
commit();
-
+
try {
// try to modify it using a command
-
- Command cmd = new SetCommand(
- domain,
- book,
- EXTLibraryPackage.eINSTANCE.getBook_Title(),
- "New Title"); //$NON-NLS-1$
+
+ Command cmd = new SetCommand(domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), "New Title");
((TransactionalCommandStack) domain.getCommandStack()).execute(cmd, null);
-
+
startReading();
-
- assertEquals("New Title", book.getTitle()); //$NON-NLS-1$
-
+
+ assertEquals("New Title", book.getTitle());
+
commit();
} catch (Exception e) {
fail(e);
@@ -347,30 +352,29 @@ public void test_loadUnloadDuringRead() throws Exception {
doTearDown();
ResourceSet rset = new ResourceSetImpl();
domain = createEditingDomain(rset);
-
+
TestListener listener = new TestListener();
domain.addResourceSetListener(listener);
-
+
startReading();
-
+
Resource res = rset.createResource(
- URI.createURI(EmfTransactionTestsBundle.getEntry(
- "/test_models/test_model.extlibrary").toString())); //$NON-NLS-1$
+ URI.createURI(EmfTransactionTestsBundle.getEntry("/test_models/test_model.extlibrary").toString()));
res.load(Collections.EMPTY_MAP);
-
+
commit();
-
+
// check that we got the expected events
assertNotNull(listener.postcommit);
List notifications = listener.postcommitNotifications;
assertFalse(notifications.isEmpty());
-
+
// look for an event indicating resource was loaded and one indicating
- // that a root was added. The root added event should come first!
+ // that a root was added. The root added event should come first!
Notification rootAdded = null;
Notification resLoaded = null;
-
+
for (Notification next : notifications) {
if (next.getNotifier() == res) {
if (next.getFeatureID(null) == Resource.RESOURCE__IS_LOADED) {
@@ -385,28 +389,28 @@ public void test_loadUnloadDuringRead() throws Exception {
}
}
}
-
+
assertNotNull(rootAdded);
assertNotNull(resLoaded);
-
- listener.reset(); // clear stored events
-
+
+ listener.reset(); // clear stored events
+
startReading();
-
+
res.unload();
-
+
commit();
-
+
// check that we got the expected events
assertNotNull(listener.postcommit);
notifications = listener.postcommitNotifications;
assertFalse(notifications.isEmpty());
-
+
// look for an event indicating resource was unloaded and one indicating
- // that a root was removed. The root removed event should come first!
+ // that a root was removed. The root removed event should come first!
Notification rootRemoved = null;
Notification resUnloaded = null;
-
+
for (Notification next : notifications) {
if (next.getNotifier() == res) {
if (next.getFeatureID(null) == Resource.RESOURCE__IS_LOADED) {
@@ -421,11 +425,11 @@ public void test_loadUnloadDuringRead() throws Exception {
}
}
}
-
+
assertNotNull(rootRemoved);
assertNotNull(resUnloaded);
}
-
+
/**
* Tests that changes to the contents of a loaded resource may not be performed
* in a read transaction.
@@ -434,30 +438,30 @@ public void test_loadUnloadDuringRead() throws Exception {
public void test_resourceContentsChanges_read() {
try {
startReading();
-
+
testResource.getContents().add(EXTLibraryFactory.eINSTANCE.createLibrary());
-
+
// should have thrown
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (IllegalStateException e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
} catch (Exception e) {
fail(e);
} finally {
rollback();
}
}
-
+
/**
- * Tests that changes to the contents of a loaded resource may be performed
- * in a write transaction.
+ * Tests that changes to the contents of a loaded resource may be performed in a
+ * write transaction.
*/
@Test
public void test_resourceContentsChanges_write() {
try {
startWriting();
-
+
testResource.getContents().add(EXTLibraryFactory.eINSTANCE.createLibrary());
} catch (Exception e) {
fail(e);
@@ -465,45 +469,45 @@ public void test_resourceContentsChanges_write() {
rollback();
}
}
-
+
/**
- * Tests that we cannot add a root to a newly created resource in a read transaction.
+ * Tests that we cannot add a root to a newly created resource in a read
+ * transaction.
*/
@Test
public void test_newResourceContentsChanges_read() {
try {
startReading();
-
- Resource res = domain.getResourceSet().createResource(
- URI.createFileURI("/tmp/foo.extlibrary")); //$NON-NLS-1$
+
+ Resource res = domain.getResourceSet().createResource(URI.createFileURI("/tmp/foo.extlibrary"));
assertFalse(res.isLoaded());
-
+
res.getContents().add(EXTLibraryFactory.eINSTANCE.createLibrary());
-
+
// should have thrown
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (IllegalStateException e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
} catch (Exception e) {
fail(e);
} finally {
rollback();
}
}
-
+
/**
- * Tests that we can add a root to a newly created resource in a write transaction.
+ * Tests that we can add a root to a newly created resource in a write
+ * transaction.
*/
@Test
public void test_newResourceContentsChanges_write() {
try {
startWriting();
-
- Resource res = domain.getResourceSet().createResource(
- URI.createFileURI("/tmp/foo.extlibrary")); //$NON-NLS-1$
+
+ Resource res = domain.getResourceSet().createResource(URI.createFileURI("/tmp/foo.extlibrary"));
assertFalse(res.isLoaded());
-
+
res.getContents().add(EXTLibraryFactory.eINSTANCE.createLibrary());
} catch (Exception e) {
fail(e);
@@ -511,7 +515,7 @@ public void test_newResourceContentsChanges_write() {
rollback();
}
}
-
+
/**
* Tests that a RunnableWithResult has its status set correctly when it is
* rolled back due to concurrent write.
@@ -519,37 +523,41 @@ public void test_newResourceContentsChanges_write() {
@Test
public void test_concurrentWrite_runnable() {
final Object monitor = new Object();
-
+
final Thread t = new Thread(new Runnable() {
+ @Override
public void run() {
synchronized (monitor) {
try {
// concurrent write
testResource.getContents().add(EXTLibraryFactory.eINSTANCE.createLibrary());
} catch (IllegalStateException e) {
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
} finally {
monitor.notify();
}
}
- }});
-
+ }
+ });
+
try {
- RunnableWithResult> rwr = new RunnableWithResult.Impl() {
+ RunnableWithResult> rwr = new RunnableWithResult.Impl<>() {
+ @Override
public void run() {
synchronized (monitor) {
t.start();
try {
- monitor.wait(); // wait for the concurrent write
+ monitor.wait(); // wait for the concurrent write
} catch (InterruptedException e) {
fail(e);
}
}
- }};
-
+ }
+ };
+
domain.runExclusive(rwr);
-
+
// shouldn't throw, but should get an error status
assertNotNull(rwr.getStatus());
assertEquals(IStatus.ERROR, rwr.getStatus().getSeverity());
@@ -566,42 +574,41 @@ public void run() {
public void test_closedTransaction_close() {
// should be able to read in a read-only transaction
startReading();
-
+
Transaction tx = commit();
-
+
try {
tx.commit();
-
+
// should have thrown
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (IllegalStateException e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
} catch (RollbackException e) {
fail(e);
}
-
+
try {
tx.rollback();
-
+
// should have thrown
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (IllegalStateException e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
}
}
-
+
@Test
public void test_readWrongThread_250498() {
final Object monitor = new Object();
- final List readNotifications = new java.util.ArrayList();
+ final List readNotifications = new java.util.ArrayList<>();
ResourceSetListener l = new ResourceSetListenerImpl() {
@Override
- public Command transactionAboutToCommit(ResourceSetChangeEvent event)
- throws RollbackException {
+ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
Command result = null;
@@ -609,14 +616,11 @@ public Command transactionAboutToCommit(ResourceSetChangeEvent event)
// notifications list
for (Notification next : event.getNotifications()) {
if ((next.getNotifier() instanceof Book)
- && (next.getFeature() == EXTLibraryPackage.Literals.BOOK__TITLE)) {
+ && (next.getFeature() == EXTLibraryPackage.Literals.BOOK__TITLE)) {
Command cmd = domain.createCommand(SetCommand.class,
- new CommandParameter(next.getNotifier(), next
- .getFeature(), 123));
+ new CommandParameter(next.getNotifier(), next.getFeature(), 123));
- result = (result == null)
- ? cmd
- : result.chain(cmd);
+ result = (result == null) ? cmd : result.chain(cmd);
}
}
@@ -637,22 +641,21 @@ public void resourceSetChanged(ResourceSetChangeEvent event) {
Thread t = new Thread(new Runnable() {
+ @Override
public void run() {
Transaction xa = null;
try {
synchronized (monitor) {
- xa = ((InternalTransactionalEditingDomain) domain)
- .startTransaction(false, null);
+ xa = ((InternalTransactionalEditingDomain) domain).startTransaction(false, null);
// do a bunch of stuff
- for (Iterator> all = root.eAllContents(); all
- .hasNext();) {
+ for (Iterator> all = root.eAllContents(); all.hasNext();) {
Object next = all.next();
if (next instanceof Book) {
Book book = (Book) next;
- book.setTitle("123 " + book.getTitle()); //$NON-NLS-1$
+ book.setTitle("123 " + book.getTitle());
Library lib = (Library) book.eContainer();
if (!lib.getWriters().isEmpty()) {
@@ -671,7 +674,7 @@ public void run() {
try {
xa.commit();
} catch (RollbackException e) {
- Assert.fail("Should not have rolled back: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assertions.fail("Should not have rolled back: " + e.getLocalizedMessage());
} finally {
xa = null;
}
@@ -701,13 +704,8 @@ public void run() {
monitor.wait();
// cause notifications compatible with a read-only context
- root
- .eResource()
- .getResourceSet()
- .getResource(
- URI
- .createURI("platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore"), //$NON-NLS-1$
- true);
+ root.eResource().getResourceSet()
+ .getResource(URI.createURI("platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore"), true);
// let the other thread try to commit
monitor.notifyAll();
@@ -715,8 +713,7 @@ public void run() {
// and wait for it
monitor.wait();
- assertEquals(
- "Got foreign notifications", 0, readNotifications.size()); //$NON-NLS-1$
+ assertEquals(0, readNotifications.size(), "Got foreign notifications");
}
} catch (Exception e) {
fail(e);
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ChangeDescriptionTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ChangeDescriptionTest.java
index 557a94e3..e10874c2 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ChangeDescriptionTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ChangeDescriptionTest.java
@@ -12,7 +12,7 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.File;
import java.util.Collections;
@@ -43,13 +43,13 @@
import org.eclipse.emf.transaction.ResourceSetListenerImpl;
import org.eclipse.emf.transaction.RollbackException;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* A test case for https://bugs.eclipse.org/bugs/show_bug.cgi?id=460206
- *
+ *
* @author Esteban Dugueperoux
*/
public class ChangeDescriptionTest {
@@ -62,7 +62,7 @@ public class ChangeDescriptionTest {
private EPackage rootEPackage1;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
resourceSet = new ResourceSetImpl();
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
@@ -73,7 +73,7 @@ public void setUp() throws Exception {
resource.getContents().add(rootEPackage1);
}
- @After
+ @AfterEach
public void tearDown() {
rootEPackage1 = null;
resource = null;
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainRegistryTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainRegistryTest.java
index ff835547..96eee1ed 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainRegistryTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainRegistryTest.java
@@ -11,12 +11,12 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+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 java.lang.ref.WeakReference;
import java.util.List;
@@ -27,9 +27,8 @@
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.tests.fixtures.TestEditingDomain;
import org.eclipse.emf.transaction.tests.fixtures.TestListener;
-import org.junit.Assert;
-import org.junit.Test;
-
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests the editing domain registry and the associated extension point.
@@ -37,10 +36,10 @@
* @author Christian W. Damus (cdamus)
*/
public class EditingDomainRegistryTest extends AbstractTest {
- private static final String TEST_DOMAIN1 = "org.eclipse.emf.transaction.tests.TestDomain1";
- private static final String TEST_DOMAIN2 = "org.eclipse.emf.transaction.tests.TestDomain2";
- private static final String TEST_DOMAIN3 = "org.eclipse.emf.transaction.tests.TestDomain3";
- private static final String TEST_DOMAIN4 = "org.eclipse.emf.transaction.tests.TestDomain4";
+ private static final String TEST_DOMAIN1 = "org.eclipse.emf.transaction.tests.TestDomain1";
+ private static final String TEST_DOMAIN2 = "org.eclipse.emf.transaction.tests.TestDomain2";
+ private static final String TEST_DOMAIN3 = "org.eclipse.emf.transaction.tests.TestDomain3";
+ private static final String TEST_DOMAIN4 = "org.eclipse.emf.transaction.tests.TestDomain4";
/**
* Tests dynamically adding and removing domains in the registry.
@@ -48,91 +47,79 @@ public class EditingDomainRegistryTest extends AbstractTest {
@Test
public void test_dynamicAddRemove() {
assertNull(domain.getID());
-
+
TransactionalEditingDomain.Registry.INSTANCE.add(TEST_DOMAIN2, domain);
-
+
// registry set the ID
assertEquals(TEST_DOMAIN2, domain.getID());
-
- assertSame(domain, TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- TEST_DOMAIN2));
-
+
+ assertSame(domain, TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(TEST_DOMAIN2));
+
// remove the domain
- assertSame(domain, TransactionalEditingDomain.Registry.INSTANCE.remove(
- TEST_DOMAIN2));
-
+ assertSame(domain, TransactionalEditingDomain.Registry.INSTANCE.remove(TEST_DOMAIN2));
+
// no longer present
assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(TEST_DOMAIN2));
-
+
// still have our ID
assertEquals(TEST_DOMAIN2, domain.getID());
}
-
+
/**
* Tests the static registration of editing domains on the extension point.
*/
public void ignore_test_staticRegistration() {
// check initial conditions for this test
assertEquals(0, TestEditingDomain.instanceCount);
-
- TransactionalEditingDomain registered = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- TEST_DOMAIN1);
-
+
+ TransactionalEditingDomain registered = TransactionalEditingDomain.Registry.INSTANCE
+ .getEditingDomain(TEST_DOMAIN1);
+
assertTrue(registered instanceof TestEditingDomain); // our factory was used
- assertEquals(TEST_DOMAIN1, registered.getID()); // ID matches
- assertEquals(1, TestEditingDomain.instanceCount); // one instance
-
+ assertEquals(TEST_DOMAIN1, registered.getID()); // ID matches
+ assertEquals(1, TestEditingDomain.instanceCount); // one instance
+
// cannot remove statically registered domains
try {
TransactionalEditingDomain.Registry.INSTANCE.remove(TEST_DOMAIN1);
- Assert.fail("Should have thrown IllegalArgumentException");
+ Assertions.fail("Should have thrown IllegalArgumentException");
} catch (IllegalArgumentException e) {
- trace("Got expected exception: " + e.getLocalizedMessage());
+ trace("Got expected exception: " + e.getLocalizedMessage());
}
-
+
// check that it is not recreated by another get call
- assertSame(
- registered,
- TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(TEST_DOMAIN1));
- assertEquals(1, TestEditingDomain.instanceCount); // no new instance
+ assertSame(registered, TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(TEST_DOMAIN1));
+ assertEquals(1, TestEditingDomain.instanceCount); // no new instance
}
-
+
/**
* Tests the replacement of a domain under an ID with another.
*/
@Test
public void test_replaceDomain() {
- TransactionalEditingDomain domain1 = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo");
+ TransactionalEditingDomain domain1 = TransactionalEditingDomain.Registry.INSTANCE
+ .getEditingDomain("org.eclipse.emf.transaction.tests.foo");
assertNull(domain1);
-
+
domain1 = new TestEditingDomain.FactoryImpl().createEditingDomain();
assertNotNull(domain1);
- TransactionalEditingDomain.Registry.INSTANCE.add(
- "org.eclipse.emf.transaction.tests.foo",
- domain1);
-
+ TransactionalEditingDomain.Registry.INSTANCE.add("org.eclipse.emf.transaction.tests.foo", domain1);
+
// check that we successfully registered domain1
- assertSame(
- domain1,
- TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo"));
-
+ assertSame(domain1,
+ TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain("org.eclipse.emf.transaction.tests.foo"));
+
// create another domain and register it under the same ID
TransactionalEditingDomain domain2 = new TestEditingDomain.FactoryImpl().createEditingDomain();
- TransactionalEditingDomain.Registry.INSTANCE.add(
- "org.eclipse.emf.transaction.tests.foo",
- domain2);
-
+ TransactionalEditingDomain.Registry.INSTANCE.add("org.eclipse.emf.transaction.tests.foo", domain2);
+
// check that we successfully replaced domain1
- assertSame(
- domain2,
- TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo"));
-
- TransactionalEditingDomain.Registry.INSTANCE.remove("org.eclipse.emf.transaction.tests.foo");
+ assertSame(domain2,
+ TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain("org.eclipse.emf.transaction.tests.foo"));
+
+ TransactionalEditingDomain.Registry.INSTANCE.remove("org.eclipse.emf.transaction.tests.foo");
}
-
+
/**
* Tests the automatic re-registration of a domain when its ID is changed.
*/
@@ -140,77 +127,77 @@ public void test_replaceDomain() {
public void test_changeDomainId() {
TransactionalEditingDomain domain1 = new TestEditingDomain.FactoryImpl().createEditingDomain();
assertNotNull(domain1);
- domain1.setID("org.eclipse.emf.transaction.tests.foo");
-
+ domain1.setID("org.eclipse.emf.transaction.tests.foo");
+
// not yet registered
- assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo"));
- assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.bar"));
-
+ assertNull(
+ TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain("org.eclipse.emf.transaction.tests.foo"));
+ assertNull(
+ TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain("org.eclipse.emf.transaction.tests.bar"));
+
// register it
- TransactionalEditingDomain.Registry.INSTANCE.add(
- "org.eclipse.emf.transaction.tests.foo",
- domain1);
- assertNotNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo"));
- assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.bar"));
-
+ TransactionalEditingDomain.Registry.INSTANCE.add("org.eclipse.emf.transaction.tests.foo", domain1);
+ assertNotNull(
+ TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain("org.eclipse.emf.transaction.tests.foo"));
+ assertNull(
+ TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain("org.eclipse.emf.transaction.tests.bar"));
+
// change the ID
- domain1.setID("org.eclipse.emf.transaction.tests.bar");
-
+ domain1.setID("org.eclipse.emf.transaction.tests.bar");
+
// automatically re-registered
- assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo"));
- assertNotNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.bar"));
-
+ assertNull(
+ TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain("org.eclipse.emf.transaction.tests.foo"));
+ assertNotNull(
+ TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain("org.eclipse.emf.transaction.tests.bar"));
+
// remove
TransactionalEditingDomain.Registry.INSTANCE.remove(domain1.getID());
- assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo"));
- assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.bar"));
-
+ assertNull(
+ TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain("org.eclipse.emf.transaction.tests.foo"));
+ assertNull(
+ TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain("org.eclipse.emf.transaction.tests.bar"));
+
// change the ID back
- domain1.setID("org.eclipse.emf.transaction.tests.foo");
-
+ domain1.setID("org.eclipse.emf.transaction.tests.foo");
+
// didn't re-register itself this time
- assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.bar"));
- assertNull(TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.foo"));
+ assertNull(
+ TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain("org.eclipse.emf.transaction.tests.bar"));
+ assertNull(
+ TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain("org.eclipse.emf.transaction.tests.foo"));
}
-
+
/**
- * Tests the attachment and detachment of registered listeners to editing domains.
+ * Tests the attachment and detachment of registered listeners to editing
+ * domains.
*/
@Test
public void test_listenerRegistration_singleDomain_multipleListeners() {
- TransactionalEditingDomain domain3 = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- TEST_DOMAIN3);
+ TransactionalEditingDomain domain3 = TransactionalEditingDomain.Registry.INSTANCE
+ .getEditingDomain(TEST_DOMAIN3);
assertNull(domain3);
-
+
domain3 = new TestEditingDomain.FactoryImpl().createEditingDomain();
assertNotNull(domain3);
TransactionalEditingDomain.Registry.INSTANCE.add(TEST_DOMAIN3, domain3);
-
+
// look for our two test listeners that are registered on the TestDomain3
assertNotNull(TestListener1.getInstance());
assertNotNull(TestListener2.getInstance());
-
+
final TransactionalEditingDomain finalDomain3 = domain3;
try {
domain3.runExclusive(new Runnable() {
+ @Override
public void run() {
- finalDomain3.getResourceSet().createResource(
- URI.createFileURI("/tmp/dummy.extlibrary"));
- }});
+ finalDomain3.getResourceSet().createResource(URI.createFileURI("/tmp/dummy.extlibrary"));
+ }
+ });
} catch (Exception e) {
fail(e);
}
-
+
// should have gotten events from the read transaction, above
assertNotNull(TestListener1.getInstance().postcommit);
List notifications = TestListener1.getInstance().postcommit.getNotifications();
@@ -220,64 +207,66 @@ public void run() {
assertSame(domain3.getResourceSet(), notification.getNotifier());
assertEquals(ResourceSet.RESOURCE_SET__RESOURCES, notification.getFeatureID(null));
assertEquals(Notification.ADD, notification.getEventType());
-
+
assertNotNull(TestListener2.getInstance().postcommit);
notifications = TestListener2.getInstance().postcommit.getNotifications();
assertFalse(notifications == null);
assertEquals(1, notifications.size());
assertSame(notification, notifications.get(0)); // same notification as other
-
+
TransactionalEditingDomain.Registry.INSTANCE.remove(TEST_DOMAIN3);
-
- Runtime.getRuntime().gc(); // try to collect garbage
+
+ Runtime.getRuntime().gc(); // try to collect garbage
try {
- Thread.sleep(2000); // give garbage collector some time
+ Thread.sleep(2000); // give garbage collector some time
} catch (InterruptedException e) {
// ignore
}
- Runtime.getRuntime().gc(); // try to collect garbage
-
+ Runtime.getRuntime().gc(); // try to collect garbage
+
// our two listeners should have been reclaimed because they are
- // removed from the editing domain
+ // removed from the editing domain
assertNull(TestListener1.getInstance());
assertNull(TestListener2.getInstance());
}
-
+
/**
- * Tests the attachment and detachment of registered listeners to editing domains.
+ * Tests the attachment and detachment of registered listeners to editing
+ * domains.
*/
@Test
public void test_listenerRegistration_multiDomains_singleListener() {
- TransactionalEditingDomain domain3 = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- TEST_DOMAIN3);
+ TransactionalEditingDomain domain3 = TransactionalEditingDomain.Registry.INSTANCE
+ .getEditingDomain(TEST_DOMAIN3);
assertNull(domain3);
-
+
domain3 = new TestEditingDomain.FactoryImpl().createEditingDomain();
assertNotNull(domain3);
TransactionalEditingDomain.Registry.INSTANCE.add(TEST_DOMAIN3, domain3);
-
- TransactionalEditingDomain domain4 = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- TEST_DOMAIN4);
+
+ TransactionalEditingDomain domain4 = TransactionalEditingDomain.Registry.INSTANCE
+ .getEditingDomain(TEST_DOMAIN4);
assertNull(domain4);
-
+
domain4 = new TestEditingDomain.FactoryImpl().createEditingDomain();
assertNotNull(domain4);
TransactionalEditingDomain.Registry.INSTANCE.add(TEST_DOMAIN4, domain4);
-
+
// look for our test listener that is registered on both domains
assertNotNull(TestListener2.getInstance());
-
+
final TransactionalEditingDomain finalDomain3 = domain3;
try {
domain3.runExclusive(new Runnable() {
+ @Override
public void run() {
- finalDomain3.getResourceSet().createResource(
- URI.createFileURI("/tmp/dummy.extlibrary"));
- }});
+ finalDomain3.getResourceSet().createResource(URI.createFileURI("/tmp/dummy.extlibrary"));
+ }
+ });
} catch (Exception e) {
fail(e);
}
-
+
// should have gotten events from the read transaction, above
assertNotNull(TestListener2.getInstance().postcommit);
List notifications = TestListener2.getInstance().postcommitNotifications;
@@ -288,19 +277,20 @@ public void run() {
assertEquals(ResourceSet.RESOURCE_SET__RESOURCES, notification.getFeatureID(null));
assertEquals(Notification.ADD, notification.getEventType());
- TestListener2.getInstance().reset(); // clear the listener for next step
-
+ TestListener2.getInstance().reset(); // clear the listener for next step
+
final TransactionalEditingDomain finalDomain4 = domain4;
try {
domain4.runExclusive(new Runnable() {
+ @Override
public void run() {
- finalDomain4.getResourceSet().createResource(
- URI.createFileURI("/tmp/dummy.extlibrary"));
- }});
+ finalDomain4.getResourceSet().createResource(URI.createFileURI("/tmp/dummy.extlibrary"));
+ }
+ });
} catch (Exception e) {
fail(e);
}
-
+
// should have gotten events from this read transaction, too
assertNotNull(TestListener2.getInstance().postcommit);
notifications = TestListener2.getInstance().postcommitNotifications;
@@ -310,58 +300,60 @@ public void run() {
assertSame(domain4.getResourceSet(), notification.getNotifier());
assertEquals(ResourceSet.RESOURCE_SET__RESOURCES, notification.getFeatureID(null));
assertEquals(Notification.ADD, notification.getEventType());
-
+
TransactionalEditingDomain.Registry.INSTANCE.remove(TEST_DOMAIN3);
TransactionalEditingDomain.Registry.INSTANCE.remove(TEST_DOMAIN4);
-
- Runtime.getRuntime().gc(); // try to collect garbage
+
+ Runtime.getRuntime().gc(); // try to collect garbage
try {
- Thread.sleep(2000); // give garbage collector some time
+ Thread.sleep(2000); // give garbage collector some time
} catch (InterruptedException e) {
// ignore
}
- Runtime.getRuntime().gc(); // try to collect garbage
-
+ Runtime.getRuntime().gc(); // try to collect garbage
+
// our two listener should have been reclaimed because it is
- // removed from both editing domains
+ // removed from both editing domains
assertNull(TestListener2.getInstance());
}
-
+
/**
- * Tests the attachment and detachment of registered listeners to editing domains.
+ * Tests the attachment and detachment of registered listeners to editing
+ * domains.
*/
@Test
public void test_listenerRegistration_universalListener() {
- TransactionalEditingDomain domain3 = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- TEST_DOMAIN3);
+ TransactionalEditingDomain domain3 = TransactionalEditingDomain.Registry.INSTANCE
+ .getEditingDomain(TEST_DOMAIN3);
assertNull(domain3);
-
+
domain3 = new TestEditingDomain.FactoryImpl().createEditingDomain();
assertNotNull(domain3);
TransactionalEditingDomain.Registry.INSTANCE.add(TEST_DOMAIN3, domain3);
-
- TransactionalEditingDomain domain4 = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- TEST_DOMAIN4);
+
+ TransactionalEditingDomain domain4 = TransactionalEditingDomain.Registry.INSTANCE
+ .getEditingDomain(TEST_DOMAIN4);
assertNull(domain4);
-
+
domain4 = new TestEditingDomain.FactoryImpl().createEditingDomain();
assertNotNull(domain4);
TransactionalEditingDomain.Registry.INSTANCE.add(TEST_DOMAIN4, domain4);
-
+
// look for our test listener that is registered on both domains
assertNotNull(TestListener3.getInstance());
-
+
final TransactionalEditingDomain finalDomain3 = domain3;
try {
domain3.runExclusive(new Runnable() {
+ @Override
public void run() {
- finalDomain3.getResourceSet().createResource(
- URI.createFileURI("/tmp/dummy.extlibrary"));
- }});
+ finalDomain3.getResourceSet().createResource(URI.createFileURI("/tmp/dummy.extlibrary"));
+ }
+ });
} catch (Exception e) {
fail(e);
}
-
+
// should have gotten events from the read transaction, above
assertNotNull(TestListener3.getInstance().postcommit);
List notifications = TestListener3.getInstance().postcommitNotifications;
@@ -372,19 +364,20 @@ public void run() {
assertEquals(ResourceSet.RESOURCE_SET__RESOURCES, notification.getFeatureID(null));
assertEquals(Notification.ADD, notification.getEventType());
- TestListener3.getInstance().reset(); // clear the listener for next step
-
+ TestListener3.getInstance().reset(); // clear the listener for next step
+
final TransactionalEditingDomain finalDomain4 = domain4;
try {
domain4.runExclusive(new Runnable() {
+ @Override
public void run() {
- finalDomain4.getResourceSet().createResource(
- URI.createFileURI("/tmp/dummy.extlibrary"));
- }});
+ finalDomain4.getResourceSet().createResource(URI.createFileURI("/tmp/dummy.extlibrary"));
+ }
+ });
} catch (Exception e) {
fail(e);
}
-
+
// should have gotten events from this read transaction, too
assertNotNull(TestListener3.getInstance().postcommit);
notifications = TestListener3.getInstance().postcommitNotifications;
@@ -394,69 +387,67 @@ public void run() {
assertSame(domain4.getResourceSet(), notification.getNotifier());
assertEquals(ResourceSet.RESOURCE_SET__RESOURCES, notification.getFeatureID(null));
assertEquals(Notification.ADD, notification.getEventType());
-
+
TransactionalEditingDomain.Registry.INSTANCE.remove(TEST_DOMAIN3);
TransactionalEditingDomain.Registry.INSTANCE.remove(TEST_DOMAIN4);
-
+
// can't test for clean removal because it is also on TestDomain1 (being
- // a universal listener) and TestDomain1 cannot be removed. It's not
- // necessary to test this again, though, anyway
+ // a universal listener) and TestDomain1 cannot be removed. It's not
+ // necessary to test this again, though, anyway
}
-
+
/**
- * Tests that we can omit the factory class in the editing domain
- * registration to use the default shared factory instance.
+ * Tests that we can omit the factory class in the editing domain registration
+ * to use the default shared factory instance.
*/
@Test
public void test_registerDefaultFactory_136674() {
- TransactionalEditingDomain defaultDomain =
- TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(
- "org.eclipse.emf.transaction.tests.TestDefaultFactoryDomain1");
+ TransactionalEditingDomain defaultDomain = TransactionalEditingDomain.Registry.INSTANCE
+ .getEditingDomain("org.eclipse.emf.transaction.tests.TestDefaultFactoryDomain1");
assertNotNull(defaultDomain);
}
-
+
//
// Fixtures
//
-
+
/** Test listener registered against TestDomain3. */
public static class TestListener1 extends TestListener {
private static WeakReference instance;
-
+
public TestListener1() {
- instance = new WeakReference(this);
+ instance = new WeakReference<>(this);
}
-
+
public static TestListener1 getInstance() {
return instance == null ? null : instance.get();
}
}
-
+
/** Test listener registered against TestDomain3. */
public static class TestListener2 extends TestListener {
private static WeakReference instance;
-
+
public TestListener2() {
- instance = new WeakReference(this);
+ instance = new WeakReference<>(this);
}
-
+
public static TestListener2 getInstance() {
return instance == null ? null : instance.get();
}
}
-
+
/** Test listener registered against all domains. */
public static class TestListener3 extends TestListener {
private static WeakReference instance;
-
+
public TestListener3() {
- instance = new WeakReference(this);
+ instance = new WeakReference<>(this);
}
-
+
public static TestListener3 getInstance() {
return instance == null ? null : instance.get();
}
}
-
-}
+}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainTest.java
index 637c0525..c8d74f1b 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainTest.java
@@ -11,13 +11,14 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+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.io.ByteArrayInputStream;
import java.io.File;
+import java.io.IOException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -29,10 +30,8 @@
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.junit.Assert;
-import org.junit.Test;
-
-import junit.framework.AssertionFailedError;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests some basic editing domain life-cycle API.
@@ -66,7 +65,7 @@ public void test_factoryUnmapResourceSet_161168() {
// TODO: Why does this not work in the build but it does in the dev environment?
// runGC();
-//
+//
// // verify that the domain was reclaimed
// assertSame(ref, q.poll());
}
@@ -80,6 +79,7 @@ public void ignore_test_readOnlyResourceMap_workspace_bug156428() {
final IProject proj = ws.getRoot().getProject("read_only_test");
addTearDownAction(new Runnable() {
+ @Override
public void run() {
delete(proj);
}
@@ -89,7 +89,7 @@ public void run() {
proj.create(null);
proj.open(null);
} catch (Exception e) {
- Assert.fail("Failed to create project: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to create project: " + e.getLocalizedMessage());
}
IFile file = proj.getFile("testResource.xmi");
@@ -104,7 +104,7 @@ public void run() {
try {
file.create(new ByteArrayInputStream(new byte[0]), false, null);
} catch (Exception e) {
- Assert.fail("Failed to create file: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to create file: " + e.getLocalizedMessage());
}
// a resource that does exist and is writable should be writable
@@ -119,7 +119,7 @@ public void run() {
try {
file.setResourceAttributes(attribs);
} catch (Exception e) {
- Assert.fail("Failed to set file read-only: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to set file read-only: " + e.getLocalizedMessage());
}
// a resource that does exist and is not writable should be read-only
@@ -138,35 +138,27 @@ public void test_readOnlyResourceMap_filesystem_bug156428() {
try {
file = File.createTempFile("testReadOnly", ".xmi");
- } catch (Exception e) {
- Assert.fail("Failed to create temporary file: " + e.getLocalizedMessage());
-
- // compiler doesn't know that fail() throws
- throw new AssertionFailedError();
- }
-
- addTearDownAction(new Runnable() {
- public void run() {
- delete(file);
- }
- });
+ addTearDownAction(() -> delete(file));
- // a resource that doesn't exist should be writable
- Resource res = domain.getResourceSet().createResource(URI.createFileURI(file.getAbsolutePath() + "2"));
- assertFalse(domain.isReadOnly(res));
+ // a resource that doesn't exist should be writable
+ Resource res = domain.getResourceSet().createResource(URI.createFileURI(file.getAbsolutePath() + "2"));
+ assertFalse(domain.isReadOnly(res));
- domain.getResourceSet().getResources().remove(res);
+ domain.getResourceSet().getResources().remove(res);
- // a resource that does exist and is writable should be writable
- res = domain.getResourceSet().createResource(URI.createFileURI(file.getAbsolutePath()));
- assertFalse(domain.isReadOnly(res));
+ // a resource that does exist and is writable should be writable
+ res = domain.getResourceSet().createResource(URI.createFileURI(file.getAbsolutePath()));
+ assertFalse(domain.isReadOnly(res));
- domain.getResourceSet().getResources().remove(res);
+ domain.getResourceSet().getResources().remove(res);
- file.setReadOnly();
+ file.setReadOnly();
- // a resource that does exist and is not writable should be read-only
- res = domain.getResourceSet().createResource(URI.createFileURI(file.getAbsolutePath()));
- assertTrue(domain.isReadOnly(res));
+ // a resource that does exist and is not writable should be read-only
+ res = domain.getResourceSet().createResource(URI.createFileURI(file.getAbsolutePath()));
+ assertTrue(domain.isReadOnly(res));
+ } catch (IOException e) {
+ Assertions.fail("Failed to create temporary file: " + e.getLocalizedMessage());
+ }
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainValidatorTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainValidatorTest.java
index 6cce2f35..a98a247f 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainValidatorTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/EditingDomainValidatorTest.java
@@ -11,13 +11,13 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.examples.extlibrary.Book;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.tests.fixtures.TestValidationEditingDomain;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests validator creation during transaction editing domain commit
@@ -26,33 +26,33 @@
*/
public class EditingDomainValidatorTest extends AbstractTest {
- private static final String TEST_DOMAIN1 = "org.eclipse.emf.transaction.tests.TestValidationDomain1";
-
+ private static final String TEST_DOMAIN1 = "org.eclipse.emf.transaction.tests.TestValidationDomain1";
+
private static final TransactionalEditingDomain myDomain = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(TEST_DOMAIN1);
-
-
+
+
/** May be overridden by subclasses to create non-default editing domains. */
@Override
protected TransactionalEditingDomain createEditingDomain(ResourceSet rset) {
return myDomain;
}
-
+
@Override
protected ResourceSet createResourceSet() {
return myDomain.getResourceSet();
}
-
+
/**
* Tests overriding of validators in editing domain
*/
@Test
- public void test_createValidators_177643() {
+ public void test_createValidators_177643() {
TestValidationEditingDomain.enableCustomValidator.set(true);
int initialCount = TestValidationEditingDomain.readWriteValidatorHitCount.get();
-
+
startWriting();
- Book book = (Book) find("root/Root Book");
- book.setTitle("New Title");
+ Book book = (Book) find("root/Root Book");
+ book.setTitle("New Title");
commit();
assertEquals(initialCount + 1, TestValidationEditingDomain.readWriteValidatorHitCount.get());
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/JobManagerSuspensionDeadlockTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/JobManagerSuspensionDeadlockTest.java
index 18134a29..42f0578e 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/JobManagerSuspensionDeadlockTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/JobManagerSuspensionDeadlockTest.java
@@ -5,21 +5,21 @@
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* Innovations Softwaretechnologie - Initial API and implementation
* Zeligsoft - Bug 248717 (ensure that a failure does not hang the suite)
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests that transactions do not dead-lock when the Eclipse Job Manager is
@@ -31,7 +31,7 @@ public class JobManagerSuspensionDeadlockTest {
@Test
public void testDeadlock()
throws Exception {
-
+
final TransactionalEditingDomain domain = new TransactionalEditingDomainImpl(
new ReflectiveItemProviderAdapterFactory());
@@ -52,6 +52,7 @@ public void run() {
System.out.println("Thread-1: Invoke runExclusive");
domain.runExclusive(new Runnable() {
+ @Override
public void run() {
System.out
.println("Thread-1: Do something Do something in exclusive mode");
@@ -75,6 +76,7 @@ public void run() {
System.out.println("Thread-2: Invoke runExclusive");
domain.runExclusive(new Runnable() {
+ @Override
public void run() {
// Notify thread 1
synchronized (lock) {
@@ -102,22 +104,22 @@ public void run() {
// org.eclipse.ui.internal.ide.applicationIDEWorkbenchAdvisor.preStartup()
// until workbench startup
Job.getJobManager().suspend();
-
+
// Start Thread-1 and make sure that it is alive
t1.start();
t1.join(250);
-
+
// Thread-1 should be alive now...
assertTrue(t1.isAlive());
-
+
t2.start();
t2.join(5000L);
-
+
// Thread-2 should have finished now
assertFalse(t2.isAlive());
-
+
t1.join(5000L);
-
+
// Thread-1 should have finished now
assertFalse(t1.isAlive());
} finally {
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/LifecycleListenersTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/LifecycleListenersTest.java
index d8f319d2..b11ff926 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/LifecycleListenersTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/LifecycleListenersTest.java
@@ -5,17 +5,17 @@
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* Zeligsoft - Initial API and implementation
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+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.assertTrue;
import java.util.Arrays;
import java.util.List;
@@ -25,11 +25,11 @@
import org.eclipse.emf.transaction.TransactionalEditingDomainEvent;
import org.eclipse.emf.transaction.TransactionalEditingDomainListener;
import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the dispatching of life-cycle events to listeners.
- *
+ *
* @author Christian W. Damus (cdamus)
*/
public class LifecycleListenersTest extends AbstractTest {
@@ -61,7 +61,7 @@ public void test_eventSequence_commit() {
// the original root transaction is closed after post-commit
TransactionalEditingDomainEvent.TRANSACTION_CLOSED);
- assertEquals("Wrong event sequence", expected, listener.eventTypesReceived);
+ assertEquals(expected, listener.eventTypesReceived, "Wrong event sequence");
}
/**
@@ -91,7 +91,7 @@ public void test_eventSequence_rollback() {
// transaction for post-commit
TransactionalEditingDomainEvent.TRANSACTION_CLOSED);
- assertEquals("Wrong event sequence", expected, listener.eventTypesReceived);
+ assertEquals(expected, listener.eventTypesReceived, "Wrong event sequence");
}
//
@@ -116,37 +116,43 @@ protected void doTearDown() throws Exception {
private class LifecycleListener implements TransactionalEditingDomainListener {
- List eventTypesReceived = new java.util.ArrayList();
+ List eventTypesReceived = new java.util.ArrayList<>();
+ @Override
public void editingDomainDisposing(TransactionalEditingDomainEvent event) {
assertNull(event.getTransaction());
eventTypesReceived.add(event.getEventType());
}
+ @Override
public void transactionClosed(TransactionalEditingDomainEvent event) {
assertNotNull(event.getTransaction());
assertFalse(event.getTransaction().isActive());
eventTypesReceived.add(event.getEventType());
}
+ @Override
public void transactionClosing(TransactionalEditingDomainEvent event) {
assertNotNull(event.getTransaction());
assertTrue(event.getTransaction().isActive());
eventTypesReceived.add(event.getEventType());
}
+ @Override
public void transactionInterrupted(TransactionalEditingDomainEvent event) {
assertNotNull(event.getTransaction());
assertFalse(event.getTransaction().isActive());
eventTypesReceived.add(event.getEventType());
}
+ @Override
public void transactionStarted(TransactionalEditingDomainEvent event) {
assertNotNull(event.getTransaction());
assertTrue(event.getTransaction().isActive());
eventTypesReceived.add(event.getEventType());
}
+ @Override
public void transactionStarting(TransactionalEditingDomainEvent event) {
assertNotNull(event.getTransaction());
assertFalse(event.getTransaction().isActive());
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/MemoryLeakTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/MemoryLeakTest.java
index deae6ed9..919b3899 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/MemoryLeakTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/MemoryLeakTest.java
@@ -11,10 +11,10 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
@@ -44,8 +44,8 @@
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.TriggerListener;
import org.eclipse.emf.transaction.util.CompositeChangeDescription;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests to check for memory leaks.
@@ -59,12 +59,12 @@ public class MemoryLeakTest extends AbstractTest {
*/
@Test
public void test_unloadResource() {
- ReferenceQueue q = new ReferenceQueue();
- Reference ref = new WeakReference(root, q);
+ ReferenceQueue q = new ReferenceQueue<>();
+ Reference ref = new WeakReference<>(root, q);
// make some change, causing a transaction to record a change description
startWriting();
- root.setName("foo"); //$NON-NLS-1$
+ root.setName("foo");
commit();
startReading();
@@ -88,12 +88,12 @@ public void test_unloadResource() {
*/
@Test
public void test_reclaimEditingDomain() {
- ReferenceQueue q = new ReferenceQueue();
- Reference ref = new WeakReference(domain, q);
+ ReferenceQueue q = new ReferenceQueue<>();
+ Reference ref = new WeakReference<>(domain, q);
// make some change, causing a transaction to record a change description
startWriting();
- root.setName("foo"); //$NON-NLS-1$
+ root.setName("foo");
commit();
domain = null; // forget the domain
@@ -125,7 +125,7 @@ public void test_nonRecordingChildTransactions_153908() {
final String oldName = root.getName();
// make a change in the root-level transaction
- root.setName("foo"); //$NON-NLS-1$
+ root.setName("foo");
// now, create 1000 nested transactions, each doing a change, *but* unrecorded
Map options = Collections.singletonMap(Transaction.OPTION_UNPROTECTED,
@@ -134,18 +134,18 @@ public void test_nonRecordingChildTransactions_153908() {
for (int i = 0; i < 1000; i++) {
startWriting(options);
- root.setName("foo" + i); //$NON-NLS-1$
+ root.setName("foo" + i);
commit();
// make another change in the root-level transaction
- root.setName("foo" + (i + 1000)); //$NON-NLS-1$
+ root.setName("foo" + (i + 1000));
}
// report the used heap
long currentUsedHeap = usedHeap();
- System.out.println("Additional heap used by the transaction: " //$NON-NLS-1$
- + ((currentUsedHeap - initialUsedHeap) / 1024L) + " kB"); //$NON-NLS-1$
+ System.out.println(
+ "Additional heap used by the transaction: " + ((currentUsedHeap - initialUsedHeap) / 1024L) + " kB");
Transaction tx = commit();
CompositeChangeDescription change = (CompositeChangeDescription) tx.getChangeDescription();
@@ -190,7 +190,7 @@ public void test_crossReferenceAdapter_undoredo_normalCommands() {
// and a transaction-sniffer to the domain
TransactionSniffer sniffer = new TransactionSniffer(domain);
- EObject level1 = find(root, "level1"); //$NON-NLS-1$
+ EObject level1 = find(root, "level1");
assertTrue(level1.eAdapters().contains(xrefAdapter));
@@ -249,11 +249,11 @@ public void test_crossReferenceAdapter_undoredo_recordingCommands() {
// and a transaction-sniffer to the domain
TransactionSniffer sniffer = new TransactionSniffer(domain);
- final EObject level1 = find(root, "level1"); //$NON-NLS-1$
+ final EObject level1 = find(root, "level1");
assertTrue(level1.eAdapters().contains(xrefAdapter));
- Command cmd = new RecordingCommand(domain, "Remove Branch") { //$NON-NLS-1$
+ Command cmd = new RecordingCommand(domain, "Remove Branch") {
@Override
protected void doExecute() {
root.getBranches().remove(level1);
@@ -301,7 +301,7 @@ public void test_crossReferenceAdapter_undoredo_normalTriggerCommands() {
// and a transaction-sniffer to the domain
TransactionSniffer sniffer = new TransactionSniffer(domain);
- EObject level1 = find(root, "level1"); //$NON-NLS-1$
+ EObject level1 = find(root, "level1");
assertTrue(level1.eAdapters().contains(xrefAdapter));
@@ -336,7 +336,7 @@ protected Command trigger(TransactionalEditingDomain domain, Notification notifi
});
Command cmd = domain.createCommand(SetCommand.class,
- new CommandParameter(root, EXTLibraryPackage.Literals.LIBRARY__NAME, "newname")); //$NON-NLS-1$
+ new CommandParameter(root, EXTLibraryPackage.Literals.LIBRARY__NAME, "newname"));
getCommandStack().execute(cmd);
@@ -376,11 +376,11 @@ public void test_crossReferenceAdapter_undoredo_recordingTriggerCommands() {
// and a transaction-sniffer to the domain
TransactionSniffer sniffer = new TransactionSniffer(domain);
- final EObject level1 = find(root, "level1"); //$NON-NLS-1$
+ final EObject level1 = find(root, "level1");
assertTrue(level1.eAdapters().contains(xrefAdapter));
- final Command trigger = new RecordingCommand(domain, "Remove Branch") { //$NON-NLS-1$
+ final Command trigger = new RecordingCommand(domain, "Remove Branch") {
@Override
protected void doExecute() {
root.getBranches().remove(level1);
@@ -400,7 +400,7 @@ protected Command trigger(TransactionalEditingDomain domain, Notification notifi
});
Command cmd = domain.createCommand(SetCommand.class,
- new CommandParameter(root, EXTLibraryPackage.Literals.LIBRARY__NAME, "newname")); //$NON-NLS-1$
+ new CommandParameter(root, EXTLibraryPackage.Literals.LIBRARY__NAME, "newname"));
getCommandStack().execute(cmd);
@@ -434,7 +434,7 @@ protected long usedHeap() {
long result = rt.totalMemory() - rt.freeMemory();
- System.out.println("Used Heap: " + (result / 1024L) + " kB"); //$NON-NLS-1$ //$NON-NLS-2$
+ System.out.println("Used Heap: " + (result / 1024L) + " kB");
return result;
}
@@ -444,13 +444,13 @@ static List getChildren(CompositeChangeDescription compositeC
List result = null;
try {
- Field children = compositeChange.getClass().getDeclaredField("changes"); //$NON-NLS-1$
+ Field children = compositeChange.getClass().getDeclaredField("changes");
children.setAccessible(true);
result = (List) children.get(compositeChange);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail(e.getLocalizedMessage());
+ Assertions.fail(e.getLocalizedMessage());
}
return result;
@@ -458,7 +458,7 @@ static List getChildren(CompositeChangeDescription compositeC
private static class TransactionSniffer extends ResourceSetListenerImpl {
private final TransactionalEditingDomain domain;
- private final List changes = new BasicEList.FastCompare();
+ private final List changes = new BasicEList.FastCompare<>();
TransactionSniffer(TransactionalEditingDomain domain) {
this.domain = domain;
@@ -485,7 +485,7 @@ void assertChangesDisposed() {
for (Iterator iter = EcoreUtil.getAllContents(changes); iter.hasNext();) {
EObject next = iter.next();
- assertEquals("Adapters not cleared.", 0, next.eAdapters().size()); //$NON-NLS-1$
+ assertEquals(0, next.eAdapters().size(), "Adapters not cleared.");
}
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/NotificationFilterTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/NotificationFilterTest.java
index b273ecd7..73a82d55 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/NotificationFilterTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/NotificationFilterTest.java
@@ -11,10 +11,10 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+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 org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.examples.extlibrary.Book;
@@ -22,7 +22,7 @@
import org.eclipse.emf.examples.extlibrary.Writer;
import org.eclipse.emf.transaction.NotificationFilter;
import org.eclipse.emf.transaction.tests.fixtures.TestListener;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests notification filtering.
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/PerformanceTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/PerformanceTest.java
index 91e40921..49dc85a1 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/PerformanceTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/PerformanceTest.java
@@ -11,8 +11,8 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.IOException;
import java.util.Collections;
@@ -36,8 +36,8 @@
import org.eclipse.emf.transaction.Transaction;
import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
import org.eclipse.emf.transaction.tests.fixtures.TestCommand;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Regression tests for performance problems (time and memory).
@@ -103,6 +103,7 @@ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws Rol
precommitEvents[0]++;
result.append(new TestCommand() {
+ @Override
public void execute() {
/* nothing to do */}
});
@@ -126,7 +127,7 @@ public void resourceSetChanged(ResourceSetChangeEvent event) {
domain.addResourceSetListener(listener);
- Map options = new java.util.HashMap();
+ Map options = new java.util.HashMap<>();
// options.put(Transaction.OPTION_NO_NOTIFICATIONS, Boolean.TRUE);
// options.put(Transaction.OPTION_NO_TRIGGERS, Boolean.TRUE);
// options.put(Transaction.OPTION_NO_VALIDATION, Boolean.TRUE);
@@ -162,7 +163,7 @@ public void resourceSetChanged(ResourceSetChangeEvent event) {
System.out.println("Number of post-commit events: " + postcommitEvents[0]);
} catch (IOException e) {
e.printStackTrace();
- Assert.fail("Failed to load test resource: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to load test resource: " + e.getLocalizedMessage());
} finally {
domain.removeResourceSetListener(listener);
}
@@ -255,12 +256,12 @@ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws Rol
System.out.println("Number of post-commit notifications sent: " + receivedPostcommitNotifications[0]);
System.out.println("Number of validation notifications sent: " + receivedValidationNotifications[0]);
- assertEquals("Wrong number of pre-commit notifications", expectedPrecommitNotifications[0],
- receivedPrecommitNotifications[0]);
- assertEquals("Wrong number of post-commit notifications", expectedPostcommitNotifications[0],
- receivedPostcommitNotifications[0]);
- assertEquals("Wrong number of validation notifications", expectedValidationNotifications[0],
- receivedValidationNotifications[0]);
+ assertEquals(expectedPrecommitNotifications[0], receivedPrecommitNotifications[0],
+ "Wrong number of pre-commit notifications");
+ assertEquals(expectedPostcommitNotifications[0], receivedPostcommitNotifications[0],
+ "Wrong number of post-commit notifications");
+ assertEquals(expectedValidationNotifications[0], receivedValidationNotifications[0],
+ "Wrong number of validation notifications");
} finally {
domain.removeResourceSetListener(validationCollector);
domain.removeResourceSetListener(prePostCommitCollector);
@@ -278,7 +279,7 @@ protected void doSetUp() throws Exception {
System.out.println("Performance test: " + this.getClass().getName());
System.out.println("===============================");
- timings = new java.util.ArrayList();
+ timings = new java.util.ArrayList<>();
}
@Override
@@ -336,7 +337,7 @@ protected void addStuffToTestResourceAndClose() {
testResource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
- Assert.fail("Failed to save test resource: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to save test resource: " + e.getLocalizedMessage());
}
testResource.unload();
@@ -444,9 +445,9 @@ private void pokeRoot() {
static {
allNotifications = Collections.emptyMap();
noTriggers = Collections.singletonMap(Transaction.OPTION_NO_TRIGGERS, Boolean.TRUE);
- validationOnly = new java.util.HashMap(noTriggers);
+ validationOnly = new java.util.HashMap<>(noTriggers);
validationOnly.put(Transaction.OPTION_NO_NOTIFICATIONS, Boolean.TRUE);
- noNotifications = new java.util.HashMap(validationOnly);
+ noNotifications = new java.util.HashMap<>(validationOnly);
noNotifications.put(Transaction.OPTION_NO_VALIDATION, Boolean.TRUE);
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/PrivilegedRunnableTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/PrivilegedRunnableTest.java
index bd97d80f..cf1ee4e6 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/PrivilegedRunnableTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/PrivilegedRunnableTest.java
@@ -11,12 +11,12 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+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 java.util.List;
@@ -24,8 +24,8 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.examples.extlibrary.Book;
import org.eclipse.emf.transaction.RunnableWithResult;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests the sharing of transactions between cooperating threads using
@@ -137,6 +137,7 @@ public void test_nestedSharing() {
Runnable nestingRunnable = new Runnable() {
+ @Override
public void run() {
thread2.syncExec(domain.createPrivilegedRunnable(write));
}
@@ -173,7 +174,7 @@ public void test_transactionMustBeActive() {
thread.syncExec(privileged);
Exception e = thread.getException();
- assertNotNull("Should have thrown IllegalStateException", e);
+ assertNotNull(e, "Should have thrown IllegalStateException");
System.out.println("Got expected exception: " + e.getLocalizedMessage());
}
@@ -193,7 +194,7 @@ public void test_transactionMustBeCurrent() {
thread.syncExec(privileged);
Exception e = thread.getException();
- assertNotNull("Should have thrown IllegalStateException", e);
+ assertNotNull(e, "Should have thrown IllegalStateException");
System.out.println("Got expected exception: " + e.getLocalizedMessage());
commit();
@@ -215,6 +216,7 @@ public void test_runtimeExceptionInRunnable_146625() {
startReading();
privileged = domain.createPrivilegedRunnable(new Runnable() {
+ @Override
public void run() {
// throw the run-time exception
throw e;
@@ -239,12 +241,13 @@ public void test_concurrentAcquireDuringPrivilegedRunnable_162027() throws Excep
startReading();
Thread otherThread = new Thread(new Runnable() {
+ @Override
public void run() {
synchronized (handshake) {
try {
handshake.wait();
} catch (InterruptedException e) {
- Assert.fail("Interrupted");
+ Assertions.fail("Interrupted");
}
handshake.notifyAll();
@@ -252,16 +255,17 @@ public void run() {
try {
domain.runExclusive(new Runnable() {
+ @Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
- Assert.fail("Interrupted");
+ Assertions.fail("Interrupted");
}
}
});
} catch (InterruptedException e) {
- Assert.fail("Interrupted");
+ Assertions.fail("Interrupted");
} catch (IllegalArgumentException e) {
// this is the symptom of the bug
shouldNotBeThrown[0] = e;
@@ -274,6 +278,7 @@ public void run() {
Thread.sleep(500);
Runnable privileged = domain.createPrivilegedRunnable(new Runnable() {
+ @Override
public void run() {
synchronized (handshake) {
handshake.notifyAll();
@@ -283,7 +288,7 @@ public void run() {
Thread.sleep(500);
} catch (InterruptedException e) {
- Assert.fail("Interrupted");
+ Assertions.fail("Interrupted");
}
}
}
@@ -353,7 +358,7 @@ public void syncExec(Runnable runnable) {
try {
wait();
} catch (InterruptedException e) {
- Assert.fail("Interrupted while waiting for runnable");
+ Assertions.fail("Interrupted while waiting for runnable");
}
}
}
@@ -401,6 +406,7 @@ private void execute(Runnable runnable) {
class TestRead implements Runnable {
boolean wasExecuted = false;
+ @Override
public void run() {
root.getBooks();
wasExecuted = true;
@@ -410,6 +416,7 @@ public void run() {
class TestReadWithResult extends RunnableWithResult.Impl> {
boolean wasExecuted = false;
+ @Override
public void run() {
setResult(root.getBooks());
setStatus(TEST_STATUS);
@@ -420,6 +427,7 @@ public void run() {
class TestWrite implements Runnable {
boolean wasExecuted = false;
+ @Override
public void run() {
root.getBooks().clear();
wasExecuted = true;
@@ -429,6 +437,7 @@ public void run() {
class TestWriteWithResult extends RunnableWithResult.Impl> {
boolean wasExecuted = false;
+ @Override
public void run() {
root.getBooks().clear();
setResult(root.getBooks());
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/RecordingCommandTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/RecordingCommandTest.java
index 4916938e..71f67ada 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/RecordingCommandTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/RecordingCommandTest.java
@@ -7,20 +7,20 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
- * SAP AG - initial API and implementation
+ * SAP AG - initial API and implementation
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for the recording command.
- *
+ *
* @author Boris Gruschko
*
*/
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ResourceSetListenersTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ResourceSetListenersTest.java
index f94d861d..05dd11e5 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ResourceSetListenersTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ResourceSetListenersTest.java
@@ -13,12 +13,12 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+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 java.util.List;
@@ -44,9 +44,8 @@
import org.eclipse.emf.transaction.tests.fixtures.LibraryDefaultNameTrigger;
import org.eclipse.emf.transaction.tests.fixtures.TestCommand;
import org.eclipse.emf.transaction.tests.fixtures.TestListener;
-import org.junit.Assert;
-import org.junit.Test;
-
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests resource listener events.
@@ -54,9 +53,8 @@
* @author Christian W. Damus (cdamus)
*/
public class ResourceSetListenersTest extends AbstractTest {
-
- private TestListener listener;
+ private TestListener listener;
/**
* Tests that simple changes are propagated to post-commit listeners.
@@ -64,26 +62,25 @@ public class ResourceSetListenersTest extends AbstractTest {
@Test
public void test_postcommit() {
try {
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
-
- String newTitle = "New Title"; //$NON-NLS-1$
-
- Command cmd = new SetCommand(
- domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle);
-
+
+ String newTitle = "New Title";
+
+ Command cmd = new SetCommand(domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle);
+
domain.getCommandStack().execute(cmd);
-
+
assertNotNull(listener.postcommit);
assertNotNull(listener.postcommit.getTransaction());
assertFalse(listener.postcommit.getTransaction().isActive());
assertSame(domain, listener.postcommit.getEditingDomain());
-
+
List notifications = listener.postcommitNotifications;
assertNotNull(notifications);
assertEquals(1, notifications.size());
-
+
Notification notification = notifications.get(0);
assertSame(book, notification.getNotifier());
assertSame(EXTLibraryPackage.eINSTANCE.getBook_Title(), notification.getFeature());
@@ -101,45 +98,46 @@ public void test_postcommit() {
public void test_postcommit_nestedChange() {
try {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
-
+
+ final Book book = (Book) find("root/Root Book");
+
commit();
-
+
assertNotNull(book);
-
- final String newTitle = "New Title"; //$NON-NLS-1$
-
+
+ final String newTitle = "New Title";
+
Command cmd = new TestCommand() {
-
+
+ @Override
public void execute() {
try {
// nested transaction
startWriting();
-
+
book.setTitle(newTitle);
-
+
commit();
-
+
assertNull(listener.postcommit);
} catch (Exception e) {
fail(e);
}
}
-
+
};
-
+
domain.getCommandStack().execute(cmd);
-
+
assertNotNull(listener.postcommit);
assertNotNull(listener.postcommit.getTransaction());
assertFalse(listener.postcommit.getTransaction().isActive());
assertSame(domain, listener.postcommit.getEditingDomain());
-
+
List notifications = listener.postcommitNotifications;
assertNotNull(notifications);
assertEquals(1, notifications.size());
-
+
Notification notification = notifications.get(0);
assertSame(book, notification.getNotifier());
assertSame(EXTLibraryPackage.eINSTANCE.getBook_Title(), notification.getFeature());
@@ -157,56 +155,57 @@ public void execute() {
public void test_postcommit_ordering() {
try {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
-
+
commit();
-
- final String newTitle = "New Title"; //$NON-NLS-1$
-
+
+ final String newTitle = "New Title";
+
Command cmd = new TestCommand() {
-
+
+ @Override
public void execute() {
try {
book.setCategory(BookCategory.BIOGRAPHY_LITERAL);
-
+
// nested transaction
startWriting();
-
+
book.setTitle(newTitle);
-
+
commit();
-
+
book.setPages(500);
} catch (Exception e) {
fail(e);
}
}
-
+
};
-
+
domain.getCommandStack().execute(cmd);
-
+
assertNotNull(listener.postcommit);
assertNotNull(listener.postcommit.getTransaction());
assertFalse(listener.postcommit.getTransaction().isActive());
assertSame(domain, listener.postcommit.getEditingDomain());
-
+
List notifications = listener.postcommitNotifications;
assertNotNull(notifications);
assertEquals(3, notifications.size());
-
+
Notification notification = notifications.get(0);
assertSame(book, notification.getNotifier());
assertSame(EXTLibraryPackage.eINSTANCE.getBook_Category(), notification.getFeature());
assertSame(BookCategory.BIOGRAPHY_LITERAL, notification.getNewValue());
-
+
notification = notifications.get(1);
assertSame(book, notification.getNotifier());
assertSame(EXTLibraryPackage.eINSTANCE.getBook_Title(), notification.getFeature());
assertSame(newTitle, notification.getNewValue());
-
+
notification = notifications.get(2);
assertSame(book, notification.getNotifier());
assertSame(EXTLibraryPackage.eINSTANCE.getBook_Pages(), notification.getFeature());
@@ -222,63 +221,67 @@ public void execute() {
@Test
public void test_postcommit_readOnly() {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
-
+
commit();
-
+
TestListener testListener = new TestListener() {
@Override
public void resourceSetChanged(ResourceSetChangeEvent event) {
try {
// can execute read operations
domain.runExclusive(new Runnable() {
+ @Override
public void run() {
// do nothing
- }});
+ }
+ });
} catch (Exception e) {
fail(e);
}
-
+
try {
// cannot execute commands
domain.getCommandStack().execute(new TestCommand() {
+ @Override
public void execute() {
// do nothing
- }});
-
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ }
+ });
+
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (Exception e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
}
-
+
try {
// cannot make ad hoc changes
book.setCategory(BookCategory.BIOGRAPHY_LITERAL);
-
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (Exception e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
}
- }};
-
+ }
+ };
+
try {
domain.addResourceSetListener(testListener);
-
- String newTitle = "New Title"; //$NON-NLS-1$
-
- Command cmd = new SetCommand(
- domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle);
-
+
+ String newTitle = "New Title";
+
+ Command cmd = new SetCommand(domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle);
+
domain.getCommandStack().execute(cmd);
} catch (Exception e) {
fail(e);
} finally {
// must remove the listener, otherwise it will be invoked again
- // by the resource unload and it will fail at that time
+ // by the resource unload and it will fail at that time
domain.removeResourceSetListener(testListener);
}
}
@@ -290,28 +293,27 @@ public void execute() {
public void test_precommit() {
try {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
-
+
commit();
-
- String newTitle = "New Title"; //$NON-NLS-1$
-
- Command cmd = new SetCommand(
- domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle);
-
+
+ String newTitle = "New Title";
+
+ Command cmd = new SetCommand(domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle);
+
domain.getCommandStack().execute(cmd);
-
+
assertNotNull(listener.precommit);
assertNotNull(listener.precommit.getTransaction());
assertFalse(listener.precommit.getTransaction().isActive());
assertSame(domain, listener.precommit.getEditingDomain());
-
+
List notifications = listener.precommitNotifications;
assertNotNull(notifications);
assertEquals(1, notifications.size());
-
+
Notification notification = notifications.get(0);
assertSame(book, notification.getNotifier());
assertSame(EXTLibraryPackage.eINSTANCE.getBook_Title(), notification.getFeature());
@@ -329,36 +331,37 @@ public void test_precommit() {
public void test_precommit_nestedChange() {
try {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
-
+
commit();
-
- final String newTitle = "New Title"; //$NON-NLS-1$
-
+
+ final String newTitle = "New Title";
+
Command cmd = new TestCommand() {
-
+
+ @Override
public void execute() {
try {
// nested transaction
startWriting();
-
+
book.setTitle(newTitle);
-
+
commit();
-
+
// reset the listener to the outer commit
listener.reset();
} catch (Exception e) {
fail(e);
}
}
-
+
};
-
+
domain.getCommandStack().execute(cmd);
-
+
assertNull(listener.precommit);
} catch (Exception e) {
fail(e);
@@ -373,61 +376,62 @@ public void execute() {
public void test_precommit_nestedChange2() {
try {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
-
+
commit();
-
- final String newTitle = "New Title"; //$NON-NLS-1$
-
+
+ final String newTitle = "New Title";
+
Command cmd = new TestCommand() {
-
+
+ @Override
public void execute() {
try {
book.setCategory(BookCategory.BIOGRAPHY_LITERAL);
-
+
// nested transaction
startWriting();
-
+
book.setTitle(newTitle);
-
+
commit();
-
+
assertNotNull(listener.precommit);
assertNotNull(listener.precommit.getTransaction());
assertFalse(listener.precommit.getTransaction().isActive());
assertSame(domain, listener.precommit.getEditingDomain());
-
+
List notifications = listener.precommitNotifications;
assertNotNull(notifications);
assertEquals(1, notifications.size());
-
+
Notification notification = notifications.get(0);
assertSame(book, notification.getNotifier());
assertSame(EXTLibraryPackage.eINSTANCE.getBook_Title(), notification.getFeature());
assertSame(newTitle, notification.getNewValue());
-
+
// reset the listener to the outer commit
listener.reset();
} catch (Exception e) {
fail(e);
}
}
-
+
};
-
+
domain.getCommandStack().execute(cmd);
-
+
assertNotNull(listener.precommit);
assertNotNull(listener.precommit.getTransaction());
assertFalse(listener.precommit.getTransaction().isActive());
assertSame(domain, listener.precommit.getEditingDomain());
-
+
List notifications = listener.precommitNotifications;
assertNotNull(notifications);
assertEquals(1, notifications.size());
-
+
Notification notification = notifications.get(0);
assertSame(book, notification.getNotifier());
assertSame(EXTLibraryPackage.eINSTANCE.getBook_Category(), notification.getFeature());
@@ -443,156 +447,160 @@ public void execute() {
@Test
public void test_precommit_readOnly() {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
-
+
commit();
-
+
TestListener testListener = new TestListener() {
@Override
public Command transactionAboutToCommit(ResourceSetChangeEvent event) {
try {
// can execute read operations
domain.runExclusive(new Runnable() {
+ @Override
public void run() {
// do nothing
- }});
+ }
+ });
} catch (Exception e) {
fail(e);
}
-
+
try {
// cannot execute commands
domain.getCommandStack().execute(new TestCommand() {
+ @Override
public void execute() {
// do nothing
- }});
-
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ }
+ });
+
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (Exception e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
}
-
+
try {
// cannot make ad hoc changes
book.setCategory(BookCategory.BIOGRAPHY_LITERAL);
-
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (Exception e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
}
-
+
return null;
- }};
-
+ }
+ };
+
try {
domain.addResourceSetListener(testListener);
-
- String newTitle = "New Title"; //$NON-NLS-1$
-
- Command cmd = new SetCommand(
- domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle);
-
+
+ String newTitle = "New Title";
+
+ Command cmd = new SetCommand(domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle);
+
domain.getCommandStack().execute(cmd);
} catch (Exception e) {
fail(e);
} finally {
// must remove the listener, otherwise it will be invoked again
- // by the resource unload and it will fail at that time
+ // by the resource unload and it will fail at that time
domain.removeResourceSetListener(testListener);
}
}
/**
- * Tests that pre-commit listeners cannot maliciously (or accidentally)
- * close the transaction that is committing.
+ * Tests that pre-commit listeners cannot maliciously (or accidentally) close
+ * the transaction that is committing.
*/
@Test
public void test_precommit_cannotClose() {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
-
+
commit();
-
+
TestListener testListener = new TestListener() {
@Override
public Command transactionAboutToCommit(ResourceSetChangeEvent event) {
try {
// cannot commit the transaction while it is committing
event.getTransaction().commit();
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (Exception e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
}
-
+
try {
// cannot commit the transaction while it is committing
event.getTransaction().rollback();
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (Exception e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
}
-
+
return null;
- }};
-
+ }
+ };
+
try {
domain.addResourceSetListener(testListener);
-
- String newTitle = "New Title"; //$NON-NLS-1$
-
- Command cmd = new SetCommand(
- domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle);
-
+
+ String newTitle = "New Title";
+
+ Command cmd = new SetCommand(domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle);
+
domain.getCommandStack().execute(cmd);
} catch (Exception e) {
fail(e);
} finally {
// must remove the listener, otherwise it will be invoked again
- // by the resource unload and it will fail at that time
+ // by the resource unload and it will fail at that time
domain.removeResourceSetListener(testListener);
}
}
-
+
/**
- * Tests that trigger commands are executed correctly, and that they can
- * avoid feed-back.
+ * Tests that trigger commands are executed correctly, and that they can avoid
+ * feed-back.
*/
@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());
-
+
startWriting();
-
- // 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
Library newLibrary = EXTLibraryFactory.eINSTANCE.createLibrary();
root.getBranches().add(newLibrary);
-
+
assertNull(newLibrary.getName());
assertTrue(newLibrary.getBranches().isEmpty());
-
+
commit();
-
+
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();
}
-
+
/**
* Tests that a command resulting from a pre-commit (trigger) listener will,
* itself, trigger further changes.
@@ -601,66 +609,66 @@ public void test_triggerCommands() {
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());
startWriting();
-
- // 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
Library newLibrary = EXTLibraryFactory.eINSTANCE.createLibrary();
root.getBranches().add(newLibrary);
-
+
assertNull(newLibrary.getName());
assertTrue(newLibrary.getBranches().isEmpty());
-
+
commit();
-
+
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();
}
-
+
/**
- * Tests that post-commit listeners get not only the notifications generated
- * by the transaction, itself, but also by its trigger commands.
+ * Tests that post-commit listeners get not only the notifications generated by
+ * the transaction, itself, but also by its trigger commands.
*/
@Test
public void test_postcommitIncludesTriggerChanges() {
// 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());
startWriting();
-
+
// for tracking the post-commit event
TestListener testListener = new TestListener();
domain.addResourceSetListener(testListener);
-
- // 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
Library newLibrary = EXTLibraryFactory.eINSTANCE.createLibrary();
root.getBranches().add(newLibrary);
-
+
assertNull(newLibrary.getName());
assertTrue(newLibrary.getBranches().isEmpty());
-
+
commit();
assertNotNull(testListener.postcommit);
assertNotNull(testListener.postcommitNotifications);
-
+
// only one notification actually is directly caused by the transaction.
- // The others come from the (chained) triggers: one adding a book to
- // Library.stock; one for adding the book to Library.books; one for
- // setting the book's Item.publicationDate
+ // The others come from the (chained) triggers: one adding a book to
+ // Library.stock; one for adding the book to Library.books; one for
+ // setting the book's Item.publicationDate
assertEquals(4, testListener.postcommitNotifications.size());
}
@@ -671,16 +679,16 @@ public void test_postcommitIncludesTriggerChanges() {
public void test_unbatchedNotifications() {
try {
// don't start any transaction, but cause notifications
- Resource newRes = domain.createResource("/tmp/test_unbatched.extlibrary"); //$NON-NLS-1$
-
+ Resource newRes = domain.createResource("/tmp/test_unbatched.extlibrary");
+
assertNotNull(listener.postcommit);
-
+
List notifications = listener.postcommitNotifications;
assertNotNull(notifications);
-
+
// unbatched notifications are always singletons
assertEquals(1, notifications.size());
-
+
Notification notification = notifications.get(0);
assertSame(domain.getResourceSet(), notification.getNotifier());
assertEquals(Notification.ADD, notification.getEventType());
@@ -690,54 +698,54 @@ public void test_unbatchedNotifications() {
fail(e);
}
}
-
+
/**
* Tests that notifications resulting from reads performed by post-commit
- * listeners are, themselves, batched and sent around again to the
- * listeners.
+ * listeners are, themselves, batched and sent around again to the listeners.
*/
@Test
public void test_readNotifications_cascading() {
final Resource[] newRes = new Resource[1];
-
+
TestListener testListener = new TestListener() {
@Override
public void resourceSetChanged(ResourceSetChangeEvent event) {
// make sure that I only do this on the first time that I
- // am invoked (from the new library notification)
- URI uri = URI.createFileURI("/tmp/test_readCascade.extlibrary"); //$NON-NLS-1$
+ // am invoked (from the new library notification)
+ URI uri = URI.createFileURI("/tmp/test_readCascade.extlibrary");
if (domain.getResourceSet().getResource(uri, false) == null) {
// prepare the fixture listener to receive the read notification
listener.reset();
-
+
newRes[0] = domain.getResourceSet().createResource(uri);
}
- }};
-
+ }
+ };
+
domain.addResourceSetListener(testListener);
-
+
try {
startWriting();
-
- // add a new library. Our listener will cause read notifications
+
+ // add a new library. Our listener will cause read notifications
Library newLibrary = EXTLibraryFactory.eINSTANCE.createLibrary();
root.getBranches().add(newLibrary);
-
+
commit();
-
+
// assert that the resource was created and stored
assertNotNull(newRes[0]);
-
+
// check that the read notifications cascaded (read in the listener
- // caused more notifications to the listeners)
+ // caused more notifications to the listeners)
assertNotNull(listener.postcommit);
-
+
List notifications = listener.postcommitNotifications;
assertNotNull(notifications);
-
+
// unbatched notifications are always singletons
assertEquals(1, notifications.size());
-
+
Notification notification = notifications.get(0);
assertSame(domain.getResourceSet(), notification.getNotifier());
assertEquals(Notification.ADD, notification.getEventType());
@@ -750,77 +758,76 @@ public void resourceSetChanged(ResourceSetChangeEvent event) {
/**
* Tests that aggregated pre-commit listeners are notified only when the
- * root-level read/write transaction commits, with all of the notifications
- * from the transaction and any nested transactions.
+ * root-level read/write transaction commits, with all of the notifications from
+ * the transaction and any nested transactions.
*/
@Test
public void test_precommit_aggregated_121508() {
try {
class AggregatedListener extends TestListener {
int count = 0;
-
+
@Override
- public Command transactionAboutToCommit(ResourceSetChangeEvent event)
- throws RollbackException {
-
+ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
+
count++;
-
+
return super.transactionAboutToCommit(event);
}
-
+
@Override
public void reset() {
super.reset();
-
+
count = 0;
}
-
+
@Override
public boolean isAggregatePrecommitListener() {
return true;
}
}
-
+
AggregatedListener localListener = new AggregatedListener();
domain.addResourceSetListener(localListener);
-
+
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
-
+
commit();
-
- String newTitle1 = "New Title1"; //$NON-NLS-1$
- String newTitle2 = "New Title2"; //$NON-NLS-1$
-
+
+ String newTitle1 = "New Title1";
+ String newTitle2 = "New Title2";
+
startWriting();
-
+
book.setTitle(newTitle1);
-
+
// nested
startWriting();
-
+
book.setTitle(newTitle2);
-
+
commit();
-
+
commit();
-
+
assertNotNull(localListener.precommit);
assertNotNull(localListener.precommit.getTransaction());
assertEquals(1, localListener.count);
-
+
List notifications = localListener.precommitNotifications;
assertNotNull(notifications);
assertEquals(2, notifications.size());
-
+
// notifications came in the right order
Notification notification = notifications.get(0);
assertSame(book, notification.getNotifier());
assertSame(EXTLibraryPackage.eINSTANCE.getBook_Title(), notification.getFeature());
assertSame(newTitle1, notification.getNewValue());
-
+
notification = notifications.get(1);
assertSame(book, notification.getNotifier());
assertSame(EXTLibraryPackage.eINSTANCE.getBook_Title(), notification.getFeature());
@@ -831,83 +838,79 @@ public boolean isAggregatePrecommitListener() {
}
/**
- * Tests that changes made by aggregated pre-commit listeners are fed back
- * into those listeners again.
+ * Tests that changes made by aggregated pre-commit listeners are fed back into
+ * those listeners again.
*/
@Test
public void test_precommit_aggregatedCascade_121508() {
try {
- final String newTitle1 = "New Title1"; //$NON-NLS-1$
- final String newTitle2 = "New Title2"; //$NON-NLS-1$
-
+ final String newTitle1 = "New Title1";
+ final String newTitle2 = "New Title2";
+
class AggregatedListener extends TestListener {
int count = 0;
-
+
@Override
- public Command transactionAboutToCommit(ResourceSetChangeEvent event)
- throws RollbackException {
-
+ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
+
count++;
-
+
super.transactionAboutToCommit(event);
-
+
if (count < 2) {
List notifications = event.getNotifications();
assertNotNull(notifications);
assertEquals(1, notifications.size());
-
+
Notification notification = notifications.get(0);
assertSame(EXTLibraryPackage.eINSTANCE.getBook_Title(), notification.getFeature());
assertSame(newTitle1, notification.getNewValue());
-
+
Book book = (Book) notification.getNotifier();
-
- return new SetCommand(
- domain, book,
- EXTLibraryPackage.eINSTANCE.getBook_Title(),
- newTitle2);
+
+ return new SetCommand(domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle2);
}
-
+
return null;
}
-
+
@Override
public void reset() {
super.reset();
-
+
count = 0;
}
-
+
@Override
public boolean isAggregatePrecommitListener() {
return true;
}
}
-
+
AggregatedListener localListener = new AggregatedListener();
domain.addResourceSetListener(localListener);
-
+
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
-
+
commit();
-
+
startWriting();
-
+
book.setTitle(newTitle1);
-
+
commit();
-
+
assertNotNull(localListener.precommit);
assertNotNull(localListener.precommit.getTransaction());
assertEquals(2, localListener.count);
-
+
List notifications = localListener.precommitNotifications;
assertNotNull(notifications);
assertEquals(1, notifications.size());
-
+
Notification notification = notifications.get(0);
assertSame(book, notification.getNotifier());
assertSame(EXTLibraryPackage.eINSTANCE.getBook_Title(), notification.getFeature());
@@ -916,50 +919,50 @@ public boolean isAggregatePrecommitListener() {
fail(e);
}
}
-
+
/**
- * Tests the propagation of resource change events to post-commit listeners
- * even in the case of a transaction rolling back, where the resource change
- * is a URI change.
+ * Tests the propagation of resource change events to post-commit listeners even
+ * in the case of a transaction rolling back, where the resource change is a URI
+ * change.
*/
@Test
public void test_rollback_resourceChangePropagation_uri_145321() {
class ResourceListener extends DemultiplexingListener {
boolean wasCalled;
-
+
@Override
protected void handleNotification(TransactionalEditingDomain domain, Notification notification) {
wasCalled = true;
}
}
-
- Resource test1 = domain.getResourceSet().createResource(URI.createURI("http://foo1.xmi")); //$NON-NLS-1$
+
+ Resource test1 = domain.getResourceSet().createResource(URI.createURI("http://foo1.xmi"));
Book book = EXTLibraryFactory.eINSTANCE.createBook();
-
+
startWriting();
-
+
// load the resource
test1.getContents().add(book);
-
+
commit();
ResourceListener listener = new ResourceListener();
domain.addResourceSetListener(listener);
-
- // now the meat of the test: unload in a transaction
+
+ // now the meat of the test: unload in a transaction
startWriting();
-
- book.setTitle("foo"); //$NON-NLS-1$
-
+
+ book.setTitle("foo");
+
rollback();
-
+
// contents change was rolled back
assertNull(book.getTitle());
-
+
// no notifications were sent out
assertFalse(listener.wasCalled);
}
-
+
/**
* Tests that, when non-undoable changes such as resource loads do not occur
* during a transaction that was rolled back, listeners are not invoked.
@@ -969,380 +972,380 @@ public void test_rollback_noEvents_145321() {
class ResourceListener extends DemultiplexingListener {
private final ResourceSet interestingResourceSet;
private final Book interestingBook;
-
+
boolean changed;
-
+
ResourceListener(ResourceSet resourceSet, Book book) {
interestingResourceSet = resourceSet;
interestingBook = book;
}
-
+
@Override
protected void handleNotification(TransactionalEditingDomain domain, Notification notification) {
Object notifier = notification.getNotifier();
-
+
if (notifier == interestingResourceSet) {
int featureID = notification.getFeatureID(ResourceSet.class);
-
+
switch (featureID) {
case ResourceSet.RESOURCE_SET__RESOURCES:
changed = true;
break;
}
} else if (notifier == interestingBook) {
- Assert.fail("Should not have received notification of contents change"); //$NON-NLS-1$
+ Assertions.fail("Should not have received notification of contents change");
}
}
}
-
- Resource test1 = domain.getResourceSet().createResource(URI.createURI("http://foo1.xmi")); //$NON-NLS-1$
+
+ Resource test1 = domain.getResourceSet().createResource(URI.createURI("http://foo1.xmi"));
Book book = EXTLibraryFactory.eINSTANCE.createBook();
-
+
ResourceListener listener = new ResourceListener(domain.getResourceSet(), book);
domain.addResourceSetListener(listener);
-
+
startWriting();
-
+
test1.getContents().add(book);
- book.setTitle("foo"); //$NON-NLS-1$
-
+ book.setTitle("foo");
+
rollback();
-
+
// contents change was rolled back
assertNull(book.getTitle());
-
+
// no resource set change occurred
assertFalse(listener.changed);
}
-
+
/**
- * Tests the propagation of resource change events to post-commit listeners
- * even in the case of a transaction rolling back, where the resource change
- * is a created change.
+ * Tests the propagation of resource change events to post-commit listeners even
+ * in the case of a transaction rolling back, where the resource change is a
+ * created change.
*/
@Test
public void test_rollback_resourceChangePropagation_created_145321() {
class ResourceListener extends DemultiplexingListener {
private final ResourceSet interestingResourceSet;
private final Book interestingBook;
-
+
boolean changed;
-
+
ResourceListener(ResourceSet resourceSet, Book book) {
interestingResourceSet = resourceSet;
interestingBook = book;
}
-
+
@Override
protected void handleNotification(TransactionalEditingDomain domain, Notification notification) {
Object notifier = notification.getNotifier();
-
+
if (notifier == interestingResourceSet) {
int featureID = notification.getFeatureID(ResourceSet.class);
-
+
switch (featureID) {
case ResourceSet.RESOURCE_SET__RESOURCES:
changed = true;
break;
}
} else if (notifier == interestingBook) {
- Assert.fail("Should not have received notification of contents change"); //$NON-NLS-1$
+ Assertions.fail("Should not have received notification of contents change");
}
}
}
-
- Resource test1 = domain.getResourceSet().createResource(URI.createURI("http://foo1.xmi")); //$NON-NLS-1$
+
+ Resource test1 = domain.getResourceSet().createResource(URI.createURI("http://foo1.xmi"));
Book book = EXTLibraryFactory.eINSTANCE.createBook();
-
+
ResourceListener listener = new ResourceListener(domain.getResourceSet(), book);
domain.addResourceSetListener(listener);
-
+
startWriting();
-
+
test1.getContents().add(book);
- book.setTitle("foo"); //$NON-NLS-1$
-
+ book.setTitle("foo");
+
// create another resource
- URI newURI = URI.createURI("http://newfoo.xmi"); //$NON-NLS-1$
+ URI newURI = URI.createURI("http://newfoo.xmi");
domain.getResourceSet().createResource(newURI);
-
+
rollback();
-
+
// contents change was rolled back
assertNull(book.getTitle());
-
+
// resource set state change was not
assertNotNull(domain.getResourceSet().getResource(newURI, false));
assertTrue(listener.changed);
}
-
+
/**
- * Tests the propagation of resource change events to post-commit listeners
- * even in the case of a transaction rolling back, where the resource change
- * is a loaded change.
+ * Tests the propagation of resource change events to post-commit listeners even
+ * in the case of a transaction rolling back, where the resource change is a
+ * loaded change.
*/
@Test
public void test_rollback_resourceChangePropagation_loaded_145321() {
class ResourceListener extends DemultiplexingListener {
private final Resource interestingResource;
private final Book interestingBook;
-
+
boolean changed;
-
+
ResourceListener(Resource resource, Book book) {
interestingResource = resource;
interestingBook = book;
}
-
+
@Override
protected void handleNotification(TransactionalEditingDomain domain, Notification notification) {
Object notifier = notification.getNotifier();
-
+
if (notifier == interestingResource) {
int featureID = notification.getFeatureID(Resource.class);
-
+
switch (featureID) {
case Resource.RESOURCE__IS_LOADED:
changed = true;
break;
}
} else if (notifier == interestingBook) {
- Assert.fail("Should not have received notification of contents change"); //$NON-NLS-1$
+ Assertions.fail("Should not have received notification of contents change");
}
}
}
-
- Resource test1 = domain.getResourceSet().createResource(URI.createURI("http://foo1.xmi")); //$NON-NLS-1$
+
+ Resource test1 = domain.getResourceSet().createResource(URI.createURI("http://foo1.xmi"));
Book book = EXTLibraryFactory.eINSTANCE.createBook();
-
+
ResourceListener listener = new ResourceListener(test1, book);
domain.addResourceSetListener(listener);
-
+
startWriting();
-
+
// causes a load event
test1.getContents().add(book);
- book.setTitle("foo"); //$NON-NLS-1$
-
+ book.setTitle("foo");
+
rollback();
-
+
// contents change was rolled back
assertNull(book.getTitle());
-
+
// loaded state change was not
assertTrue(test1.isLoaded());
assertTrue(listener.changed);
}
-
+
/**
- * Tests the propagation of resource change events to post-commit listeners
- * even in the case of a transaction rolling back, where the resource change
- * is an unloaded change.
+ * Tests the propagation of resource change events to post-commit listeners even
+ * in the case of a transaction rolling back, where the resource change is an
+ * unloaded change.
*/
@Test
public void test_rollback_resourceChangePropagation_unloaded_145321() {
class ResourceListener extends DemultiplexingListener {
private final Resource interestingResource;
private final Book interestingBook;
-
+
boolean changed;
-
+
ResourceListener(Resource resource, Book book) {
interestingResource = resource;
interestingBook = book;
}
-
+
@Override
protected void handleNotification(TransactionalEditingDomain domain, Notification notification) {
Object notifier = notification.getNotifier();
-
+
if (notifier == interestingResource) {
int featureID = notification.getFeatureID(Resource.class);
-
+
switch (featureID) {
case Resource.RESOURCE__IS_LOADED:
changed = true;
break;
}
} else if (notifier == interestingBook) {
- Assert.fail("Should not have received notification of contents change"); //$NON-NLS-1$
+ Assertions.fail("Should not have received notification of contents change");
}
}
}
-
- Resource test1 = domain.getResourceSet().createResource(URI.createURI("http://foo1.xmi")); //$NON-NLS-1$
+
+ Resource test1 = domain.getResourceSet().createResource(URI.createURI("http://foo1.xmi"));
Book book = EXTLibraryFactory.eINSTANCE.createBook();
-
+
startWriting();
-
+
// load the resource
test1.getContents().add(book);
-
+
commit();
ResourceListener listener = new ResourceListener(test1, book);
domain.addResourceSetListener(listener);
-
- // now the meat of the test: unload in a transaction
+
+ // now the meat of the test: unload in a transaction
startWriting();
-
- book.setTitle("foo"); //$NON-NLS-1$
+
+ book.setTitle("foo");
test1.unload();
-
+
rollback();
-
+
// contents change was rolled back
assertNull(book.getTitle());
-
+
// loaded state change was not
-//TODO: Proxies are being added back into the resource!
+//TODO: Proxies are being added back into the resource!
// assertFalse(test1.isLoaded());
assertTrue(listener.changed);
}
-
- /**
- * 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.
- */
+
+ /**
+ * 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
+ 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];
-
- // add a new library. Our trigger will set a default name
- domain.getCommandStack().execute(new RecordingCommand(domain) {
- @Override
+ newLibrary.setName("New Library");
+ }
+ };
+ }
+
+ return result;
+ }
+ });
+
+ final Library[] newLibrary = new Library[1];
+
+ // add a new library. Our trigger will set a default name
+ domain.getCommandStack().execute(new RecordingCommand(domain) {
+ @Override
protected void doExecute() {
- newLibrary[0] = EXTLibraryFactory.eINSTANCE.createLibrary();
- root.getBranches().add(newLibrary[0]);
-
- assertNull(newLibrary[0].getName());
- }});
-
- startReading();
-
- assertEquals("New Library", newLibrary[0].getName()); //$NON-NLS-1$
-
- commit();
-
- domain.getCommandStack().undo();
-
- assertFalse(root.getBranches().contains(newLibrary[0]));
- assertNull(newLibrary[0].eResource());
- assertNull(newLibrary[0].getName());
-
- domain.getCommandStack().redo();
-
- assertTrue(root.getBranches().contains(newLibrary[0]));
- assertEquals("New Library", newLibrary[0].getName()); //$NON-NLS-1$
- }
-
+ newLibrary[0] = EXTLibraryFactory.eINSTANCE.createLibrary();
+ root.getBranches().add(newLibrary[0]);
+
+ assertNull(newLibrary[0].getName());
+ }
+ });
+
+ startReading();
+
+ assertEquals("New Library", newLibrary[0].getName());
+
+ commit();
+
+ domain.getCommandStack().undo();
+
+ assertFalse(root.getBranches().contains(newLibrary[0]));
+ assertNull(newLibrary[0].eResource());
+ assertNull(newLibrary[0].getName());
+
+ domain.getCommandStack().redo();
+
+ assertTrue(root.getBranches().contains(newLibrary[0]));
+ assertEquals("New Library", newLibrary[0].getName());
+ }
+
@Test
- public void test_internalListenerNotifications_177642() {
- class LocalListener extends ResourceSetListenerImpl {
- private int setCount, unsetCount;
-
- void assertTarget(TransactionalEditingDomain domain) {
- assertSame(domain, getTarget());
- }
-
- void assertSetCount(int count) {
- assertEquals(count, setCount);
- }
-
- void assertUnsetCount(int count) {
- assertEquals(count, unsetCount);
- }
-
- @Override
- public void setTarget(TransactionalEditingDomain domain) {
- super.setTarget(domain);
-
- setCount++;
- }
-
- @Override
- public void unsetTarget(TransactionalEditingDomain domain) {
- unsetCount++;
-
- super.unsetTarget(domain);
- }
- }
-
- LocalListener l = new LocalListener();
-
- domain.addResourceSetListener(l);
-
- l.assertSetCount(1);
- l.assertTarget(domain);
- l.assertUnsetCount(0);
-
- domain.addResourceSetListener(l);
-
- // idempotent
- l.assertSetCount(1);
- l.assertTarget(domain);
- l.assertUnsetCount(0);
-
- domain.removeResourceSetListener(l);
-
- l.assertSetCount(1);
- l.assertTarget(null);
- l.assertUnsetCount(1);
-
- domain.removeResourceSetListener(l);
-
- // idempotent
- l.assertSetCount(1);
- l.assertTarget(null);
- l.assertUnsetCount(1);
- }
-
+ public void test_internalListenerNotifications_177642() {
+ class LocalListener extends ResourceSetListenerImpl {
+ private int setCount, unsetCount;
+
+ void assertTarget(TransactionalEditingDomain domain) {
+ assertSame(domain, getTarget());
+ }
+
+ void assertSetCount(int count) {
+ assertEquals(count, setCount);
+ }
+
+ void assertUnsetCount(int count) {
+ assertEquals(count, unsetCount);
+ }
+
+ @Override
+ public void setTarget(TransactionalEditingDomain domain) {
+ super.setTarget(domain);
+
+ setCount++;
+ }
+
+ @Override
+ public void unsetTarget(TransactionalEditingDomain domain) {
+ unsetCount++;
+
+ super.unsetTarget(domain);
+ }
+ }
+
+ LocalListener l = new LocalListener();
+
+ domain.addResourceSetListener(l);
+
+ l.assertSetCount(1);
+ l.assertTarget(domain);
+ l.assertUnsetCount(0);
+
+ domain.addResourceSetListener(l);
+
+ // idempotent
+ l.assertSetCount(1);
+ l.assertTarget(domain);
+ l.assertUnsetCount(0);
+
+ domain.removeResourceSetListener(l);
+
+ l.assertSetCount(1);
+ l.assertTarget(null);
+ l.assertUnsetCount(1);
+
+ domain.removeResourceSetListener(l);
+
+ // idempotent
+ l.assertSetCount(1);
+ l.assertTarget(null);
+ l.assertUnsetCount(1);
+ }
+
//
// Fixture methods
//
-
+
@Override
- protected void doSetUp()
- throws Exception {
-
+ protected void doSetUp() throws Exception {
+
super.doSetUp();
-
+
// in case the resource that we created tracks modification, we
- // don't want this because it will add notifications that
- // confuse our counts when we attach listeners to gather
- // notifications
+ // don't want this because it will add notifications that
+ // confuse our counts when we attach listeners to gather
+ // notifications
testResource.setTrackingModification(false);
-
+
listener = new TestListener();
domain.addResourceSetListener(listener);
}
-
+
@Override
- protected void doTearDown()
- throws Exception {
-
+ protected void doTearDown() throws Exception {
+
domain.removeResourceSetListener(listener);
listener = null;
-
+
super.doTearDown();
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/TestsPlugin.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/TestsPlugin.java
index ae2deaf1..8ae3e140 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/TestsPlugin.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/TestsPlugin.java
@@ -21,18 +21,18 @@
*/
public class TestsPlugin extends Plugin {
public static TestsPlugin instance;
-
+
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
-
+
instance = this;
}
-
+
@Override
public void stop(BundleContext context) throws Exception {
instance = null;
-
+
super.stop(context);
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/TransactionChangeRecorderTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/TransactionChangeRecorderTest.java
index 7a1d09ff..e28af3ae 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/TransactionChangeRecorderTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/TransactionChangeRecorderTest.java
@@ -11,10 +11,10 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+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 java.io.IOException;
import java.util.Collections;
@@ -35,8 +35,8 @@
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.impl.TransactionChangeRecorder;
import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests the TransactionChangeRecorder class, specifically.
@@ -207,7 +207,7 @@ public void test_changeRecorderDispose_161169() {
eclass.setName("NewName");
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Should not have asserted the transaction protocol: " + e.getLocalizedMessage());
+ Assertions.fail("Should not have asserted the transaction protocol: " + e.getLocalizedMessage());
}
}
@@ -239,7 +239,7 @@ public void test_changeRecorderDispose_detachedElements_161169() {
eclass.setName("NewName");
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Should not have asserted the transaction protocol: " + e.getLocalizedMessage());
+ Assertions.fail("Should not have asserted the transaction protocol: " + e.getLocalizedMessage());
}
}
@@ -271,7 +271,7 @@ public void test_freeDetachedResources_161169() {
eclass.setName("NewName");
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Should not have asserted the transaction protocol: " + e.getLocalizedMessage());
+ Assertions.fail("Should not have asserted the transaction protocol: " + e.getLocalizedMessage());
}
}
@@ -302,7 +302,7 @@ public void test_freeDetachedResources_properContents_161169() {
// set the nested resource free
TransactionUtil.disconnectFromEditingDomain(nestedResource1);
- Assert.fail("Should have thrown IllegalArgumentException");
+ Assertions.fail("Should have thrown IllegalArgumentException");
} catch (IllegalArgumentException e) {
// pass
System.out.println("Got expected exception: " + e.getLocalizedMessage());
@@ -312,7 +312,7 @@ public void test_freeDetachedResources_properContents_161169() {
// modify the nested element
nested.setName("NewName");
- Assert.fail("Should have thrown IllegalStateException");
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (IllegalStateException e) {
// pass
System.out.println("Got expected exception: " + e.getLocalizedMessage());
@@ -348,7 +348,7 @@ public void test_freeDetachedElements_161169() {
eclass.setName("NewName");
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Should not have asserted the transaction protocol: " + e.getLocalizedMessage());
+ Assertions.fail("Should not have asserted the transaction protocol: " + e.getLocalizedMessage());
}
}
@@ -377,7 +377,7 @@ public void test_freeDetachedElements_properContents_161169() {
// set the nested element free
TransactionUtil.disconnectFromEditingDomain(nested);
- Assert.fail("Should have thrown IllegalArgumentException");
+ Assertions.fail("Should have thrown IllegalArgumentException");
} catch (IllegalArgumentException e) {
// pass
System.out.println("Got expected exception: " + e.getLocalizedMessage());
@@ -387,7 +387,7 @@ public void test_freeDetachedElements_properContents_161169() {
// modify the nested element
nested.setName("NewName");
- Assert.fail("Should have thrown IllegalStateException");
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (IllegalStateException e) {
// pass
System.out.println("Got expected exception: " + e.getLocalizedMessage());
@@ -423,7 +423,7 @@ public void test_freeElements_multipleEditingDomains_161169() {
try {
TransactionUtil.disconnectFromEditingDomain(rootResource);
- Assert.fail("Should have thrown IllegalArgumentException");
+ Assertions.fail("Should have thrown IllegalArgumentException");
} catch (IllegalArgumentException e) {
// pass
System.out.println("Got expected exception: " + e.getLocalizedMessage());
@@ -440,7 +440,7 @@ public void test_freeElements_multipleEditingDomains_161169() {
eclass.setName("NewName");
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Should not have asserted the transaction protocol: " + e.getLocalizedMessage());
+ Assertions.fail("Should not have asserted the transaction protocol: " + e.getLocalizedMessage());
}
}
@@ -466,13 +466,13 @@ public void unsetTarget(Notifier oldTarget) {
// unload the resource
Resource res = eclass.eResource();
res.unload();
- assertTrue("Resource not reloaded", res.isLoaded());
+ assertTrue(res.isLoaded(), "Resource not reloaded");
try {
// should be allowed to modify this resource by unloading it again
res.unload();
} catch (IllegalStateException e) {
- Assert.fail("Should not have thrown: " + e.getLocalizedMessage());
+ Assertions.fail("Should not have thrown: " + e.getLocalizedMessage());
}
}
@@ -521,7 +521,7 @@ protected void doSetUp() throws Exception {
commit();
} catch (IOException e) {
- Assert.fail("Failed to create test model: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to create test model: " + e.getLocalizedMessage());
}
}
@@ -549,7 +549,7 @@ protected EPackage findPackage(String qname, boolean require) {
EPackage result = (EPackage) find(rootResource, qname);
if (require) {
- assertNotNull("Did not find package " + qname, result);
+ assertNotNull(result, "Did not find package " + qname);
}
return result;
@@ -559,7 +559,7 @@ protected EClass findClass(String qname, boolean require) {
EClass result = (EClass) find(rootResource, qname);
if (require) {
- assertNotNull("Did not find class " + qname, result);
+ assertNotNull(result, "Did not find class " + qname);
}
return result;
@@ -567,7 +567,7 @@ protected EClass findClass(String qname, boolean require) {
/**
* Gets the name of an Ecore object.
- *
+ *
* @param object the object
* @return its name
*/
@@ -585,7 +585,7 @@ protected void loadRoot() {
rootResource.load(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
- Assert.fail("Failed to load root resource: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to load root resource: " + e.getLocalizedMessage());
}
}
@@ -599,7 +599,7 @@ protected TransactionChangeRecorder getRecorder(Notifier notifier) {
}
}
- assertNotNull("Did not find change recorder", result);
+ assertNotNull(result, "Did not find change recorder");
return result;
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/TransactionOptionsTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/TransactionOptionsTest.java
index 3696b606..bd943a7f 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/TransactionOptionsTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/TransactionOptionsTest.java
@@ -11,12 +11,12 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+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 java.util.Collection;
import java.util.Collections;
@@ -39,8 +39,8 @@
import org.eclipse.emf.transaction.impl.TransactionImpl;
import org.eclipse.emf.transaction.tests.fixtures.TestListener;
import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests the effect of transaction options.
@@ -60,11 +60,11 @@ public void test_noNotifications() {
startWriting(Transaction.OPTION_NO_NOTIFICATIONS);
- 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);
book.setTitle(newTitle);
@@ -86,11 +86,11 @@ public void test_noTriggers() {
startWriting(Transaction.OPTION_NO_TRIGGERS);
- 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);
book.setTitle(newTitle);
@@ -112,7 +112,7 @@ public void test_noValidation() {
startWriting(Transaction.OPTION_NO_VALIDATION);
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
book.setTitle(null);
@@ -141,11 +141,11 @@ public void test_noUndo() {
final Transaction tx = getActiveTransaction();
- 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);
book.setTitle(newTitle);
@@ -165,11 +165,11 @@ public void test_noUndo_recordingCommand() {
Command cmd = new RecordingCommand(domain) {
@Override
protected void doExecute() {
- 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);
book.setTitle(newTitle);
@@ -190,9 +190,9 @@ protected void doExecute() {
startReading();
// still find these changes
- Book book = (Book) find("root/New Title"); //$NON-NLS-1$
+ Book book = (Book) find("root/New Title");
assertNotNull(book.getTitle());
- assertSame(find("root/level1/Level1 Writer"), book.getAuthor()); //$NON-NLS-1$
+ assertSame(find("root/level1/Level1 Writer"), book.getAuthor());
commit();
}
@@ -205,10 +205,10 @@ protected void doExecute() {
public void test_noUndo_regularCommand() {
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 String newTitle = "New Title";
Command cmd = new SetCommand(domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), newTitle);
@@ -234,11 +234,11 @@ public void test_unprotected() {
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);
// start an unprotected write transaction
@@ -279,11 +279,11 @@ public void test_nested_noNotifications_124334() {
// nested silent transaction
startWriting(Transaction.OPTION_NO_NOTIFICATIONS);
- 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);
book.setTitle(newTitle);
@@ -310,11 +310,11 @@ public void test_nested_unvalidatedPostCommit_124334() {
// nested silent transaction
startWriting(Transaction.OPTION_NO_VALIDATION);
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
final String newTitle = null;
- final Writer newAuthor = (Writer) find("root/level1/Level1 Writer"); //$NON-NLS-1$
+ final Writer newAuthor = (Writer) find("root/level1/Level1 Writer");
assertNotNull(newAuthor);
book.setTitle(newTitle);
@@ -341,10 +341,10 @@ public void test_nested_unvalidated_124334() {
// nested silent transaction
startWriting(Transaction.OPTION_NO_VALIDATION);
- final Book book1 = (Book) find("root/Root Book"); //$NON-NLS-1$
+ final Book book1 = (Book) find("root/Root Book");
assertNotNull(book1);
- final Book book2 = (Book) find("root/level1/Level1 Book"); //$NON-NLS-1$
+ final Book book2 = (Book) find("root/level1/Level1 Book");
assertNotNull(book2);
final String newTitle = null;
@@ -358,7 +358,7 @@ public void test_nested_unvalidated_124334() {
try {
tx.commit();
- Assert.fail("Should have rolled back because of outer transaction validation"); //$NON-NLS-1$
+ Assertions.fail("Should have rolled back because of outer transaction validation");
} catch (RollbackException e) {
// expected exception
Collection errors = findValidationStatuses(e.getStatus(), IStatus.ERROR);
@@ -370,7 +370,7 @@ public void test_nested_unvalidated_124334() {
@Test
public void test_transactionOptionInheritance_135569() {
- Map options = new java.util.HashMap();
+ Map options = new java.util.HashMap<>();
Map, ?> active;
// test the inheritance of empty options
@@ -390,19 +390,19 @@ public void test_transactionOptionInheritance_135569() {
// test the inheritance of non-empty options
options.put(Transaction.OPTION_NO_UNDO, Boolean.TRUE);
Object marker = new Object();
- options.put("my own option", marker); //$NON-NLS-1$
+ options.put("my own option", marker);
startWriting(options);
active = getActiveTransaction().getOptions();
assertSame(Boolean.TRUE, active.get(Transaction.OPTION_NO_UNDO));
- assertSame(marker, active.get("my own option")); //$NON-NLS-1$
+ assertSame(marker, active.get("my own option"));
startWriting();
active = getActiveTransaction().getOptions();
assertSame(Boolean.TRUE, active.get(Transaction.OPTION_NO_UNDO));
- assertSame(marker, active.get("my own option")); //$NON-NLS-1$
+ assertSame(marker, active.get("my own option"));
commit();
commit();
@@ -411,25 +411,25 @@ public void test_transactionOptionInheritance_135569() {
options.put(Transaction.OPTION_NO_UNDO, Boolean.TRUE);
marker = new Object();
- options.put("my own option", marker); //$NON-NLS-1$
+ options.put("my own option", marker);
startWriting(options);
options.put(Transaction.OPTION_NO_UNDO, Boolean.FALSE);
Object marker2 = new Object();
- options.put("my own option", marker2); //$NON-NLS-1$
+ options.put("my own option", marker2);
// active options should be copied, not affected by changes to 'options'
active = getActiveTransaction().getOptions();
assertSame(Boolean.TRUE, active.get(Transaction.OPTION_NO_UNDO));
- assertSame(marker, active.get("my own option")); //$NON-NLS-1$
+ assertSame(marker, active.get("my own option"));
startWriting(options);
active = getActiveTransaction().getOptions();
assertSame(Boolean.FALSE, active.get(Transaction.OPTION_NO_UNDO));
- assertSame(marker2, active.get("my own option")); //$NON-NLS-1$
+ assertSame(marker2, active.get("my own option"));
commit();
commit();
@@ -445,11 +445,11 @@ public void test_notificationsNotRetainedAfterCommit_152335() {
startWriting();
InternalTransaction tx = getActiveTransaction();
- 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);
book.setTitle(newTitle);
@@ -470,18 +470,18 @@ public void test_notificationsNotRetainedAfterCommit_152335() {
*/
@Test
public void test_noNotificationsInSilentUnprotected_152335() {
- Map options = new java.util.HashMap();
+ Map options = new java.util.HashMap<>();
options.put(Transaction.OPTION_NO_NOTIFICATIONS, Boolean.TRUE);
options.put(Transaction.OPTION_UNPROTECTED, Boolean.TRUE);
startWriting(options);
InternalTransaction tx = getActiveTransaction();
- 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);
book.setTitle(newTitle);
@@ -508,13 +508,13 @@ public void test_childrenOfSilentUnprotected_152332() {
startWriting();
- 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";
book.setTitle(newTitle);
- Map options = new java.util.HashMap();
+ Map options = new java.util.HashMap<>();
options.put(Transaction.OPTION_NO_NOTIFICATIONS, Boolean.TRUE);
options.put(Transaction.OPTION_UNPROTECTED, Boolean.TRUE);
@@ -524,7 +524,7 @@ public void test_childrenOfSilentUnprotected_152332() {
// this transaction thinks it is normal, but it isn't
startWriting();
- final Writer newAuthor = (Writer) find("root/level1/Level1 Writer"); //$NON-NLS-1$
+ final Writer newAuthor = (Writer) find("root/level1/Level1 Writer");
assertNotNull(newAuthor);
newAuthor.getBooks().add(book);
@@ -550,9 +550,10 @@ public void test_childrenOfSilentUnprotected_152332() {
@Test
public void test_optionsInheritedAtActivationTime_() {
final Object sync = new Object();
- final String bogusOption = "**bogus**option**"; //$NON-NLS-1$
+ final String bogusOption = "**bogus**option**";
Runnable run = new Runnable() {
+ @Override
public void run() {
synchronized (sync) {
startWriting(bogusOption);
@@ -562,7 +563,7 @@ public void run() {
try {
sync.wait();
} catch (Exception e) {
- Assert.fail("Wait failed in thread"); //$NON-NLS-1$
+ Assertions.fail("Wait failed in thread");
}
commit();
@@ -570,7 +571,7 @@ public void run() {
try {
sync.notifyAll();
} catch (Exception e) {
- Assert.fail("Wait failed in thread"); //$NON-NLS-1$
+ Assertions.fail("Wait failed in thread");
}
}
@@ -585,7 +586,7 @@ public void run() {
try {
sync.wait();
} catch (Exception e) {
- Assert.fail("Wait failed on main"); //$NON-NLS-1$
+ Assertions.fail("Wait failed on main");
}
}
@@ -600,7 +601,7 @@ public void run() {
try {
sync.wait();
} catch (Exception e) {
- Assert.fail("Wait failed on main"); //$NON-NLS-1$
+ Assertions.fail("Wait failed on main");
}
}
}
@@ -622,7 +623,7 @@ public void test_defaultTransactionOptions() {
getCommandStack().execute(new AddCommand(domain, root, EXTLibraryPackage.Literals.LIBRARY__WRITERS,
EXTLibraryFactory.eINSTANCE.createWriter()));
- assertNull("Shouldn't have received notifications", l.postcommit); //$NON-NLS-1$
+ assertNull(l.postcommit, "Shouldn't have received notifications");
}
//
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/UndoRedoTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/UndoRedoTest.java
index dbab5107..3152ebf8 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/UndoRedoTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/UndoRedoTest.java
@@ -12,13 +12,13 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+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.Set;
@@ -49,8 +49,8 @@
import org.eclipse.emf.transaction.tests.fixtures.LibraryDefaultBookTrigger;
import org.eclipse.emf.transaction.tests.fixtures.TestCommand;
import org.eclipse.emf.transaction.util.ConditionalRedoCommand;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests undo and redo of commands by the command stack.
@@ -376,6 +376,7 @@ void reset() {
count = 0;
}
+ @Override
public void execute() {
reset();
}
@@ -391,7 +392,7 @@ public void redo() {
}
}
- final Set countingCommands = new java.util.HashSet();
+ final Set countingCommands = new java.util.HashSet<>();
// add the trigger to create a default book in a new library, combined
// with a counting command
@@ -478,6 +479,7 @@ protected Command trigger(TransactionalEditingDomain domain, Notification notifi
@Test
public void test_nonredoableCommand_138287() {
Command cmd = new TestCommand.Redoable() {
+ @Override
public void execute() {
// nothing to do
}
@@ -508,6 +510,7 @@ public void test_nonredoableTriggerCommand_138287() {
@Override
protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
return new TestCommand.Redoable() {
+ @Override
public void execute() {
// nothing to do
}
@@ -550,6 +553,7 @@ public void test_nonredoableTriggerCommands() {
@Override
protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
return new TestCommand.Redoable() {
+ @Override
public void execute() {
// nothing to do
}
@@ -567,6 +571,7 @@ public boolean canRedo() {
@Override
protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
return new TestCommand.Redoable() {
+ @Override
public void execute() {
// nothing to do
}
@@ -607,6 +612,7 @@ public void test_nonredoableTriggerCommand_RecordingCommand_138287() {
@Override
protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
return new TestCommand.Redoable() {
+ @Override
public void execute() {
// nothing to do
}
@@ -658,7 +664,7 @@ public void test_defaultUndoRedoOptionsMapReadOnly_bug207986() {
try {
TransactionImpl.DEFAULT_UNDO_REDO_OPTIONS.put(BOGUS_OPTION, Boolean.TRUE);
- Assert.fail("Should not have been permitted to add the bogus option");
+ Assertions.fail("Should not have been permitted to add the bogus option");
} catch (RuntimeException e) {
// success
System.out.println("Got expected runtime exception: " + e.getLocalizedMessage());
@@ -718,15 +724,15 @@ protected void doExecute() {
}
});
- assertEquals("Wrong number of copies on execute", newCopies, book[0].getCopies());
+ assertEquals(newCopies, book[0].getCopies(), "Wrong number of copies on execute");
getCommandStack().undo();
- assertFalse("Wrong number of copies on undo", book[0].getCopies() == newCopies);
+ assertFalse(book[0].getCopies() == newCopies, "Wrong number of copies on undo");
getCommandStack().redo();
- assertEquals("Wrong number of copies on redo", newCopies, book[0].getCopies());
+ assertEquals(newCopies, book[0].getCopies(), "Wrong number of copies on redo");
} finally {
domain.removeResourceSetListener(listener);
}
@@ -785,15 +791,15 @@ protected void doExecute() {
});
getCommandStack().execute(cc);
- assertEquals("Wrong number of copies on execute", newCopies, book[0].getCopies());
+ assertEquals(newCopies, book[0].getCopies(), "Wrong number of copies on execute");
getCommandStack().undo();
- assertFalse("Wrong number of copies on undo", book[0].getCopies() == newCopies);
+ assertFalse(book[0].getCopies() == newCopies, "Wrong number of copies on undo");
getCommandStack().redo();
- assertEquals("Wrong number of copies on redo", newCopies, book[0].getCopies());
+ assertEquals(newCopies, book[0].getCopies(), "Wrong number of copies on redo");
} finally {
domain.removeResourceSetListener(listener);
}
@@ -832,22 +838,27 @@ private URI unloadTestResource() {
public class UndoRedoResourceSetListener implements ResourceSetListener {
public int undoCount = 0;
+ @Override
public NotificationFilter getFilter() {
return null;
}
+ @Override
public boolean isAggregatePrecommitListener() {
return false;
}
+ @Override
public boolean isPostcommitOnly() {
return false;
}
+ @Override
public boolean isPrecommitOnly() {
return false;
}
+ @Override
public void resourceSetChanged(ResourceSetChangeEvent event) {
Transaction transaction = event.getTransaction();
@@ -857,6 +868,7 @@ public void resourceSetChanged(ResourceSetChangeEvent event) {
}
}
+ @Override
public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
return null;
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ValidateEditTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ValidateEditTest.java
index cb5071f5..77202f97 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ValidateEditTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ValidateEditTest.java
@@ -11,10 +11,10 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+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.Collection;
import java.util.Collections;
@@ -32,8 +32,8 @@
import org.eclipse.emf.transaction.tests.fixtures.TestCommand;
import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.emf.transaction.util.ValidateEditSupport;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests validate-edit support.
@@ -53,6 +53,7 @@ public boolean canExecute() {
return true;
}
+ @Override
public void execute() {
try {
book.setTitle(newTitle);
@@ -69,6 +70,7 @@ public boolean canExecute() {
return true;
}
+ @Override
public void execute() {
try {
book.setTitle(null);
@@ -103,7 +105,7 @@ public void ignore_test_validateEditRollback() {
try {
getCommandStack().execute(setTitle, null);
- Assert.fail("Should have rolled back");
+ Assertions.fail("Should have rolled back");
} catch (RollbackException e) {
// success
System.out.println("Got expected exception: " + e.getLocalizedMessage());
@@ -134,7 +136,7 @@ protected IStatus doValidateEdit(Transaction transaction, Collection extends R
try {
getCommandStack().execute(setTitle, null);
- Assert.fail("Should have rolled back");
+ Assertions.fail("Should have rolled back");
} catch (RollbackException e) {
// success
System.out.println("Got expected exception: " + e.getLocalizedMessage());
@@ -142,7 +144,7 @@ protected IStatus doValidateEdit(Transaction transaction, Collection extends R
fail(e);
}
- assertTrue("Custom validation not invoked", token[0]);
+ assertTrue(token[0], "Custom validation not invoked");
assertTitleNotChanged();
assertResourceNotDirty();
}
@@ -156,7 +158,7 @@ public void test_liveValidationFailure_validateEditOK() {
try {
getCommandStack().execute(clearTitle, null);
- Assert.fail("Should have rolled back");
+ Assertions.fail("Should have rolled back");
} catch (RollbackException e) {
// success
System.out.println("Got expected exception: " + e.getLocalizedMessage());
@@ -176,7 +178,7 @@ public void test_validationRollback_validateEditFails() {
try {
getCommandStack().execute(clearTitle, null);
- Assert.fail("Should have rolled back");
+ Assertions.fail("Should have rolled back");
} catch (RollbackException e) {
// success
System.out.println("Got expected exception: " + e.getLocalizedMessage());
@@ -248,10 +250,10 @@ void assertTitleNotChanged() {
}
void assertResourceDirty() {
- assertTrue("Resource not dirty", testResource.isModified());
+ assertTrue(testResource.isModified(), "Resource not dirty");
}
void assertResourceNotDirty() {
- assertFalse("Resource is dirty", testResource.isModified());
+ assertFalse(testResource.isModified(), "Resource is dirty");
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ValidationRollbackTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ValidationRollbackTest.java
index fa6bbe9b..8f9990ac 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ValidationRollbackTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/ValidationRollbackTest.java
@@ -11,12 +11,12 @@
*/
package org.eclipse.emf.transaction.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+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 java.util.Collections;
import java.util.EventObject;
@@ -54,8 +54,8 @@
import org.eclipse.emf.transaction.internal.EMFTransactionPlugin;
import org.eclipse.emf.transaction.tests.fixtures.LogCapture;
import org.eclipse.emf.transaction.tests.fixtures.TestListener;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests transaction validation and rollback scenarios.
@@ -94,6 +94,7 @@ public void test_rollback() {
// check that the changes were rolled back
domain.runExclusive(new Runnable() {
+ @Override
public void run() {
assertSame(oldTitle, book.getTitle());
assertSame(oldAuthor, book.getAuthor());
@@ -151,6 +152,7 @@ public void test_rollback_nested() {
// check that the outer transaction commit worked (values still ok)
domain.runExclusive(new Runnable() {
+ @Override
public void run() {
assertSame(oldTitle, book.getTitle());
assertSame(oldAuthor, book.getAuthor());
@@ -197,6 +199,7 @@ public void test_rollback_outer() {
// check that the outer transaction rollback reverted the values
domain.runExclusive(new Runnable() {
+ @Override
public void run() {
assertSame(oldTitle, book.getTitle());
assertSame(oldAuthor, book.getAuthor());
@@ -225,7 +228,7 @@ public void test_validation() {
xa.commit(); // this should throw RollbackException
- Assert.fail("Should have thrown RollbackException");
+ Assertions.fail("Should have thrown RollbackException");
} catch (RollbackException e) {
// success
status = e.getStatus();
@@ -263,7 +266,7 @@ public void test_validation_nestedCommitted() {
xa.commit(); // this should throw RollbackException
- Assert.fail("Should have thrown RollbackException");
+ Assertions.fail("Should have thrown RollbackException");
} catch (RollbackException e) {
// success
trace("Got expected exception: " + e.getLocalizedMessage());
@@ -296,6 +299,7 @@ public void test_validation_nestedRolledBack() {
// check that the outer transaction's new value is committed
domain.runExclusive(new Runnable() {
+ @Override
public void run() {
assertSame(newTitle, book.getTitle());
}
@@ -321,7 +325,7 @@ public void test_abort() {
xa.commit(); // this should throw RollbackException
- Assert.fail("Should have thrown RollbackException");
+ Assertions.fail("Should have thrown RollbackException");
} catch (RollbackException e) {
// success
trace("Got expected exception: " + e.getLocalizedMessage());
@@ -354,7 +358,7 @@ protected void doExecute() {
((InternalTransactionalEditingDomain) domain).startTransaction(false, null);
((InternalTransactionalEditingDomain) domain).startTransaction(false, null);
} catch (Exception e) {
- Assert.fail("Failed to start nested transaction: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to start nested transaction: " + e.getLocalizedMessage());
}
throw new TestError("intentional error");
}
@@ -365,7 +369,7 @@ protected void doExecute() {
} catch (TestError error) {
// success case -- error was not masked by IllegalStateException
} catch (IllegalArgumentException e) {
- Assert.fail("Rolled back out of order: " + e.getLocalizedMessage());
+ Assertions.fail("Rolled back out of order: " + e.getLocalizedMessage());
}
}
@@ -396,7 +400,7 @@ protected void doExecute() {
root.getBranches().clear();
}
});
- Assert.fail("Should have thrown Error");
+ Assertions.fail("Should have thrown Error");
} catch (Error e) {
assertSame(error, e);
}
@@ -405,15 +409,17 @@ protected void doExecute() {
class TestThread implements Runnable {
boolean ran = false;
+ @Override
public void run() {
// get the transaction lock
try {
domain.runExclusive(new Runnable() {
+ @Override
public void run() {
/* nothing to do */}
});
} catch (InterruptedException ex) {
- Assert.fail("Interrupted");
+ Assertions.fail("Interrupted");
}
synchronized (this) {
@@ -433,10 +439,10 @@ public void run() {
try {
testThread.wait(2000);
} catch (InterruptedException ex) {
- Assert.fail("Interrupted");
+ Assertions.fail("Interrupted");
}
- assertTrue("Dangling transaction lock", testThread.ran);
+ assertTrue(testThread.ran, "Dangling transaction lock");
}
} finally {
domain.removeResourceSetListener(testListener);
@@ -549,6 +555,7 @@ public void test_rollbackNotifiesCommandStackListeners_175725() {
class TestCSL implements CommandStackListener {
int invocationCount = 0;
+ @Override
public void commandStackChanged(EventObject event) {
invocationCount++;
}
@@ -570,8 +577,8 @@ public void commandStackChanged(EventObject event) {
stack.removeCommandStackListener(listener);
}
- assertEquals("Command-stack listener invoked wrong number of times", 2, listener.invocationCount);
- assertFalse("Should not have an undo command", stack.canUndo());
+ assertEquals(2, listener.invocationCount, "Command-stack listener invoked wrong number of times");
+ assertFalse(stack.canUndo(), "Should not have an undo command");
}
/**
@@ -592,7 +599,7 @@ protected void doExecute() {
try {
getCommandStack().execute(command, Collections.EMPTY_MAP);
- Assert.fail("Should have rolled back");
+ Assertions.fail("Should have rolled back");
} catch (RollbackException e) {
// expected
System.out.println("Got expected rollback");
@@ -600,7 +607,7 @@ protected void doExecute() {
// check that rollback was effective
assertEquals("Root Book", book.getTitle());
} catch (InterruptedException e) {
- Assert.fail("Interrupted");
+ Assertions.fail("Interrupted");
}
}
@@ -656,7 +663,7 @@ public void test_rollback_nesting_noNotifications_206819() {
commit();
if (notifications != null) {
- Assert.fail("Got " + notifications.size() + " post-commit notifications"); //$NON-NLS-2$
+ Assertions.fail("Got " + notifications.size() + " post-commit notifications"); //$NON-NLS-2$
}
} catch (Exception e) {
fail(e);
@@ -727,7 +734,7 @@ public void test_rollback_nesting_trailingNotifications_206819() {
commit();
if (notifications != null) {
- Assert.fail("Got " + notifications.size() + " post-commit notifications"); //$NON-NLS-2$
+ Assertions.fail("Got " + notifications.size() + " post-commit notifications"); //$NON-NLS-2$
}
} catch (Exception e) {
fail(e);
@@ -757,6 +764,7 @@ public void test_rollback_nestedTransactions_illegalSubList_227429() {
final Runnable run = new Runnable() {
Resource resource = null;
+ @Override
public void run() {
if (resource == null) {
resource = domain.getResourceSet().createResource(URI.createURI("http://localhost/foo.xmi"));
@@ -803,10 +811,12 @@ public void undo() {
undoRedo();
}
+ @Override
public void redo() {
undoRedo();
}
+ @Override
public void execute() {
run.run();
}
@@ -870,7 +880,7 @@ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws Rol
xa.commit();
- Assert.fail("Commit of root transaction should have failed.");
+ Assertions.fail("Commit of root transaction should have failed.");
} catch (RollbackException e) {
// roll-back is expected
} catch (Exception e) {
@@ -901,9 +911,9 @@ protected void doExecute() {
assertFalse(getCommandStack().canUndo());
} catch (RollbackException e) {
- Assert.fail("Should not have rolled back: " + e.getLocalizedMessage());
+ Assertions.fail("Should not have rolled back: " + e.getLocalizedMessage());
} catch (InterruptedException e) {
- Assert.fail("Interrupted");
+ Assertions.fail("Interrupted");
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/constraints/BookTitleConstraint.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/constraints/BookTitleConstraint.java
index c3cf93c9..b717a825 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/constraints/BookTitleConstraint.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/constraints/BookTitleConstraint.java
@@ -28,16 +28,16 @@ public class BookTitleConstraint
@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) {
return ctx.createFailureStatus();
}
}
-
+
return ctx.createSuccessStatus();
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/constraints/ClientSelector.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/constraints/ClientSelector.java
index 27a9c4c1..a01ca902 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/constraints/ClientSelector.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/constraints/ClientSelector.java
@@ -22,6 +22,7 @@
public class ClientSelector
implements IClientSelector {
+ @Override
public boolean selects(Object object) {
return ValidationRollbackTest.validationEnabled;
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/ItemDefaultPublicationDateTrigger.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/ItemDefaultPublicationDateTrigger.java
index 37d699d7..dc999a0e 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/ItemDefaultPublicationDateTrigger.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/ItemDefaultPublicationDateTrigger.java
@@ -32,11 +32,11 @@ public ItemDefaultPublicationDateTrigger() {
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(
@@ -45,7 +45,7 @@ protected Command trigger(TransactionalEditingDomain domain, Notification notifi
EXTLibraryPackage.eINSTANCE.getItem_PublicationDate(),
new java.util.Date());
}
-
+
return result;
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/JobListener.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/JobListener.java
index 36623ada..3c86f0f2 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/JobListener.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/JobListener.java
@@ -24,17 +24,17 @@
public class JobListener implements IJobChangeListener {
private final Object runningMonitor = new Object();
private boolean notifiedRunning;
-
+
private final Object doneMonitor = new Object();
private boolean notifiedDone;
-
+
private Job acquireJob = null;
-
+
/**
* Blocks the current thread until the AcquireJob starts running.
- *
+ *
* @return the AcquireJob
- *
+ *
* @throws InterruptedException if the current thread is interrupted
*/
public Job waitUntilRunning() throws InterruptedException {
@@ -43,15 +43,15 @@ public Job waitUntilRunning() throws InterruptedException {
runningMonitor.wait();
}
}
-
+
return acquireJob;
}
-
+
/**
* Blocks the current thread until the AcquireJob finishes.
- *
+ *
* @return the AcquireJob
- *
+ *
* @throws InterruptedException if the current thread is interrupted
*/
public Job waitUntilDone() throws InterruptedException {
@@ -60,11 +60,12 @@ public Job waitUntilDone() throws InterruptedException {
doneMonitor.wait();
}
}
-
+
return acquireJob;
}
// Documentation copied from the inherited specification
+ @Override
public void running(IJobChangeEvent event) {
if (event.getJob() == acquireJob) {
synchronized (runningMonitor) {
@@ -75,6 +76,7 @@ public void running(IJobChangeEvent event) {
}
// Documentation copied from the inherited specification
+ @Override
public void done(IJobChangeEvent event) {
if (event.getJob() == acquireJob) {
synchronized (doneMonitor) {
@@ -85,27 +87,31 @@ public void done(IJobChangeEvent event) {
}
// Documentation copied from the inherited specification
+ @Override
public void scheduled(IJobChangeEvent event) {
Job job = event.getJob();
-
+
if (acquireJob == null) {
- if (job.getClass().getName().endsWith("AcquireJob")) { //$NON-NLS-1$
+ if (job.getClass().getName().endsWith("AcquireJob")) {
acquireJob = job;
}
}
}
// Documentation copied from the inherited specification
+ @Override
public void sleeping(IJobChangeEvent event) {
// not interesting
}
-
+
// Documentation copied from the inherited specification
+ @Override
public void aboutToRun(IJobChangeEvent event) {
// not interesting
}
// Documentation copied from the inherited specification
+ @Override
public void awake(IJobChangeEvent event) {
// not interesting
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/LibraryDefaultBookTrigger.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/LibraryDefaultBookTrigger.java
index d7ad2162..42c9b20a 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/LibraryDefaultBookTrigger.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/LibraryDefaultBookTrigger.java
@@ -34,21 +34,21 @@ public LibraryDefaultBookTrigger() {
NotificationFilter.createEventTypeFilter(
Notification.ADD)));
}
-
+
@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$
+ newBook.setTitle("New Book");
result = new AddCommand(
domain,
newLibrary.getBooks(),
newBook);
}
-
+
return result;
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/LibraryDefaultNameTrigger.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/LibraryDefaultNameTrigger.java
index 9cc62a00..98b8c7a0 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/LibraryDefaultNameTrigger.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/LibraryDefaultNameTrigger.java
@@ -32,20 +32,20 @@ public LibraryDefaultNameTrigger() {
NotificationFilter.createEventTypeFilter(
Notification.ADD)));
}
-
+
@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$
+ "New Library");
}
-
+
return result;
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/LogCapture.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/LogCapture.java
index c401481c..cff2f578 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/LogCapture.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/LogCapture.java
@@ -11,9 +11,9 @@
*/
package org.eclipse.emf.transaction.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.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestCommand.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestCommand.java
index 97e02e27..26c9e1a1 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestCommand.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestCommand.java
@@ -28,21 +28,23 @@ public abstract class TestCommand
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 {
-
-
+
+
+ @Override
public boolean canRedo() {
return true;
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestEditingDomain.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestEditingDomain.java
index c6ab3eb1..a08765f8 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestEditingDomain.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestEditingDomain.java
@@ -24,7 +24,7 @@
*/
public class TestEditingDomain extends TransactionalEditingDomainImpl {
public static int instanceCount = 0;
-
+
public TestEditingDomain(AdapterFactory adapterFactory, ResourceSet resourceSet) {
super(adapterFactory, resourceSet);
instanceCount++;
@@ -42,9 +42,9 @@ public TransactionalEditingDomain createEditingDomain() {
TransactionalEditingDomain result = new TestEditingDomain(
new ComposedAdapterFactory(
ComposedAdapterFactory.Descriptor.Registry.INSTANCE));
-
+
mapResourceSet(result);
-
+
return result;
}
@@ -59,6 +59,6 @@ public TransactionalEditingDomain getEditingDomain(ResourceSet rset) {
// not used by the extension point
return null;
}
-
+
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestListener.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestListener.java
index 82952602..2d7139b6 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestListener.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestListener.java
@@ -30,16 +30,16 @@
public class TestListener extends ResourceSetListenerImpl {
/** The last pre-commit event received. */
public ResourceSetChangeEvent precommit;
-
+
/** The copied list of precommit notifications from the precommit event. */
public List precommitNotifications;
-
+
/** The last post-commit event received. */
public ResourceSetChangeEvent postcommit;
-
+
/** The copied list of postcommit notifications from the postcommit event.*/
public List postcommitNotifications;
-
+
public TestListener() {
super(NotificationFilter.ANY);
}
@@ -47,23 +47,23 @@ public TestListener() {
public TestListener(NotificationFilter filter) {
super(filter);
}
-
+
@Override
public Command transactionAboutToCommit(ResourceSetChangeEvent event)
throws RollbackException {
-
+
precommit = event;
- precommitNotifications = new ArrayList(event.getNotifications());
-
+ precommitNotifications = new ArrayList<>(event.getNotifications());
+
return null;
}
-
+
@Override
public void resourceSetChanged(ResourceSetChangeEvent event) {
postcommit = event;
- postcommitNotifications = new ArrayList(event.getNotifications());
+ postcommitNotifications = new ArrayList<>(event.getNotifications());
}
-
+
/**
* Clears the stored events.
*/
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestValidationEditingDomain.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestValidationEditingDomain.java
index 2d8877d5..4d838139 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestValidationEditingDomain.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/tests/fixtures/TestValidationEditingDomain.java
@@ -38,15 +38,15 @@
* @author David Cummings (dcummin)
*/
public class TestValidationEditingDomain extends TransactionalEditingDomainImpl {
-
+
public TestValidationEditingDomain(AdapterFactory adapterFactory) {
super(adapterFactory);
}
public static AtomicInteger readWriteValidatorHitCount = new AtomicInteger(0);
-
+
public static AtomicBoolean enableCustomValidator = new AtomicBoolean(false);
-
+
public static class FactoryImpl extends TransactionalEditingDomainImpl.FactoryImpl {
@Override
@@ -54,9 +54,9 @@ public TransactionalEditingDomain createEditingDomain() {
TransactionalEditingDomainImpl result = new TestValidationEditingDomain(
new ComposedAdapterFactory(
ComposedAdapterFactory.Descriptor.Registry.INSTANCE));
-
+
result.setValidatorFactory(new TestValidatorFactory());
-
+
mapResourceSet(result);
return result;
@@ -73,17 +73,19 @@ public TransactionalEditingDomain getEditingDomain(ResourceSet rset) {
// not used by the extension point
return null;
}
-
+
public class TestValidatorFactory implements TransactionValidator.Factory {
+ @Override
public TransactionValidator createReadOnlyValidator() {
return new ReadOnlyValidatorImpl();
}
+ @Override
public TransactionValidator createReadWriteValidator() {
return new TestReadWriteValidatorImpl();
}
}
-
+
public class TestReadWriteValidatorImpl extends ReadWriteValidatorImpl {
@Override
protected IValidator createValidator() {
@@ -92,6 +94,7 @@ protected IValidator createValidator() {
ILiveValidator validator = ModelValidationService.getInstance().newValidator(
EvaluationMode.LIVE);
validator.addConstraintFilter(new IConstraintFilter() {
+ @Override
public boolean accept(IConstraintDescriptor constraint,
EObject target) {
return false;
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/util/tests/CompositeChangeDescriptionTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/util/tests/CompositeChangeDescriptionTest.java
index a842dc1a..01978c5f 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/util/tests/CompositeChangeDescriptionTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/util/tests/CompositeChangeDescriptionTest.java
@@ -11,10 +11,10 @@
*/
package org.eclipse.emf.transaction.util.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+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.Iterator;
@@ -30,7 +30,7 @@
import org.eclipse.emf.transaction.TransactionChangeDescription;
import org.eclipse.emf.transaction.tests.AbstractTest;
import org.eclipse.emf.transaction.util.CompositeChangeDescription;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the {@link CompositeChangeDescription} class.
@@ -287,10 +287,12 @@ protected void doTearDown() throws Exception {
*/
private static class NonApplicableChange extends ChangeDescriptionImpl implements TransactionChangeDescription {
+ @Override
public boolean canApply() {
return false;
}
+ @Override
public boolean isEmpty() {
return false;
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/util/tests/LockTest.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/util/tests/LockTest.java
index efaa0318..47a4d87f 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/util/tests/LockTest.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/util/tests/LockTest.java
@@ -12,10 +12,10 @@
*/
package org.eclipse.emf.transaction.util.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.Field;
import java.util.concurrent.CountDownLatch;
@@ -32,10 +32,10 @@
import org.eclipse.emf.transaction.tests.fixtures.JobListener;
import org.eclipse.emf.transaction.util.Lock;
import org.eclipse.ui.PlatformUI;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+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 Lock} class.
@@ -43,11 +43,11 @@
* @author Christian W. Damus (cdamus)
*/
public class LockTest {
-
+
private Lock lock;
private Object monitor;
private volatile boolean interrupted;
-
+
/**
* Tests that the depth of an unacquired lock is zero.
*/
@@ -56,7 +56,7 @@ public void test_depth() {
assertNull(lock.getOwner());
assertEquals(0, lock.getDepth());
}
-
+
/**
* Tests that a thread can acquire and release the lock.
*/
@@ -71,223 +71,231 @@ public void test_acquire() {
fail(e);
}
}
-
+
/**
- * Tests that a thread attempting to acquire will wait for a thread
- * that owns the lock to release it.
+ * Tests that a thread attempting to acquire will wait for a thread that owns
+ * the lock to release it.
*/
@Test
public void test_waitForAcquire() {
Thread t = new Thread(new Runnable() {
+ @Override
public void run() {
try {
synchronized (monitor) {
lock.acquire(false);
-
+
// wake up the main thread so that it will try to acquire
monitor.notifyAll();
}
-
+
Thread.sleep(1000);
} catch (Exception e) {
- Assert.fail();
+ Assertions.fail();
} finally {
if (lock != null) {
lock.release();
}
}
- }});
-
+ }
+ });
+
try {
long start = System.currentTimeMillis();
-
+
synchronized (monitor) {
t.start();
-
+
// wait for the other thread to acquire the lock
monitor.wait();
}
-
+
// now attempt to acquire the lock while the other thread sleeps
lock.acquire(false);
-
- // check that we did actually wait for the lock :-)
+
+ // check that we did actually wait for the lock :-)
assertTrue(System.currentTimeMillis() - start >= 1000);
-
+
lock.release();
} catch (Exception e) {
fail(e);
}
}
-
+
/**
* Tests the timeout capability of acquiring.
*/
@Test
public void test_waitForAcquire_timeout() {
Thread t = new Thread(new Runnable() {
+ @Override
public void run() {
try {
synchronized (monitor) {
lock.acquire(false);
-
+
// wake up the main thread so that it will try to acquire
monitor.notifyAll();
}
-
+
Thread.sleep(5000);
} catch (Exception e) {
- Assert.fail();
+ Assertions.fail();
} finally {
if (lock != null) {
// will be cleared already by tearDown()
lock.release();
}
}
- }});
+ }
+ });
t.setDaemon(true);
-
+
try {
synchronized (monitor) {
t.start();
-
+
// wait for the other thread to acquire the lock
monitor.wait();
}
-
- // now attempt to acquire the lock with a timeout. Should give up
+
+ // now attempt to acquire the lock with a timeout. Should give up
assertFalse(lock.acquire(1000, false));
-
+
// we did not get it
assertEquals(0, lock.getDepth());
} catch (Exception e) {
fail(e);
}
}
-
+
/**
- * Tests that when the UI thread attempts to acquire, liveness is maintained
- * as the UI thread continues to process sync runnables.
+ * Tests that when the UI thread attempts to acquire, liveness is maintained as
+ * the UI thread continues to process sync runnables.
*/
@Test
public void test_uiSafeWaitForAcquire() {
if (!PlatformUI.isWorkbenchRunning()) {
// can only execute this test case in a workbench
- AbstractTest.trace("*** Test skipped because not running in a workbench ***"); //$NON-NLS-1$
+ AbstractTest.trace("*** Test skipped because not running in a workbench ***");
return;
}
-
- final int longInterval = PlatformUI.getWorkbench().getProgressService()
- .getLongOperationTime();
-
+
+ final int longInterval = PlatformUI.getWorkbench().getProgressService().getLongOperationTime();
+
final boolean syncRunnableFinished[] = new boolean[1];
-
+
Thread t = new Thread(new Runnable() {
+ @Override
public void run() {
try {
synchronized (monitor) {
lock.acquire(false);
-
+
// wake up the main thread so that it will try to acquire
monitor.notifyAll();
}
-
+
Thread.sleep(longInterval);
-
+
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+ @Override
public void run() {
syncRunnableFinished[0] = true;
- }});
-
+ }
+ });
+
Thread.sleep(longInterval);
} catch (Exception e) {
- Assert.fail();
+ Assertions.fail();
} finally {
if (lock != null) {
lock.release();
}
}
- }});
-
+ }
+ });
+
try {
long start = System.currentTimeMillis();
-
+
synchronized (monitor) {
t.start();
-
+
// wait for the other thread to acquire the lock
monitor.wait();
}
-
+
// now attempt to acquire the lock while the other thread sleeps
lock.uiSafeAcquire(false);
-
- // check that we did actually wait for the lock :-)
+
+ // check that we did actually wait for the lock :-)
assertTrue(System.currentTimeMillis() - start >= longInterval);
-
+
// check that the UI processed the synchronous Runnable
assertTrue(syncRunnableFinished[0]);
-
+
lock.release();
} catch (Exception e) {
fail(e);
}
}
-
+
/**
- * Tests that a non-exclusive thread can yield to another non-exclusive
- * thread.
+ * Tests that a non-exclusive thread can yield to another non-exclusive thread.
*/
@Test
public void test_yield() {
final boolean token[] = new boolean[1];
-
+
Thread t = new Thread(new Runnable() {
+ @Override
public void run() {
try {
synchronized (monitor) {
// wake up the main thread so that it will try to acquire
monitor.notifyAll();
}
-
+
lock.acquire(false);
-
- synchronized(monitor) {
+
+ synchronized (monitor) {
token[0] = true;
monitor.notify();
}
} catch (Exception e) {
- Assert.fail();
+ Assertions.fail();
} finally {
if (lock != null) {
lock.release();
}
}
- }});
-
+ }
+ });
+
try {
lock.acquire(false);
-
+
synchronized (monitor) {
t.start();
-
+
// wait for the other thread to acquire the lock
monitor.wait();
}
-
+
Thread.sleep(500);
-
+
// now yield to the other thread
assertTrue(lock.yield());
-
+
synchronized (monitor) {
lock.release();
-
+
// wait for the other thread to set the token
monitor.wait();
assertTrue(token[0]);
}
-
+
// now attempt to re-acquire the lock
lock.acquire(false);
lock.release();
@@ -295,56 +303,58 @@ public void run() {
fail(e);
}
}
-
+
/**
* Tests that a non-exclusive thread cannot yield to an exclusive thread.
*/
@Test
public void test_yieldExclusion() {
final boolean token[] = new boolean[1];
-
+
Thread t = new Thread(new Runnable() {
+ @Override
public void run() {
try {
synchronized (monitor) {
// wake up the main thread so that it will try to acquire
monitor.notifyAll();
}
-
- lock.acquire(true); // exclusive
-
- synchronized(monitor) {
+
+ lock.acquire(true); // exclusive
+
+ synchronized (monitor) {
token[0] = true;
monitor.notify();
}
} catch (Exception e) {
- Assert.fail();
+ Assertions.fail();
} finally {
if (lock != null) {
lock.release();
}
}
- }});
-
+ }
+ });
+
try {
lock.acquire(false);
-
+
synchronized (monitor) {
t.start();
-
+
// wait for the other thread to acquire the lock
monitor.wait();
}
-
+
Thread.sleep(500);
-
+
// now attempt to yield to the other thread
assertFalse(lock.yield());
-
+
synchronized (monitor) {
lock.release();
-
- // now, we're done. The other thread can proceed
+
+ // now, we're done. The other thread can proceed
monitor.wait();
assertTrue(token[0]);
}
@@ -352,7 +362,7 @@ public void run() {
fail(e);
}
}
-
+
/**
* Tests that a thread cannot yield when no other threads are waiting.
*/
@@ -360,96 +370,98 @@ public void run() {
public void test_yield_noneWaiting() {
try {
lock.acquire(false);
-
+
assertFalse(lock.yield());
-
+
lock.release();
} catch (Exception e) {
fail(e);
}
}
-
+
/**
- * Tests for correct propagation of thread interrupt from the acquire()
- * method.
+ * Tests for correct propagation of thread interrupt from the acquire() method.
*/
@Test
public void test_interrupt_acquire() {
Thread t = new Thread(new Runnable() {
+ @Override
public void run() {
try {
synchronized (monitor) {
// wake up the main thread so that it will try to acquire
monitor.notifyAll();
}
-
+
lock.acquire(false);
} catch (InterruptedException e) {
// pass
interrupted = true;
} catch (Exception e) {
- Assert.fail();
+ Assertions.fail();
}
- }});
-
+ }
+ });
+
try {
lock.acquire(false);
-
+
synchronized (monitor) {
t.start();
-
+
// wait for the other thread to acquire the lock
monitor.wait();
}
-
+
Thread.sleep(500);
-
+
// now interrupt the other thread
t.interrupt();
-
+
Thread.sleep(500);
-
+
lock.release();
-
+
assertTrue(interrupted);
} catch (Exception e) {
fail(e);
}
}
-
+
/**
- * Tests for correct propagation of thread interrupt from the acquire()
- * method when the thread is already interrupted upon entering it.
+ * Tests for correct propagation of thread interrupt from the acquire() method
+ * when the thread is already interrupted upon entering it.
*/
@Test
public void test_interrupt_acquire_alreadyInterrupted() {
try {
Thread.currentThread().interrupt();
lock.acquire(false);
-
- Assert.fail("Should have thrown InterruptedException"); //$NON-NLS-1$
+
+ Assertions.fail("Should have thrown InterruptedException");
} catch (InterruptedException e) {
// pass
- AbstractTest.trace("Got the expected InterruptedException"); //$NON-NLS-1$
+ AbstractTest.trace("Got the expected InterruptedException");
} catch (Exception e) {
fail(e);
}
}
-
+
/**
- * Tests for correct propagation of thread interrupt when the AcquireJob
- * of a uiSafeAcquire() call is interrupted.
+ * Tests for correct propagation of thread interrupt when the AcquireJob of a
+ * uiSafeAcquire() call is interrupted.
*/
@Test
public void test_interrupt_uiSafeAcquire_jobInterrupted() {
Thread t = new Thread(new Runnable() {
+ @Override
public void run() {
try {
synchronized (monitor) {
// wake up the main thread
monitor.notifyAll();
}
-
+
lock.uiSafeAcquire(false);
} catch (InterruptedException e) {
// pass
@@ -457,41 +469,42 @@ public void run() {
} catch (Exception e) {
fail(e);
}
- }});
-
+ }
+ });
+
JobListener jl = new JobListener();
-
+
try {
lock.acquire(false);
-
+
Job.getJobManager().addJobChangeListener(jl);
-
+
synchronized (monitor) {
t.start();
-
+
// wait for the other thread
monitor.wait();
}
-
+
Job acquireJob = jl.waitUntilRunning();
-
+
// wait a moment for the job to actually find a worker thread
- // (J2SE 5.0 on Mac is very fast)
+ // (J2SE 5.0 on Mac is very fast)
Thread.sleep(500);
-
+
// now interrupt the acquire Job
acquireJob.getThread().interrupt();
-
+
// be sure to sleep again, so that the job has time to detect its
- // interruption before we release the lock
+ // interruption before we release the lock
Thread.sleep(500);
-
+
lock.release();
-
+
jl.waitUntilDone();
-
+
t.join();
-
+
assertTrue(interrupted);
} catch (Exception e) {
fail(e);
@@ -499,59 +512,61 @@ public void run() {
Job.getJobManager().removeJobChangeListener(jl);
}
}
-
+
/**
- * Tests for correct propagation of thread interrupt when the acquire job
- * of a uiSafeAcquire() is cancelled.
+ * Tests for correct propagation of thread interrupt when the acquire job of a
+ * uiSafeAcquire() is cancelled.
*/
@Test
public void test_interrupt_uiSafeAcquire_jobCancelled() {
Thread t = new Thread(new Runnable() {
+ @Override
public void run() {
try {
synchronized (monitor) {
// wake up the main thread
monitor.notifyAll();
}
-
+
lock.uiSafeAcquire(false);
} catch (InterruptedException e) {
// pass
interrupted = true;
} catch (Exception e) {
- Assert.fail();
+ Assertions.fail();
}
- }});
-
+ }
+ });
+
JobListener jl = new JobListener();
-
+
try {
lock.acquire(false);
-
+
Job.getJobManager().addJobChangeListener(jl);
-
+
synchronized (monitor) {
t.start();
-
+
// wait for the other thread
monitor.wait();
}
-
+
// wait until the acquire job is running so that we will know that
- // the other thread is blocked
+ // the other thread is blocked
Job acquireJob = jl.waitUntilRunning();
-
+
Thread.sleep(500);
-
+
// now cancel the job via the progress monitor
acquireJob.cancel();
-
+
jl.waitUntilDone();
-
+
lock.release();
-
+
t.join();
-
+
assertTrue(interrupted);
} catch (Exception e) {
fail(e);
@@ -559,7 +574,7 @@ public void run() {
Job.getJobManager().removeJobChangeListener(jl);
}
}
-
+
/**
* Tests that when the UI thread attempts to acquire, liveness is maintained
* even if the UI thread is running an implicit job.
@@ -568,81 +583,86 @@ public void run() {
public void test_uiSafeWaitForAcquire_implicitJob_bug162141() {
if (!PlatformUI.isWorkbenchRunning()) {
// can only execute this test case in a workbench
- AbstractTest.trace("*** Test skipped because not running in a workbench ***"); //$NON-NLS-1$
+ AbstractTest.trace("*** Test skipped because not running in a workbench ***");
return;
}
// an identity rule
ISchedulingRule rule = new ISchedulingRule() {
+ @Override
public boolean isConflicting(ISchedulingRule rule) {
return rule == this;
}
-
+
+ @Override
public boolean contains(ISchedulingRule rule) {
return rule == this;
- }};
-
- final TransactionalEditingDomain domain =
- TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain();
-
+ }
+ };
+
+ final TransactionalEditingDomain domain = TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain();
+
lock = getLock(domain);
-
- final int longInterval = PlatformUI.getWorkbench().getProgressService()
- .getLongOperationTime();
-
+
+ final int longInterval = PlatformUI.getWorkbench().getProgressService().getLongOperationTime();
+
final boolean syncRunnableFinished[] = new boolean[1];
-
+
Thread t = new Thread(new Runnable() {
-
+
+ @Override
public void run() {
try {
synchronized (monitor) {
lock.acquire(false);
-
+
// wake up the main thread so that it will try to acquire
monitor.notifyAll();
}
-
+
Thread.sleep(longInterval);
-
+
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+ @Override
public void run() {
syncRunnableFinished[0] = true;
- }});
-
+ }
+ });
+
Thread.sleep(longInterval);
} catch (Exception e) {
- Assert.fail();
+ Assertions.fail();
} finally {
if (lock != null) {
lock.release();
}
}
- }});
-
+ }
+ });
+
try {
long start = System.currentTimeMillis();
-
+
synchronized (monitor) {
t.start();
-
+
// wait for the other thread to acquire the lock
monitor.wait();
}
-
+
// start an implicit job on our fake rule
Job.getJobManager().beginRule(rule, null);
-
+
try {
// now attempt to acquire the lock while the other thread sleeps
lock.uiSafeAcquire(false);
-
- // check that we did actually wait for the lock :-)
+
+ // check that we did actually wait for the lock :-)
assertTrue(System.currentTimeMillis() - start >= longInterval);
-
+
// check that the UI processed the synchronous Runnable
assertTrue(syncRunnableFinished[0]);
-
+
lock.release();
} finally {
Job.getJobManager().endRule(rule);
@@ -653,43 +673,44 @@ public void run() {
domain.dispose();
}
}
-
+
@Test
public void test_uiSafeWaitForAcquire_explicitJob_beginRule_262175() {
- final TransactionalEditingDomain domain =
- TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain();
-
- final CountDownLatch latch = new CountDownLatch(1);
-
+ final TransactionalEditingDomain domain = TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain();
+
+ final CountDownLatch latch = new CountDownLatch(1);
+
lock = getLock(domain);
-
- final boolean[] status = {false};
-
- Job job = new Job("TestJob") { //$NON-NLS-1$
-
+
+ final boolean[] status = { false };
+
+ Job job = new Job("TestJob") {
+
@Override
protected IStatus run(IProgressMonitor monitor) {
// test rule
ISchedulingRule rule = new ISchedulingRule() {
+ @Override
public boolean contains(ISchedulingRule rule) {
return rule == this;
}
+ @Override
public boolean isConflicting(ISchedulingRule rule) {
return rule == this;
}
};
-
+
// simulates ownership of a rule
Job.getJobManager().beginRule(rule, new NullProgressMonitor());
-
+
try {
latch.countDown();
lock.uiSafeAcquire(false);
-
- synchronized(status) {
+
+ synchronized (status) {
status[0] = true;
}
} catch (InterruptedException e) {
@@ -698,182 +719,179 @@ public boolean isConflicting(ISchedulingRule rule) {
lock.release();
Job.getJobManager().endRule(rule);
}
-
+
return Status.OK_STATUS;
}
};
-
+
try {
lock.acquire(true);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
-
+
try {
-
+
job.schedule();
-
+
latch.await();
-
+
Thread.sleep(1000); // make sure the Job entered the wait for this.lock
-
+
lock.release();
-
+
try {
job.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
-
+
} catch (InterruptedException e) {
fail(e);
} finally {
- synchronized(status) {
- assertTrue("Job did not acquire a rule", status[0]); //$NON-NLS-1$
+ synchronized (status) {
+ assertTrue(status[0], "Job did not acquire a rule");
}
}
}
-
- /**
- * Tests that when IJobManager::beginRule() method fails, we don't end up
- * with an AcquireJob getting and transfering the lock after we've already
- * given up.
- */
+
+ /**
+ * Tests that when IJobManager::beginRule() method fails, we don't end up with
+ * an AcquireJob getting and transfering the lock after we've already given up.
+ */
@Test
- public void test_uiSafeWaitForAcquire_beginRuleThrows_bug205857() {
- final ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot();
-
- final TransactionalEditingDomain domain =
- TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain();
-
- lock = getLock(domain);
-
- Thread t = new Thread(new Runnable() {
-
- public void run() {
- try {
- synchronized (monitor) {
- // wake up the main thread to give us a sched rule
- monitor.notifyAll();
- }
-
- lock.uiSafeAcquire(false);
- Assert.fail("Should have thrown InterruptedException"); //$NON-NLS-1$
- } catch (InterruptedException e) {
- // success
- System.out.println("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
- } catch (Exception e) {
- // success
- fail(e);
- } finally {
- // we were given this rule, so we must end it
- Job.getJobManager().endRule(rule);
- }
- }});
-
- try {
- Job.getJobManager().beginRule(rule, null);
- lock.acquire(false);
-
- synchronized (monitor) {
- t.start();
-
- // wait for the other thread to start
- monitor.wait();
- }
-
- // sleep just a bit to let the other thread start waiting for
- // the lock on its initial 250-millis hard wait
- Thread.sleep(50L);
-
- // hand over the scheduling rule before the other thread starts
- // the AcquireJob-based wait
- Job.getJobManager().transferRule(rule, t);
-
- // now, wait long enough for the other thread to start its
- // AcquireJob-based-wait and then release the lock
- Thread.sleep(250L);
- lock.release();
-
- // now, wait for the other thread to finish
- t.join();
-
- // sleep a bit
- Thread.sleep(250L);
-
- Thread owner = lock.getOwner();
- if (owner != null) {
- Assert.fail("Lock still owned by thread " + owner.getName()); //$NON-NLS-1$
- }
- } catch (Exception e) {
- fail(e);
- } finally {
- domain.dispose();
- }
- }
-
-
+ public void test_uiSafeWaitForAcquire_beginRuleThrows_bug205857() {
+ final ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot();
+
+ final TransactionalEditingDomain domain = TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain();
+
+ lock = getLock(domain);
+
+ Thread t = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ synchronized (monitor) {
+ // wake up the main thread to give us a sched rule
+ monitor.notifyAll();
+ }
+
+ lock.uiSafeAcquire(false);
+ Assertions.fail("Should have thrown InterruptedException");
+ } catch (InterruptedException e) {
+ // success
+ System.out.println("Got expected exception: " + e.getLocalizedMessage());
+ } catch (Exception e) {
+ // success
+ fail(e);
+ } finally {
+ // we were given this rule, so we must end it
+ Job.getJobManager().endRule(rule);
+ }
+ }
+ });
+
+ try {
+ Job.getJobManager().beginRule(rule, null);
+ lock.acquire(false);
+
+ synchronized (monitor) {
+ t.start();
+
+ // wait for the other thread to start
+ monitor.wait();
+ }
+
+ // sleep just a bit to let the other thread start waiting for
+ // the lock on its initial 250-millis hard wait
+ Thread.sleep(50L);
+
+ // hand over the scheduling rule before the other thread starts
+ // the AcquireJob-based wait
+ Job.getJobManager().transferRule(rule, t);
+
+ // now, wait long enough for the other thread to start its
+ // AcquireJob-based-wait and then release the lock
+ Thread.sleep(250L);
+ lock.release();
+
+ // now, wait for the other thread to finish
+ t.join();
+
+ // sleep a bit
+ Thread.sleep(250L);
+
+ Thread owner = lock.getOwner();
+ if (owner != null) {
+ Assertions.fail("Lock still owned by thread " + owner.getName());
+ }
+ } catch (Exception e) {
+ fail(e);
+ } finally {
+ domain.dispose();
+ }
+ }
+
//
// Fixture methods
//
-
- @Before
- public void setUp()
- throws Exception {
-
- AbstractTest.trace("===> Begin : " + this.getClass().getName()); //$NON-NLS-1$
-
+
+ @BeforeEach
+ public void setUp() throws Exception {
+
+ AbstractTest.trace("===> Begin : " + this.getClass().getName());
+
lock = new Lock();
monitor = new Object();
}
-
- @After
- public void tearDown()
- throws Exception {
-
+
+ @AfterEach
+ public void tearDown() throws Exception {
+
lock = null;
monitor = null;
interrupted = false;
-
- AbstractTest.trace("===> End : " + this.getClass().getName()); //$NON-NLS-1$
+
+ AbstractTest.trace("===> End : " + this.getClass().getName());
}
-
+
/**
* Records a failure due to an exception that should not have been thrown.
- *
+ *
* @param e the exception
*/
protected void fail(Exception e) {
e.printStackTrace();
- Assert.fail("Should not have thrown: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assertions.fail("Should not have thrown: " + e.getLocalizedMessage());
}
-
+
/**
* A reflective hack to get the transaction lock of an editing domain.
- *
+ *
* @param domain the editing domain
- *
+ *
* @return its transaction lock
*/
private Lock getLock(TransactionalEditingDomain domain) {
Lock result = null;
Field field = null;
-
+
try {
Class> clazz = domain.getClass();
-
- field = clazz.getDeclaredField("transactionLock"); //$NON-NLS-1$
+
+ field = clazz.getDeclaredField("transactionLock");
field.setAccessible(true);
-
+
result = (Lock) field.get(domain);
} catch (Exception e) {
- Assert.fail("Could not access transactionLock field: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ Assertions.fail("Could not access transactionLock field: " + e.getLocalizedMessage());
} finally {
if (field != null) {
field.setAccessible(false);
}
}
-
+
return result;
}
}
diff --git a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/util/tests/TransactionUtilTests.java b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/util/tests/TransactionUtilTests.java
index 793d2194..03ead374 100644
--- a/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/util/tests/TransactionUtilTests.java
+++ b/tests/org.eclipse.emf.transaction.tests/src/org/eclipse/emf/transaction/util/tests/TransactionUtilTests.java
@@ -11,8 +11,8 @@
*/
package org.eclipse.emf.transaction.util.tests;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
@@ -22,7 +22,7 @@
import org.eclipse.emf.transaction.Transaction;
import org.eclipse.emf.transaction.tests.AbstractTest;
import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests the {@link TransactionUtil} class.
@@ -74,6 +74,7 @@ public void test_getEditingDomain_Object() {
assertSame(domain, TransactionUtil.getEditingDomain(domain));
IEditingDomainProvider edp = new IEditingDomainProvider() {
+ @Override
public EditingDomain getEditingDomain() {
return domain;
}
diff --git a/tests/org.eclipse.emf.workspace.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.emf.workspace.tests/META-INF/MANIFEST.MF
index d4a0148d..43bfb0b5 100644
--- a/tests/org.eclipse.emf.workspace.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.emf.workspace.tests/META-INF/MANIFEST.MF
@@ -5,7 +5,12 @@ Bundle-SymbolicName: org.eclipse.emf.workspace.tests;singleton:=true
Bundle-Version: 1.11.0.qualifier
Bundle-Vendor: Eclipse.org
Bundle-Localization: plugin
-Require-Bundle: org.junit;bundle-version="[4.0.0,5.0.0)",
+Require-Bundle: junit-jupiter-api;bundle-version="5.11.3",
+ junit-jupiter-engine;bundle-version="5.11.3",
+ junit-vintage-engine;bundle-version="5.11.3",
+ junit-platform-commons;bundle-version="1.11.3",
+ junit-platform-engine;bundle-version="1.11.3",
+ junit-platform-runner;bundle-version="1.11.3",
org.eclipse.emf.workspace;bundle-version="1.3.0",
org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.emf.examples.library;bundle-version="[2.3.0,3.0.0)",
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/AbstractEMFOperationTest.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/AbstractEMFOperationTest.java
index 18ec5b96..edd321e7 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/AbstractEMFOperationTest.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/AbstractEMFOperationTest.java
@@ -13,12 +13,12 @@
*/
package org.eclipse.emf.workspace.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+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 java.lang.reflect.Method;
import java.util.Collections;
@@ -62,8 +62,8 @@
import org.eclipse.emf.workspace.tests.fixtures.TestListener;
import org.eclipse.emf.workspace.tests.fixtures.TestOperation;
import org.eclipse.emf.workspace.tests.fixtures.TestUndoContext;
-import org.junit.Assert;
-
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests the {@link AbstractEMFOperation} framework.
@@ -71,49 +71,50 @@
* @author Christian W. Damus (cdamus)
*/
public class AbstractEMFOperationTest extends AbstractTest {
-
- @org.junit.Test
+
+ @Test
public void test_execute_undo_redo() {
- UndoRedoResourceSetListener listener = new UndoRedoResourceSetListener();
- domain.addResourceSetListener(listener);
-
- assertEquals(0, listener.undoCount);
-
+ UndoRedoResourceSetListener listener = new UndoRedoResourceSetListener();
+ domain.addResourceSetListener(listener);
+
+ assertEquals(0, listener.undoCount);
+
startReading();
-
- final Book book = (Book) find("root/Root Book");
+
+ 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";
- final Writer newAuthor = (Writer) find("root/level1/Level1 Writer");
+
+ final String newTitle = "New Title";
+ final Writer newAuthor = (Writer) find("root/level1/Level1 Writer");
assertNotNull(newAuthor);
-
+
commit();
-
+
IUndoContext ctx = new TestUndoContext();
-
+
IUndoableOperation oper = new TestOperation(domain) {
@Override
protected void doExecute() {
book.setTitle(newTitle);
newAuthor.getBooks().add(book);
- }};
-
+ }
+ };
+
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 {
@@ -122,85 +123,86 @@ protected void doExecute() {
} catch (ExecutionException e) {
fail(e);
}
-
- assertEquals(1, listener.undoCount);
-
+
+ assertEquals(1, listener.undoCount);
+
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);
}
-
- assertEquals(2, listener.undoCount);
-
+
+ assertEquals(2, listener.undoCount);
+
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, where those triggers do non-EMF work.
*/
- @org.junit.Test
+ @Test
public void test_triggerCommands_nonEMF() {
- final String[] externalData = new String[] {"..."};
-
+ final String[] externalData = new String[] { "..." };
+
// one trigger sets the external data
domain.addResourceSetListener(new TriggerListener() {
-
+
@Override
- protected Command trigger(TransactionalEditingDomain domain,
- Notification notification) {
+ protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
if (notification.getFeature() == EXTLibraryPackage.Literals.LIBRARY__NAME) {
return new ExternalDataCommand(externalData, notification.getNewStringValue());
}
-
+
return null;
- }});
-
+ }
+ });
+
final Library[] newLibrary = new Library[1];
-
+
IUndoContext ctx = new TestUndoContext();
-
+
IUndoableOperation oper = new TestOperation(domain) {
@Override
protected void doExecute() {
- // 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
newLibrary[0] = EXTLibraryFactory.eINSTANCE.createLibrary();
root.getBranches().add(newLibrary[0]);
-
+
assertNull(newLibrary[0].getName());
assertTrue(newLibrary[0].getBranches().isEmpty());
-
- newLibrary[0].setName("New Library");
- }};
-
+
+ newLibrary[0].setName("New Library");
+ }
+ };
+
try {
oper.addContext(ctx);
history.execute(oper, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
- assertEquals("New Library", newLibrary[0].getName());
- assertEquals("New Library", externalData[0]);
-
+
+ assertEquals("New Library", newLibrary[0].getName());
+ assertEquals("New Library", externalData[0]);
+
commit();
try {
@@ -209,72 +211,73 @@ protected void doExecute() {
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were undone
assertFalse(root.getBranches().contains(newLibrary[0]));
- assertEquals("...", externalData[0]);
-
+ assertEquals("...", 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
assertTrue(root.getBranches().contains(newLibrary[0]));
- assertEquals("New Library", newLibrary[0].getName());
- assertEquals("New Library", externalData[0]);
-
+ assertEquals("New Library", newLibrary[0].getName());
+ assertEquals("New Library", externalData[0]);
+
commit();
}
-
+
/**
* Tests that trigger commands are executed correctly when executing operations,
* including undo and redo.
*/
- @org.junit.Test
+ @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 = new Library[1];
-
+
IUndoContext ctx = new TestUndoContext();
-
+
IUndoableOperation oper = new TestOperation(domain) {
@Override
protected void doExecute() {
- // 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
newLibrary[0] = EXTLibraryFactory.eINSTANCE.createLibrary();
root.getBranches().add(newLibrary[0]);
-
+
assertNull(newLibrary[0].getName());
assertTrue(newLibrary[0].getBranches().isEmpty());
- }};
-
+ }
+ };
+
try {
oper.addContext(ctx);
history.execute(oper, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
- assertEquals("New Library", newLibrary[0].getName());
+
+ assertEquals("New Library", newLibrary[0].getName());
assertEquals(1, newLibrary[0].getBooks().size());
- assertEquals("New Book", newLibrary[0].getBooks().get(0).getTitle());
-
+ assertEquals("New Book", newLibrary[0].getBooks().get(0).getTitle());
+
commit();
try {
@@ -283,76 +286,77 @@ protected void doExecute() {
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were undone
assertFalse(root.getBranches().contains(newLibrary[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
assertTrue(root.getBranches().contains(newLibrary[0]));
- assertEquals("New Library", newLibrary[0].getName());
+ assertEquals("New Library", newLibrary[0].getName());
assertEquals(1, newLibrary[0].getBooks().size());
- assertEquals("New Book", newLibrary[0].getBooks().get(0).getTitle());
-
+ assertEquals("New Book", newLibrary[0].getBooks().get(0).getTitle());
+
commit();
}
-
+
/**
* Tests that a command resulting from a pre-commit (trigger) listener will,
* itself, trigger further changes.
*/
- @org.junit.Test
+ @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 = new Library[1];
-
+
IUndoContext ctx = new TestUndoContext();
-
+
IUndoableOperation oper = new TestOperation(domain) {
@Override
protected void doExecute() {
- // 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
newLibrary[0] = EXTLibraryFactory.eINSTANCE.createLibrary();
root.getBranches().add(newLibrary[0]);
-
+
assertNull(newLibrary[0].getName());
assertTrue(newLibrary[0].getBranches().isEmpty());
- }};
-
+ }
+ };
+
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[0].getBooks().size());
Book book = newLibrary[0].getBooks().get(0);
- assertEquals("New Book", book.getTitle());
-
+ assertEquals("New Book", book.getTitle());
+
// the publication date is created by the cascaded trigger
assertNotNull(book.getPublicationDate());
-
+
commit();
try {
@@ -361,62 +365,63 @@ protected void doExecute() {
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were undone
assertFalse(root.getBranches().contains(newLibrary[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
assertTrue(root.getBranches().contains(newLibrary[0]));
assertEquals(1, newLibrary[0].getBooks().size());
book = newLibrary[0].getBooks().get(0);
- assertEquals("New Book", book.getTitle());
+ assertEquals("New Book", book.getTitle());
assertNotNull(book.getPublicationDate());
-
+
commit();
}
-
+
/**
* Tests that validation correctly rolls back changes and fails execution.
*/
- @org.junit.Test
+ @Test
public void test_validation() {
startReading();
-
- final Book book = (Book) find("root/Root Book");
+
+ 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");
+ final Writer newAuthor = (Writer) find("root/level1/Level1 Writer");
assertNotNull(newAuthor);
-
+
commit();
-
+
IUndoContext ctx = new TestUndoContext();
-
+
IUndoableOperation oper = new TestOperation(domain) {
@Override
protected void doExecute() {
book.setTitle(newTitle);
newAuthor.getBooks().add(book);
- }};
-
+ }
+ };
+
IStatus status = null;
-
+
try {
validationEnabled = true;
oper.addContext(ctx);
@@ -426,56 +431,53 @@ protected void doExecute() {
} 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 the application of options to the transaction used for executing.
*/
- @org.junit.Test
+ @Test
public void test_options_124741() {
startReading();
-
- final Book book = (Book) find("root/Root Book");
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
-
+
final String newTitle = null; // would cause validation failure
- final Writer newAuthor = (Writer) find("root/level1/Level1 Writer");
+ final Writer newAuthor = (Writer) find("root/level1/Level1 Writer");
assertNotNull(newAuthor);
-
+
commit();
-
+
TestListener listener = new TestListener();
domain.addResourceSetListener(listener);
-
+
IUndoContext ctx = new TestUndoContext();
-
- IUndoableOperation oper = new TestOperation(
- domain,
- makeOptions(
- Transaction.OPTION_NO_NOTIFICATIONS, true,
- Transaction.OPTION_NO_TRIGGERS, true,
- Transaction.OPTION_NO_VALIDATION, true)) {
-
+
+ IUndoableOperation oper = new TestOperation(domain, makeOptions(Transaction.OPTION_NO_NOTIFICATIONS, true,
+ Transaction.OPTION_NO_TRIGGERS, true, Transaction.OPTION_NO_VALIDATION, true)) {
+
@Override
protected void doExecute() {
book.setTitle(newTitle);
newAuthor.getBooks().add(book);
- }};
-
+ }
+ };
+
IStatus status = null;
try {
validationEnabled = true;
@@ -486,444 +488,446 @@ protected void doExecute() {
} finally {
validationEnabled = false;
}
-
+
startReading();
-
- // verify that the changes were applied. This asserts that execution did
- // succeed
+
+ // verify that the changes were applied. This asserts that execution did
+ // succeed
assertSame(newTitle, book.getTitle());
assertSame(newAuthor, book.getAuthor());
-
+
commit();
// no validation was performed
assertNotNull(status);
assertTrue(status.isOK());
-
+
// no triggers were invoked
assertNull(listener.precommit);
-
+
// no listeners were notified
assertNull(listener.postcommit);
}
-
+
/**
- * Tests that, when an exception unwinds the Java stack during the execution
- * of an AbstractEMFOperation, the active transactions are rolled back in
- * the correct sequence.
+ * Tests that, when an exception unwinds the Java stack during the execution of
+ * an AbstractEMFOperation, the active transactions are rolled back in the
+ * correct sequence.
*/
- @org.junit.Test
+ @Test
public void test_rollbackNestingTransactionOnException_135673() {
- CompositeEMFOperation outer = new CompositeEMFOperation(domain, "");
- AbstractEMFOperation inner = new AbstractEMFOperation(domain, "") {
+ CompositeEMFOperation outer = new CompositeEMFOperation(domain, "");
+ AbstractEMFOperation inner = new AbstractEMFOperation(domain, "") {
@Override
public boolean canExecute() {
return true;
}
+
@Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
// start some nested transactions
try {
((InternalTransactionalEditingDomain) domain).startTransaction(false, null);
((InternalTransactionalEditingDomain) domain).startTransaction(false, null);
} catch (Exception e) {
- Assert.fail("Failed to start nested transaction: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to start nested transaction: " + e.getLocalizedMessage());
}
- throw new TestError("intentional error");
- }};
-
+ throw new TestError("intentional error");
+ }
+ };
+
outer.add(inner);
-
+
try {
outer.execute(new NullProgressMonitor(), null);
} catch (ExecutionException e) {
- Assert.fail("Unexpected exception: " + e.getLocalizedMessage());
+ Assertions.fail("Unexpected exception: " + e.getLocalizedMessage());
} catch (TestError error) {
// success case -- error was not masked by IllegalStateException
} catch (IllegalArgumentException e) {
- Assert.fail("Rolled back out of order: " + e.getLocalizedMessage());
+ Assertions.fail("Rolled back out of order: " + e.getLocalizedMessage());
}
}
-
- @org.junit.Test
+
+ @Test
public void test_undoRedoNonEMFOperationWithEMFChanges_155268() {
- final CompositeEMFOperation comp = new CompositeEMFOperation(domain, "");
-
- final Book book = (Book) find("root/Root Book");
+ final CompositeEMFOperation comp = new CompositeEMFOperation(domain, "");
+
+ final Book book = (Book) find("root/Root Book");
assertNotNull(book);
-
- final AbstractEMFOperation emfOperation = new AbstractEMFOperation(domain, "") {
+
+ final AbstractEMFOperation emfOperation = new AbstractEMFOperation(domain, "") {
@Override
public boolean canExecute() {
return true;
}
-
+
@Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
- book.setTitle("155268");
-
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ book.setTitle("155268");
+
return Status.OK_STATUS;
}
};
-
+
IUndoableOperation nonEMFOperation = new IUndoableOperation() {
private IUndoableOperation wrappedOperation = emfOperation;
+ @Override
public void addContext(IUndoContext context) {
wrappedOperation.addContext(context);
}
+ @Override
public boolean canExecute() {
return wrappedOperation.canExecute();
}
+ @Override
public boolean canRedo() {
return wrappedOperation.canRedo();
}
+ @Override
public boolean canUndo() {
return wrappedOperation.canUndo();
}
+ @Override
public void dispose() {
wrappedOperation.dispose();
}
- public IStatus execute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ @Override
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return wrappedOperation.execute(monitor, info);
}
+ @Override
public IUndoContext[] getContexts() {
return wrappedOperation.getContexts();
}
+ @Override
public String getLabel() {
return wrappedOperation.getLabel();
}
+ @Override
public boolean hasContext(IUndoContext context) {
return wrappedOperation.hasContext(context);
}
- public IStatus redo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ @Override
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return wrappedOperation.redo(monitor, info);
}
+ @Override
public void removeContext(IUndoContext context) {
wrappedOperation.removeContext(context);
}
- public IStatus undo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
+ @Override
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return wrappedOperation.undo(monitor, info);
}
};
-
- AbstractEMFOperation root = new AbstractEMFOperation(domain, "") {
+
+ AbstractEMFOperation root = new AbstractEMFOperation(domain, "") {
@Override
public boolean canExecute() {
return true;
}
-
+
@Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
comp.execute(monitor, info);
-
+
return Status.OK_STATUS;
}
};
-
+
comp.add(nonEMFOperation);
-
+
try {
root.execute(new NullProgressMonitor(), null);
} catch (ExecutionException e) {
- Assert.fail("Unexpected exception: " + e.getLocalizedMessage());
+ Assertions.fail("Unexpected exception: " + e.getLocalizedMessage());
} catch (TestError error) {
// success case -- error was not masked by IllegalStateException
} catch (IllegalArgumentException e) {
- Assert.fail("Rolled back out of order: " + e.getLocalizedMessage());
+ Assertions.fail("Rolled back out of order: " + e.getLocalizedMessage());
}
-
- assertEquals(book.getTitle(),"155268");
-
+
+ assertEquals(book.getTitle(), "155268");
+
try {
root.undo(new NullProgressMonitor(), null);
} catch (ExecutionException e) {
- Assert.fail("Unexpected exception: " + e.getLocalizedMessage());
+ Assertions.fail("Unexpected exception: " + e.getLocalizedMessage());
} catch (TestError error) {
// success case -- error was not masked by IllegalStateException
} catch (IllegalArgumentException e) {
- Assert.fail("Rolled back out of order: " + e.getLocalizedMessage());
+ Assertions.fail("Rolled back out of order: " + e.getLocalizedMessage());
}
-
- assertFalse("155268".equals(book.getTitle()));
-
+
+ assertFalse("155268".equals(book.getTitle()));
+
try {
root.redo(new NullProgressMonitor(), null);
} catch (ExecutionException e) {
- Assert.fail("Unexpected exception: " + e.getLocalizedMessage());
+ Assertions.fail("Unexpected exception: " + e.getLocalizedMessage());
} catch (TestError error) {
// success case -- error was not masked by IllegalStateException
} catch (IllegalArgumentException e) {
- Assert.fail("Rolled back out of order: " + e.getLocalizedMessage());
+ Assertions.fail("Rolled back out of order: " + e.getLocalizedMessage());
+ }
+
+ assertEquals(book.getTitle(), "155268");
+ }
+
+ /**
+ * Tests that execute/undo/redo are contented with null as the
+ * progress monitor.
+ */
+ @Test
+ public void test_nullProgressMonitors_bug150033() {
+ IUndoableOperation operation = new AbstractEMFOperation(domain, "Test") {
+
+ @Override
+ protected IStatus doUndo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ monitor.isCanceled();
+
+ return super.doUndo(monitor, info);
+ }
+
+ @Override
+ protected IStatus doRedo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ monitor.isCanceled();
+
+ return super.doRedo(monitor, info);
+ }
+
+ @Override
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ monitor.isCanceled();
+ return Status.OK_STATUS;
+ }
+ };
+
+ try {
+ operation.execute(null, null);
+ } catch (Exception e) {
+ Assertions.fail("Should not have failed to execute with null monitor: " + e.getLocalizedMessage());
+ }
+
+ try {
+ operation.undo(null, null);
+ } catch (Exception e) {
+ Assertions.fail("Should not have failed to undo with null monitor: " + e.getLocalizedMessage());
+ }
+
+ try {
+ operation.redo(null, null);
+ } catch (Exception e) {
+ Assertions.fail("Should not have failed to redo with null monitor: " + e.getLocalizedMessage());
}
-
- assertEquals(book.getTitle(),"155268");
}
-
- /**
- * Tests that execute/undo/redo are contented with null as the
- * progress monitor.
- */
- @org.junit.Test
- public void test_nullProgressMonitors_bug150033() {
- IUndoableOperation operation = new AbstractEMFOperation(domain, "Test") {
-
- @Override
- protected IStatus doUndo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
- monitor.isCanceled();
-
- return super.doUndo(monitor, info);
- }
-
- @Override
- protected IStatus doRedo(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
- monitor.isCanceled();
-
- return super.doRedo(monitor, info);
- }
-
- @Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
-
- monitor.isCanceled();
- return Status.OK_STATUS;
- }};
-
- try {
- operation.execute(null, null);
- } catch (Exception e) {
- Assert.fail("Should not have failed to execute with null monitor: " + e.getLocalizedMessage());
- }
-
- try {
- operation.undo(null, null);
- } catch (Exception e) {
- Assert.fail("Should not have failed to undo with null monitor: " + e.getLocalizedMessage());
- }
-
- try {
- operation.redo(null, null);
- } catch (Exception e) {
- Assert.fail("Should not have failed to redo with null monitor: " + e.getLocalizedMessage());
- }
- }
-
- /**
- * Tests that recording-commands used as triggers are not undone twice.
- */
- @org.junit.Test
- public void test_undoWithRecordingCommandTrigger_218276() {
- final Book[] book = new Book[] {(Book) find("root/Root Book")};
- final int newCopies = 30;
-
- final RecordingCommand trigger = new RecordingCommand(domain, "Test Trigger") {
-
+
+ /**
+ * Tests that recording-commands used as triggers are not undone twice.
+ */
+ @Test
+ public void test_undoWithRecordingCommandTrigger_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";
-
+
+ final String newTitle = "New Title";
+
IUndoableOperation op = new TestOperation(domain) {
@Override
- protected void doExecute()
- throws ExecutionException {
+ protected void doExecute() throws ExecutionException {
book[0].setTitle(newTitle);
- }};
+ }
+ };
op.execute(null, null);
-
- assertEquals("Wrong number of copies on execute", newCopies, book[0].getCopies());
-
+
+ assertEquals(newCopies, book[0].getCopies(), "Wrong number of copies on execute");
+
op.undo(null, null);
-
- assertFalse("Wrong number of copies on undo", book[0].getCopies() == newCopies);
-
+
+ assertFalse(book[0].getCopies() == newCopies, "Wrong number of copies on undo");
+
op.redo(null, null);
-
- assertEquals("Wrong number of copies on redo", newCopies, book[0].getCopies());
+
+ assertEquals(newCopies, book[0].getCopies(), "Wrong number of copies on redo");
} catch (ExecutionException e) {
fail(e);
} finally {
domain.removeResourceSetListener(listener);
}
- }
-
- /**
- * Tests the API for changing options after construction of the operation.
- */
- @org.junit.Test
- public void test_setOptions_245419() {
+ }
+
+ /**
+ * Tests the API for changing options after construction of the operation.
+ */
+ @Test
+ public void test_setOptions_245419() {
startReading();
-
+
final Book book = (Book) find("root/Root Book");
assertNotNull(book);
-
+
final String newTitle = "New Title";
final Writer newAuthor = (Writer) find("root/level1/Level1 Writer");
assertNotNull(newAuthor);
-
+
commit();
-
- Map options = new java.util.HashMap();
+
+ Map options = new java.util.HashMap<>();
options.put("one", 1);
options.put("two", 2);
-
+
IUndoContext ctx = new TestUndoContext();
-
+
TestOperation oper = new TestOperation(domain, options) {
@Override
protected void doExecute() {
book.setTitle(newTitle);
newAuthor.getBooks().add(book);
- }};
-
+ }
+ };
+
// this should be no surprise
assertSubset(options, oper.getOptions());
-
+
// the options were copied from the original map
options.clear();
options.put("first", true);
options.put("second", false);
assertNotSubset(options, oper.getOptions());
-
+
// set the new options
assertTrue(oper.canSetOptions());
oper.setOptions(options);
-
+
// they are, indeed, changed
assertSubset(options, oper.getOptions());
-
+
try {
oper.addContext(ctx);
history.execute(oper, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// cannot change, now
assertFalse(oper.canSetOptions());
try {
oper.setOptions(options);
- Assert.fail("Should not have been able to set options");
+ Assertions.fail("Should not have been able to set options");
} catch (IllegalStateException e) {
// success
System.out.println("Got expected exception: " + e.getLocalizedMessage());
}
-
+
try {
assertTrue(history.canUndo(ctx));
history.undo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// nor now
assertFalse(oper.canSetOptions());
try {
oper.setOptions(options);
- Assert.fail("Should not have been able to set options");
+ Assertions.fail("Should not have been able to set options");
} catch (IllegalStateException e) {
// success
System.out.println("Got expected exception: " + e.getLocalizedMessage());
}
-
+
try {
assertTrue(history.canRedo(ctx));
history.redo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// and certainly not after a redo
assertFalse(oper.canSetOptions());
try {
oper.setOptions(options);
- Assert.fail("Should not have been able to set options");
+ Assertions.fail("Should not have been able to set options");
} catch (IllegalStateException e) {
// success
System.out.println("Got expected exception: " + e.getLocalizedMessage());
}
- }
-
- /**
+ }
+
+ /**
* Tests that execution of an AbstractEMFOperation can be made to reuse the
* active transaction.
*/
- @org.junit.Test
+ @Test
public void test_executeInActiveTransaction_245393() {
- IUndoableOperation operation = new AbstractEMFOperation(domain,
- "Test_executeInActiveTransaction") {
+ IUndoableOperation operation = new AbstractEMFOperation(domain, "Test_executeInActiveTransaction") {
@Override
- protected IStatus doExecute(IProgressMonitor monitor,
- IAdaptable info)
- throws ExecutionException {
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
final Transaction outer = ((InternalTransactionalEditingDomain) getEditingDomain())
- .getActiveTransaction();
- AbstractEMFOperation delegate = new AbstractEMFOperation(
- domain, "Test_executeInActiveTransaction_delegate") {
+ .getActiveTransaction();
+ AbstractEMFOperation delegate = new AbstractEMFOperation(domain,
+ "Test_executeInActiveTransaction_delegate") {
@Override
- protected IStatus doExecute(IProgressMonitor monitor,
- IAdaptable info)
- throws ExecutionException {
-
- assertSame("Transaction not reused by inner operation",
- outer,
- ((InternalTransactionalEditingDomain) getEditingDomain())
- .getActiveTransaction());
-
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ assertSame(outer,
+ ((InternalTransactionalEditingDomain) getEditingDomain()).getActiveTransaction(),
+ "Transaction not reused by inner operation");
+
return Status.OK_STATUS;
}
};
@@ -938,11 +942,11 @@ protected IStatus doExecute(IProgressMonitor monitor,
try {
operation.execute(new NullProgressMonitor(), null);
} catch (Exception e) {
- Assert.fail("Unexpected exception: " + e.getLocalizedMessage());
+ Assertions.fail("Unexpected exception: " + e.getLocalizedMessage());
}
}
-
- @org.junit.Test
+
+ @Test
public void test_rollbackOnError_250253() {
RollbackListener l = new RollbackListener();
l.install(domain);
@@ -951,39 +955,35 @@ public void test_rollbackOnError_250253() {
new AbstractEMFOperation(domain, "Test error result") {
@Override
- protected IStatus doExecute(IProgressMonitor monitor,
- IAdaptable info)
- throws ExecutionException {
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- return new Status(IStatus.ERROR,
- "org.eclipse.emf.transaction.tests", "I want to fail");
+ return new Status(IStatus.ERROR, "org.eclipse.emf.transaction.tests", "I want to fail");
}
}.execute(null, null);
-
+
l.assertRolledBack();
} catch (ExecutionException e) {
- Assert.fail("Shouldn't have an execution exception from a normal error return."
- + e.getLocalizedMessage());
+ Assertions.fail(
+ "Shouldn't have an execution exception from a normal error return." + e.getLocalizedMessage());
} finally {
l.uninstall(domain);
}
}
-
- /**
- * Tests that child operations reuse their parent's transaction when the parent
- * has the {@link Transaction#OPTION_VALIDATE_EDIT} option, but the child does not.
+
+ /**
+ * Tests that child operations reuse their parent's transaction when the parent
+ * has the {@link Transaction#OPTION_VALIDATE_EDIT} option, but the child does
+ * not.
*/
- @org.junit.Test
- public void test_inheritValidateEditOption_247691() {
+ @Test
+ public void test_inheritValidateEditOption_247691() {
- final CompositeEMFOperation outer = new CompositeEMFOperation(domain,
- "outer",
- Collections.singletonMap(Transaction.OPTION_VALIDATE_EDIT,
- Boolean.TRUE));
+ final CompositeEMFOperation outer = new CompositeEMFOperation(domain, "outer",
+ Collections.singletonMap(Transaction.OPTION_VALIDATE_EDIT, Boolean.TRUE));
outer.setTransactionNestingEnabled(false);
- AbstractEMFOperation inner = new AbstractEMFOperation(domain, "inner") {
+ AbstractEMFOperation inner = new AbstractEMFOperation(domain, "inner") {
@Override
public boolean canExecute() {
@@ -991,23 +991,17 @@ public boolean canExecute() {
}
@Override
- protected IStatus doExecute(IProgressMonitor monitor,
- IAdaptable info)
- throws ExecutionException {
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
Method getTransactionMethod = null;
-
+
try {
- getTransactionMethod = AbstractEMFOperation.class
- .getDeclaredMethod("getTransaction", new Class[0]);
+ getTransactionMethod = AbstractEMFOperation.class.getDeclaredMethod("getTransaction", new Class[0]);
getTransactionMethod.setAccessible(true);
- Object outerTransaction = getTransactionMethod.invoke(
- outer, new Object[0]);
- Object innerTransaction = getTransactionMethod.invoke(this,
- new Object[0]);
- assertTrue("Should have reused the parent transaction",
- innerTransaction == null
- || innerTransaction == outerTransaction);
+ Object outerTransaction = getTransactionMethod.invoke(outer, new Object[0]);
+ Object innerTransaction = getTransactionMethod.invoke(this, new Object[0]);
+ assertTrue(innerTransaction == null || innerTransaction == outerTransaction,
+ "Should have reused the parent transaction");
return Status.OK_STATUS;
} catch (Exception e) {
@@ -1025,27 +1019,26 @@ protected IStatus doExecute(IProgressMonitor monitor,
try {
outer.execute(new NullProgressMonitor(), null);
} catch (ExecutionException e) {
- Assert.fail("Unexpected exception: " + e.getLocalizedMessage());
+ Assertions.fail("Unexpected exception: " + e.getLocalizedMessage());
}
}
-
+
//
// Fixtures
//
-
- void assertSubset(Map, ?> expected, Map, ?> actual) {
+
+ void assertSubset(Map, ?> expected, Map, ?> actual) {
for (Map.Entry, ?> next : expected.entrySet()) {
- assertEquals("map is not a subset", next.getValue(), actual
- .get(next.getKey()));
+ assertEquals(next.getValue(), actual.get(next.getKey()), "map is not a subset");
}
}
-
- void assertNotSubset(Map, ?> notExpected, Map, ?> actual) {
- boolean subset = true;
-
+
+ void assertNotSubset(Map, ?> notExpected, Map, ?> actual) {
+ boolean subset = true;
+
for (Map.Entry, ?> next : notExpected.entrySet()) {
Object value = actual.get(next.getKey());
-
+
if (value == null) {
if (next.getValue() != null) {
subset = false;
@@ -1056,10 +1049,10 @@ void assertNotSubset(Map, ?> notExpected, Map, ?> actual) {
break;
}
}
-
- assertFalse("map is a subset", subset);
+
+ assertFalse(subset, "map is a subset");
}
-
+
static class TestError extends Error {
private static final long serialVersionUID = 1502966836790504386L;
@@ -1067,58 +1060,60 @@ static class TestError extends Error {
super(msg);
}
}
-
- public class UndoRedoResourceSetListener implements ResourceSetListener {
- public int undoCount = 0;
-
- public NotificationFilter getFilter() {
- return null;
- }
-
- public boolean isAggregatePrecommitListener() {
- return false;
- }
-
- public boolean isPostcommitOnly() {
- return false;
- }
-
- public boolean isPrecommitOnly() {
- return false;
- }
-
- public void resourceSetChanged(ResourceSetChangeEvent event) {
- Transaction transaction = event.getTransaction();
-
- Object obj = transaction.getOptions().get(Transaction.OPTION_IS_UNDO_REDO_TRANSACTION);
- if (Boolean.TRUE.equals(obj)) {
- undoCount++;
- }
- }
-
- public Command transactionAboutToCommit(ResourceSetChangeEvent event)
- throws RollbackException {
- return null;
- }
- }
-
- public static class RollbackListener
- extends TransactionalEditingDomainListenerImpl {
+
+ public class UndoRedoResourceSetListener implements ResourceSetListener {
+ public int undoCount = 0;
+
+ @Override
+ public NotificationFilter getFilter() {
+ return null;
+ }
+
+ @Override
+ public boolean isAggregatePrecommitListener() {
+ return false;
+ }
+
+ @Override
+ public boolean isPostcommitOnly() {
+ return false;
+ }
+
+ @Override
+ public boolean isPrecommitOnly() {
+ return false;
+ }
+
+ @Override
+ public void resourceSetChanged(ResourceSetChangeEvent event) {
+ Transaction transaction = event.getTransaction();
+
+ Object obj = transaction.getOptions().get(Transaction.OPTION_IS_UNDO_REDO_TRANSACTION);
+ if (Boolean.TRUE.equals(obj)) {
+ undoCount++;
+ }
+ }
+
+ @Override
+ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
+ return null;
+ }
+ }
+
+ public static class RollbackListener extends TransactionalEditingDomainListenerImpl {
private int rollbackCount = 0;
public void install(TransactionalEditingDomain domain) {
- TransactionUtil.getAdapter(domain,
- TransactionalEditingDomain.Lifecycle.class)
- .addTransactionalEditingDomainListener(this);
+ TransactionUtil.getAdapter(domain, TransactionalEditingDomain.Lifecycle.class)
+ .addTransactionalEditingDomainListener(this);
}
public void uninstall(TransactionalEditingDomain domain) {
- TransactionUtil.getAdapter(domain,
- TransactionalEditingDomain.Lifecycle.class)
- .removeTransactionalEditingDomainListener(this);
+ TransactionUtil.getAdapter(domain, TransactionalEditingDomain.Lifecycle.class)
+ .removeTransactionalEditingDomainListener(this);
}
-
+
public void reset() {
rollbackCount = 0;
}
@@ -1131,15 +1126,15 @@ public void transactionClosed(TransactionalEditingDomainEvent event) {
}
public void assertRolledBack() {
- assertEquals("No rollback occurred", 1, rollbackCount);
+ assertEquals(1, rollbackCount, "No rollback occurred");
}
public void assertRollbacks(int expected) {
- assertEquals("Wrong number of rollbacks", expected, rollbackCount);
+ assertEquals(expected, rollbackCount, "Wrong number of rollbacks");
}
public void assertNoRollbacks() {
- assertEquals("Should not have any rollbacks", 0, rollbackCount);
+ assertEquals(0, rollbackCount, "Should not have any rollbacks");
}
}
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/AbstractTest.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/AbstractTest.java
index 36fb2016..19a471c1 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/AbstractTest.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/AbstractTest.java
@@ -11,9 +11,9 @@
* Zeligsoft - Bug 234868
*/
package org.eclipse.emf.workspace.tests;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.io.IOException;
import java.io.InputStream;
@@ -40,7 +40,6 @@
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.examples.extlibrary.AudioVisualItem;
import org.eclipse.emf.examples.extlibrary.Book;
import org.eclipse.emf.examples.extlibrary.Library;
import org.eclipse.emf.examples.extlibrary.Periodical;
@@ -54,9 +53,9 @@
import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
import org.eclipse.emf.validation.model.IConstraintStatus;
import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
import org.osgi.framework.Bundle;
/**
@@ -95,7 +94,7 @@ public AbstractTest() {
// Test configuration methods
//
- @Before
+ @BeforeEach
public final void setUp() throws Exception {
trace("===> Begin : " + this.getClass().getName());
doSetUp();
@@ -124,7 +123,7 @@ protected void doSetUp() throws Exception {
testResource = originalRes;
root = (Library) find("root");
} catch (IOException e) {
- Assert.fail("Failed to load test model: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to load test model: " + e.getLocalizedMessage());
}
domain = createEditingDomain(rset);
@@ -137,7 +136,7 @@ protected TransactionalEditingDomain createEditingDomain(ResourceSet rset) {
return WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain(rset, history);
}
- @After
+ @AfterEach
public final void tearDown() throws Exception {
try {
doTearDown();
@@ -193,7 +192,7 @@ protected void delete(java.io.File file) {
info.setAttribute(EFS.ATTRIBUTE_ARCHIVE, false);
store.putInfo(info, EFS.SET_ATTRIBUTES, null);
} catch (Exception e) {
- Assert.fail("Failed to clean up test file: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to clean up test file: " + e.getLocalizedMessage());
}
}
@@ -213,7 +212,7 @@ protected void delete(IFile file) {
}
file.delete(true, null);
} catch (Exception e) {
- Assert.fail("Failed to clean up test file: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to clean up test file: " + e.getLocalizedMessage());
}
}
@@ -238,7 +237,7 @@ public boolean visit(IResource res) throws CoreException {
project.delete(true, true, null);
} catch (Exception e) {
- Assert.fail("Failed to clean up test project: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to clean up test project: " + e.getLocalizedMessage());
}
}
@@ -266,7 +265,7 @@ protected Resource createTestResource(String name) {
.createResource(URI.createPlatformResourceURI(file.getFullPath().toString(), true).toString());
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Exception creating test resource: " + e.getLocalizedMessage());
+ Assertions.fail("Exception creating test resource: " + e.getLocalizedMessage());
}
return result;
@@ -296,7 +295,7 @@ protected Resource createTestResource(String sourceName, String name, boolean en
result.load(Collections.EMPTY_MAP);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Exception creating test resource: " + e.getLocalizedMessage());
+ Assertions.fail("Exception creating test resource: " + e.getLocalizedMessage());
}
return result;
@@ -309,7 +308,7 @@ protected Resource createTestResource(String sourceName, String name, boolean en
*/
protected void fail(Exception e) {
e.printStackTrace();
- Assert.fail("Should not have thrown: " + e.getLocalizedMessage());
+ Assertions.fail("Should not have thrown: " + e.getLocalizedMessage());
}
/**
@@ -320,7 +319,7 @@ protected void fail(Exception e) {
* @see #find(String)
*/
protected void assertFound(String name) {
- assertNotNull("Did not find " + name, find(testResource, name));
+ assertNotNull(find(testResource, name), "Did not find " + name);
}
/**
@@ -335,7 +334,7 @@ protected void assertFound(String name) {
* @see #find(Object, String)
*/
protected void assertFound(Object start, String name) {
- assertNotNull("Did not find " + name, find(testResource, name));
+ assertNotNull(find(testResource, name), "Did not find " + name); // FIXME: use start!
}
/**
@@ -346,7 +345,7 @@ protected void assertFound(Object start, String name) {
* @see #find(String)
*/
protected void assertNotFound(String name) {
- assertNull("Found " + name, find(testResource, name));
+ assertNull(find(testResource, name), "Found " + name);
}
/**
@@ -361,7 +360,7 @@ protected void assertNotFound(String name) {
* @see #find(Object, String)
*/
protected void assertNotFound(Object start, String name) {
- assertNull("Found " + name, find(testResource, name));
+ assertNull(find(testResource, name), "Found " + name); // FIXME: use start!
}
/**
@@ -454,11 +453,6 @@ private GetName() {
super();
}
- @SuppressWarnings("unused")
- public Object caseAudoVisualItem(AudioVisualItem object) {
- return object.getTitle();
- }
-
@Override
public String caseBook(Book object) {
return object.getTitle();
@@ -697,10 +691,4 @@ protected IConstraintStatus findValidationStatus(IStatus status, int severity) {
return result;
}
-
- public void test_DoNothing() {
- // see Bugzilla 493963
- String why = "Maven wants to find a test to run in this abstract class";
- assertTrue(why.contains("Maven"));
- }
}
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/BasicWorkbenchTest.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/BasicWorkbenchTest.java
index 95971c64..2d62f5fe 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/BasicWorkbenchTest.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/BasicWorkbenchTest.java
@@ -11,9 +11,9 @@
*/
package org.eclipse.emf.workspace.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+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 java.util.Collections;
import java.util.List;
@@ -33,28 +33,28 @@
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
import org.eclipse.emf.workspace.tests.fixtures.TestListener;
-import org.junit.Assert;
-import org.junit.Test;
-
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Basic tests of the workbench editing domain, including compatibility with the
- * base {@link TransactionalEditingDomain} API and basic operation history integration.
+ * base {@link TransactionalEditingDomain} API and basic operation history
+ * integration.
*
* @author Christian W. Damus (cdamus)
*/
public class BasicWorkbenchTest extends AbstractTest {
/**
- * Tests that read transactions are not actually enforced for EList initialization,
- * etc.
+ * Tests that read transactions are not actually enforced for EList
+ * initialization, etc.
*/
@Test
public void test_read() {
try {
// should be able to read with running exclusive, as we cannot
- // actually enforce the protocol
- assertNotNull(find("root/Root Book")); //$NON-NLS-1$
+ // actually enforce the protocol
+ assertNotNull(find("root/Root Book"));
} catch (Exception e) {
fail(e);
}
@@ -63,117 +63,119 @@ public void test_read() {
/**
* Tests that we can read in a read-only transaction.
*/
- @org.junit.Test
+ @Test
public void test_read_readOnlyTransaction() {
// should be able to read in a read-only transaction
startReading();
-
- assertNotNull(find("root/Root Book")); //$NON-NLS-1$
-
+
+ assertNotNull(find("root/Root Book"));
+
commit();
}
/**
* Tests that we can read in a read-write transaction.
*/
- @org.junit.Test
+ @Test
public void test_read_readWriteTransaction() {
// should be able to read in a read/write transaction
startWriting();
-
- assertNotNull(find("root/Root Book")); //$NON-NLS-1$
-
+
+ assertNotNull(find("root/Root Book"));
+
commit();
}
/**
* Tests that we can read in a runExclusive() runnable.
*/
- @org.junit.Test
+ @Test
public void test_read_exclusive() {
try {
// should be able to read exclusively
final Book book[] = new Book[1];
-
+
domain.runExclusive(new Runnable() {
+ @Override
public void run() {
- book[0] = (Book) find("root/Root Book"); //$NON-NLS-1$
- }});
-
+ book[0] = (Book) find("root/Root Book");
+ }
+ });
+
assertNotNull(book[0]);
} catch (InterruptedException e) {
- Assert.fail("Should not be interrupted"); //$NON-NLS-1$
+ Assertions.fail("Should not be interrupted");
} catch (Exception e) {
fail(e);
}
}
-
+
/**
* Tests that we cannot write without a write transaction.
*/
- @org.junit.Test
+ @Test
public void test_write() {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
commit();
-
+
try {
// try to modify it
- book.setTitle("New Title"); //$NON-NLS-1$
-
+ book.setTitle("New Title");
+
// should have thrown
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (IllegalStateException e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
} catch (Exception e) {
fail(e);
}
}
-
+
/**
* Tests that we cannot write in a read-only transaction.
*/
- @org.junit.Test
+ @Test
public void test_write_readOnlytransaction() {
try {
startReading();
-
- Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
-
+
+ Book book = (Book) find("root/Root Book");
+
// try to modify it in a read/write transaction
- book.setTitle("New Title"); //$NON-NLS-1$
-
+ book.setTitle("New Title");
+
// should have thrown
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (IllegalStateException e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
} catch (Exception e) {
fail(e);
} finally {
rollback();
}
}
-
+
/**
* Tests that we can write in a read-write transaction.
*/
- @org.junit.Test
+ @Test
public void test_write_readWritetransaction() {
try {
startWriting();
-
- Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
-
+
+ Book book = (Book) find("root/Root Book");
+
// try to modify it in a read/write transaction
- book.setTitle("New Title"); //$NON-NLS-1$
-
+ book.setTitle("New Title");
+
commit();
-
- assertEquals("New Title", book.getTitle()); //$NON-NLS-1$
+
+ assertEquals("New Title", book.getTitle());
} catch (Exception e) {
fail(e);
} finally {
@@ -182,27 +184,28 @@ public void test_write_readWritetransaction() {
}
}
}
-
+
/**
* Tests that we cannot write from a different thread than the thread that
* currently has a write transaction open.
*/
- @org.junit.Test
+ @Test
public void test_write_wrongThread() {
final Object monitor = new Object();
-
+
Thread t = new Thread(new Runnable() {
-
+
+ @Override
public void run() {
Transaction xa = null;
-
+
try {
synchronized (monitor) {
xa = ((InternalTransactionalEditingDomain) domain).startTransaction(true, null);
-
+
// wake up the main thread
monitor.notifyAll();
-
+
// wait for the main thread to continue
monitor.wait();
}
@@ -213,26 +216,27 @@ public void run() {
xa.rollback();
}
}
- }});
-
+ }
+ });
+
try {
synchronized (monitor) {
t.start();
-
+
// wait for the thread to start its transaction
monitor.wait();
}
-
- Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
-
+
+ Book book = (Book) find("root/Root Book");
+
// try to modify it in a read/write transaction
- book.setTitle("New Title"); //$NON-NLS-1$
-
+ book.setTitle("New Title");
+
// should have thrown
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (IllegalStateException e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
} catch (Exception e) {
fail(e);
} finally {
@@ -242,32 +246,28 @@ public void run() {
}
}
}
-
+
/**
* Tests that we can use the command stack to execute a writing command.
*/
- @org.junit.Test
+ @Test
public void test_write_command() {
startReading();
-
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+
+ final Book book = (Book) find("root/Root Book");
commit();
-
+
try {
// try to modify it using a command
-
- Command cmd = new SetCommand(
- domain,
- book,
- EXTLibraryPackage.eINSTANCE.getBook_Title(),
- "New Title"); //$NON-NLS-1$
+
+ Command cmd = new SetCommand(domain, book, EXTLibraryPackage.eINSTANCE.getBook_Title(), "New Title");
((TransactionalCommandStack) domain.getCommandStack()).execute(cmd, null);
-
+
startReading();
-
- assertEquals("New Title", book.getTitle()); //$NON-NLS-1$
-
+
+ assertEquals("New Title", book.getTitle());
+
commit();
} catch (Exception e) {
fail(e);
@@ -278,36 +278,35 @@ public void test_write_command() {
* Tests that we can load and unload resources (having contents) without a write
* transaction.
*/
- @org.junit.Test
+ @Test
public void test_loadUnloadDuringRead() throws Exception {
// create a new domain that hasn't yet loaded the test resource
doTearDown();
ResourceSet rset = new ResourceSetImpl();
domain = createEditingDomain(rset);
-
+
TestListener listener = new TestListener();
domain.addResourceSetListener(listener);
-
+
startReading();
-
+
Resource res = rset.createResource(
- URI.createURI(EmfWorkbenchTestsBundle.getEntry(
- "/test_models/test_model.extlibrary").toString())); //$NON-NLS-1$
+ URI.createURI(EmfWorkbenchTestsBundle.getEntry("/test_models/test_model.extlibrary").toString()));
res.load(Collections.EMPTY_MAP);
-
+
commit();
-
+
// check that we got the expected events
assertNotNull(listener.postcommit);
List notifications = listener.postcommit.getNotifications();
assertFalse(notifications.isEmpty());
-
+
// look for an event indicating resource was loaded and one indicating
- // that a root was added. The root added event should come first!
+ // that a root was added. The root added event should come first!
Notification rootAdded = null;
Notification resLoaded = null;
-
+
for (Notification next : notifications) {
if (next.getNotifier() == res) {
if (next.getFeatureID(null) == Resource.RESOURCE__IS_LOADED) {
@@ -322,28 +321,28 @@ public void test_loadUnloadDuringRead() throws Exception {
}
}
}
-
+
assertNotNull(rootAdded);
assertNotNull(resLoaded);
-
- listener.reset(); // clear stored events
-
+
+ listener.reset(); // clear stored events
+
startReading();
-
+
res.unload();
-
+
commit();
-
+
// check that we got the expected events
assertNotNull(listener.postcommit);
notifications = listener.postcommit.getNotifications();
assertFalse(notifications.isEmpty());
-
+
// look for an event indicating resource was unloaded and one indicating
- // that a root was removed. The root removed event should come first!
+ // that a root was removed. The root removed event should come first!
Notification rootRemoved = null;
Notification resUnloaded = null;
-
+
for (Notification next : notifications) {
if (next.getNotifier() == res) {
if (next.getFeatureID(null) == Resource.RESOURCE__IS_LOADED) {
@@ -358,43 +357,43 @@ public void test_loadUnloadDuringRead() throws Exception {
}
}
}
-
+
assertNotNull(rootRemoved);
assertNotNull(resUnloaded);
}
-
+
/**
* Tests that changes to the contents of a loaded resource may not be performed
* in a read transaction.
*/
- @org.junit.Test
+ @Test
public void test_resourceContentsChanges_read() {
try {
startReading();
-
+
testResource.getContents().add(EXTLibraryFactory.eINSTANCE.createLibrary());
-
+
// should have thrown
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (IllegalStateException e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
} catch (Exception e) {
fail(e);
} finally {
rollback();
}
}
-
+
/**
- * Tests that changes to the contents of a loaded resource may be performed
- * in a write transaction.
+ * Tests that changes to the contents of a loaded resource may be performed in a
+ * write transaction.
*/
- @org.junit.Test
+ @Test
public void test_resourceContentsChanges_write() {
try {
startWriting();
-
+
testResource.getContents().add(EXTLibraryFactory.eINSTANCE.createLibrary());
} catch (Exception e) {
fail(e);
@@ -402,45 +401,45 @@ public void test_resourceContentsChanges_write() {
rollback();
}
}
-
+
/**
- * Tests that we cannot add a root to a newly created resource in a read transaction.
+ * Tests that we cannot add a root to a newly created resource in a read
+ * transaction.
*/
- @org.junit.Test
+ @Test
public void test_newResourceContentsChanges_read() {
try {
startReading();
-
- Resource res = domain.getResourceSet().createResource(
- URI.createFileURI("/tmp/foo.extlibrary")); //$NON-NLS-1$
+
+ Resource res = domain.getResourceSet().createResource(URI.createFileURI("/tmp/foo.extlibrary"));
assertFalse(res.isLoaded());
-
+
res.getContents().add(EXTLibraryFactory.eINSTANCE.createLibrary());
-
+
// should have thrown
- Assert.fail("Should have thrown IllegalStateException"); //$NON-NLS-1$
+ Assertions.fail("Should have thrown IllegalStateException");
} catch (IllegalStateException e) {
// success
- trace("Got expected exception: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ trace("Got expected exception: " + e.getLocalizedMessage());
} catch (Exception e) {
fail(e);
} finally {
rollback();
}
}
-
+
/**
- * Tests that we can add a root to a newly created resource in a write transaction.
+ * Tests that we can add a root to a newly created resource in a write
+ * transaction.
*/
- @org.junit.Test
+ @Test
public void test_newResourceContentsChanges_write() {
try {
startWriting();
-
- Resource res = domain.getResourceSet().createResource(
- URI.createFileURI("/tmp/foo.extlibrary")); //$NON-NLS-1$
+
+ Resource res = domain.getResourceSet().createResource(URI.createFileURI("/tmp/foo.extlibrary"));
assertFalse(res.isLoaded());
-
+
res.getContents().add(EXTLibraryFactory.eINSTANCE.createLibrary());
} catch (Exception e) {
fail(e);
diff --git a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/CompositeEMFOperationTest.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/CompositeEMFOperationTest.java
index 1a09956c..6ff74885 100644
--- a/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/CompositeEMFOperationTest.java
+++ b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/CompositeEMFOperationTest.java
@@ -12,12 +12,12 @@
*/
package org.eclipse.emf.workspace.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+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 java.lang.reflect.Field;
import java.util.Arrays;
@@ -52,9 +52,8 @@
import org.eclipse.emf.workspace.tests.fixtures.NullOperation;
import org.eclipse.emf.workspace.tests.fixtures.TestOperation;
import org.eclipse.emf.workspace.tests.fixtures.TestUndoContext;
-import org.junit.Assert;
-import org.junit.Test;
-
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests the {@link CompositeEMFOperation} class.
@@ -62,68 +61,54 @@
* @author Christian W. Damus (cdamus)
*/
public class CompositeEMFOperationTest extends AbstractTest {
- private static IStatus ERROR_STATUS =
- new Status(IStatus.ERROR, "bogus", 1, "no message", null); //$NON-NLS-1$ //$NON-NLS-2$
+ private static IStatus ERROR_STATUS = new Status(IStatus.ERROR, "bogus", 1, "no message", null); //$NON-NLS-2$
+
/**
* Tests that the undo contexts of the composite correctly aggregate the
* contexts of the children that it contains.
*/
@Test
public void test_contexts() {
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
IUndoContext ctx1 = new UndoContext();
IUndoContext ctx2 = new UndoContext();
IUndoContext ctx3 = new UndoContext();
-
+
IUndoableOperation child1 = new NullOperation();
IUndoableOperation child2 = new NullOperation();
IUndoableOperation child3 = new NullOperation();
-
+
// configure some contexts
child1.addContext(ctx1);
child2.addContext(ctx2);
child2.addContext(ctx1);
child3.addContext(ctx3);
-
+
// no contexts, yet
- assertEquals(
- Collections.EMPTY_LIST,
- Arrays.asList(composite.getContexts()));
-
+ assertEquals(Collections.EMPTY_LIST, Arrays.asList(composite.getContexts()));
+
composite.add(child1);
- assertEquals(
- Arrays.asList(new IUndoContext[] {ctx1}),
- Arrays.asList(composite.getContexts()));
-
+ assertEquals(Arrays.asList(new IUndoContext[] { ctx1 }), Arrays.asList(composite.getContexts()));
+
// note that we don't get ctx1 twice
composite.add(child2);
- assertEquals(
- Arrays.asList(new IUndoContext[] {ctx1, ctx2}),
- Arrays.asList(composite.getContexts()));
-
+ assertEquals(Arrays.asList(new IUndoContext[] { ctx1, ctx2 }), Arrays.asList(composite.getContexts()));
+
composite.add(child3);
- assertEquals(
- Arrays.asList(new IUndoContext[] {ctx1, ctx2, ctx3}),
- Arrays.asList(composite.getContexts()));
-
+ assertEquals(Arrays.asList(new IUndoContext[] { ctx1, ctx2, ctx3 }), Arrays.asList(composite.getContexts()));
+
// still have ctx1, but not ctx2
composite.remove(child2);
- assertEquals(
- Arrays.asList(new IUndoContext[] {ctx1, ctx3}),
- Arrays.asList(composite.getContexts()));
-
+ assertEquals(Arrays.asList(new IUndoContext[] { ctx1, ctx3 }), Arrays.asList(composite.getContexts()));
+
composite.remove(child1);
- assertEquals(
- Arrays.asList(new IUndoContext[] {ctx3}),
- Arrays.asList(composite.getContexts()));
-
+ assertEquals(Arrays.asList(new IUndoContext[] { ctx3 }), Arrays.asList(composite.getContexts()));
+
composite.remove(child3);
- assertEquals(
- Collections.EMPTY_LIST,
- Arrays.asList(composite.getContexts()));
+ assertEquals(Collections.EMPTY_LIST, Arrays.asList(composite.getContexts()));
}
-
+
/**
* Tests that the undo contexts of the composite correctly aggregate the
* contexts of the children that it contains, when manipulating the children
@@ -131,212 +116,200 @@ public void test_contexts() {
*/
@Test
public void test_contexts_listIterator_125151() {
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
IUndoContext ctx1 = new UndoContext();
IUndoContext ctx2 = new UndoContext();
IUndoContext ctx3 = new UndoContext();
-
+
IUndoableOperation child1 = new NullOperation();
IUndoableOperation child2 = new NullOperation();
IUndoableOperation child3 = new NullOperation();
-
+
// configure some contexts
child1.addContext(ctx1);
child2.addContext(ctx2);
child2.addContext(ctx1);
child3.addContext(ctx3);
-
+
ListIterator iter = composite.listIterator();
-
+
// no contexts, yet
- assertEquals(
- Collections.EMPTY_LIST,
- Arrays.asList(composite.getContexts()));
-
+ assertEquals(Collections.EMPTY_LIST, Arrays.asList(composite.getContexts()));
+
iter.add(child1);
- assertEquals(
- Arrays.asList(new IUndoContext[] {ctx1}),
- Arrays.asList(composite.getContexts()));
-
+ assertEquals(Arrays.asList(new IUndoContext[] { ctx1 }), Arrays.asList(composite.getContexts()));
+
// note that we don't get ctx1 twice
iter.add(child2);
- assertEquals(
- Arrays.asList(new IUndoContext[] {ctx1, ctx2}),
- Arrays.asList(composite.getContexts()));
-
+ assertEquals(Arrays.asList(new IUndoContext[] { ctx1, ctx2 }), Arrays.asList(composite.getContexts()));
+
iter.add(child3);
- assertEquals(
- Arrays.asList(new IUndoContext[] {ctx1, ctx2, ctx3}),
- Arrays.asList(composite.getContexts()));
-
+ assertEquals(Arrays.asList(new IUndoContext[] { ctx1, ctx2, ctx3 }), Arrays.asList(composite.getContexts()));
+
// still have ctx1, but not ctx2 when we remove child2
iter.previous();
iter.previous();
iter.remove();
- assertEquals(
- Arrays.asList(new IUndoContext[] {ctx1, ctx3}),
- Arrays.asList(composite.getContexts()));
-
+ assertEquals(Arrays.asList(new IUndoContext[] { ctx1, ctx3 }), Arrays.asList(composite.getContexts()));
+
// removing child1
iter.previous();
iter.remove();
- assertEquals(
- Arrays.asList(new IUndoContext[] {ctx3}),
- Arrays.asList(composite.getContexts()));
-
+ assertEquals(Arrays.asList(new IUndoContext[] { ctx3 }), Arrays.asList(composite.getContexts()));
+
// removing child3
iter.next();
iter.remove();
- assertEquals(
- Collections.EMPTY_LIST,
- Arrays.asList(composite.getContexts()));
+ assertEquals(Collections.EMPTY_LIST, Arrays.asList(composite.getContexts()));
}
-
+
/**
* Tests the aggregation of canExecute() from child operations.
*/
@Test
public void test_canExecute() {
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
- CompositeEMFOperation composite2 = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+ CompositeEMFOperation composite2 = new CompositeEMFOperation(domain, "Composite");
+
composite.add(new NullOperation());
composite.add(new NullOperation());
composite.add(composite2);
composite.add(new NullOperation());
-
+
composite2.add(new NullOperation());
composite2.add(new NullOperation(false)); // can't execute this one
composite2.add(new NullOperation());
-
+
assertFalse(composite.canExecute());
}
-
+
/**
* Tests the aggregation of canUndo() from child operations.
*/
@Test
public void test_canUndo() {
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
- CompositeEMFOperation composite2 = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+ CompositeEMFOperation composite2 = new CompositeEMFOperation(domain, "Composite");
+
composite.add(new NullOperation());
composite.add(new NullOperation());
composite.add(composite2);
composite.add(new NullOperation());
-
+
composite2.add(new NullOperation());
composite2.add(new NullOperation(true, false)); // can't undo this one
composite2.add(new NullOperation());
-
+
composite.addContext(ctx);
assertTrue(composite.canExecute());
-
+
try {
history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
assertFalse(composite.canUndo());
assertFalse(history.canUndo(ctx));
}
-
+
/**
* Tests the aggregation of canRedo() from child operations.
*/
@Test
public void test_canRedo() {
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
- CompositeEMFOperation composite2 = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+ CompositeEMFOperation composite2 = new CompositeEMFOperation(domain, "Composite");
+
composite.add(new NullOperation());
composite.add(new NullOperation());
composite.add(composite2);
composite.add(new NullOperation());
-
+
composite2.add(new NullOperation());
composite2.add(new NullOperation(true, true, false)); // can undo but not redo
composite2.add(new NullOperation());
-
+
composite.addContext(ctx);
assertTrue(composite.canExecute());
-
+
try {
history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
assertTrue(composite.canUndo());
assertTrue(history.canUndo(ctx));
-
+
try {
history.undo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
assertFalse(composite.canRedo());
assertFalse(history.canRedo(ctx));
}
-
+
@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();
-
+
// non-EMF "external" data to be modified by the composite
final String[] externalData = new String[1];
- externalData[0] = "..."; //$NON-NLS-1$
-
+ externalData[0] = "...";
+
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
composite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
book.setTitle(newTitle);
- }});
-
+ }
+ });
+
composite.add(new ChangeExternalData(externalData, book));
-
+
composite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
newAuthor.getBooks().add(book);
- }});
-
+ }
+ });
+
try {
composite.addContext(ctx);
history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were applied
assertSame(newTitle, book.getTitle());
assertEquals(newTitle, externalData[0]);
assertSame(newAuthor, book.getAuthor());
-
+
commit();
try {
@@ -345,100 +318,101 @@ protected void doExecute() {
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were undone
assertSame(oldTitle, book.getTitle());
- assertEquals("...", externalData[0]); //$NON-NLS-1$
+ assertEquals("...", externalData[0]);
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());
assertEquals(newTitle, externalData[0]);
assertSame(newAuthor, book.getAuthor());
-
+
commit();
}
-
+
/**
- * Tests undo/redo of nested non-EMF operations, to check the correct
- * nesting of non-EMF transactions with change descriptions encapsulating
- * non-EMF changes.
+ * Tests undo/redo of nested non-EMF operations, to check the correct nesting of
+ * non-EMF transactions with change descriptions encapsulating non-EMF changes.
*/
@Test
public void test_execute_undo_redo_nested() {
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();
-
+
// non-EMF "external" data to be modified by the composite
final String[] externalData = new String[1];
- externalData[0] = "..."; //$NON-NLS-1$
-
+ externalData[0] = "...";
+
// non-EMF "external" data to be modified by the nested composite
final String[] externalData2 = new String[1];
- externalData2[0] = ":::"; //$NON-NLS-1$
-
+ externalData2[0] = ":::";
+
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
composite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
book.setTitle(newTitle);
- }});
-
+ }
+ });
+
composite.add(new ChangeExternalData(externalData, book));
-
+
// more nesting
ICompositeOperation composite2 = new NonEMFCompositeOperation();
composite2.add(new ChangeExternalData(externalData2, book));
composite.add(composite2);
-
+
// EMF change in the nested non-transactional composite
composite2.add(new TestOperation(domain) {
@Override
protected void doExecute() {
newAuthor.getBooks().add(book);
- }});
-
+ }
+ });
+
try {
composite.addContext(ctx);
history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were applied
assertSame(newTitle, book.getTitle());
assertEquals(newTitle, externalData[0]);
assertEquals(newTitle, externalData2[0]);
assertSame(newAuthor, book.getAuthor());
-
+
commit();
try {
@@ -447,88 +421,90 @@ protected void doExecute() {
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were undone
assertSame(oldTitle, book.getTitle());
- assertEquals("...", externalData[0]); //$NON-NLS-1$
- assertEquals(":::", externalData2[0]); //$NON-NLS-1$
+ assertEquals("...", externalData[0]);
+ assertEquals(":::", externalData2[0]);
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());
assertEquals(newTitle, externalData[0]);
assertEquals(newTitle, externalData2[0]);
assertSame(newAuthor, book.getAuthor());
-
+
commit();
}
-
+
/**
- * Tests rollback of nested non-EMF operations on validation failure, to
- * check the correct nesting of non-EMF transactions with change
- * descriptions encapsulating non-EMF changes.
+ * Tests rollback of nested non-EMF operations on validation failure, to check
+ * the correct nesting of non-EMF transactions with change descriptions
+ * encapsulating non-EMF changes.
*/
@Test
public void test_rollback_nested() {
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 Writer newAuthor = (Writer) find("root/level1/Level1 Writer"); //$NON-NLS-1$
+
+ final Writer newAuthor = (Writer) find("root/level1/Level1 Writer");
assertNotNull(newAuthor);
-
+
commit();
-
+
// non-EMF "external" data to be modified by the composite
final String[] externalData = new String[1];
- externalData[0] = "..."; //$NON-NLS-1$
-
+ externalData[0] = "...";
+
// non-EMF "external" data to be modified by the nested composite
final String[] externalData2 = new String[1];
- externalData2[0] = ":::"; //$NON-NLS-1$
-
+ externalData2[0] = ":::";
+
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
composite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
newAuthor.getBooks().add(book);
- }});
-
+ }
+ });
+
composite.add(new ChangeExternalData(externalData, book));
-
+
// more nesting
ICompositeOperation composite2 = new NonEMFCompositeOperation();
composite2.add(new ChangeExternalData(externalData2, book));
composite.add(composite2);
-
+
// EMF change in the nested non-transactional composite
composite2.add(new TestOperation(domain) {
@Override
protected void doExecute() {
- book.setTitle(null); // will not pass validation
- }});
-
+ book.setTitle(null); // will not pass validation
+ }
+ });
+
IStatus status = null;
-
+
try {
validationEnabled = true;
composite.addContext(ctx);
@@ -538,22 +514,22 @@ protected void doExecute() {
} finally {
validationEnabled = false;
}
-
+
// check that validation failed with an error
assertNotNull(status);
assertNotNull(findValidationStatus(status, IStatus.ERROR));
-
+
startReading();
-
+
// verify that the changes were rolled back
assertSame(oldAuthor, book.getAuthor());
assertEquals(oldTitle, book.getTitle());
- assertEquals("...", externalData[0]); //$NON-NLS-1$
- assertEquals(":::", externalData2[0]); //$NON-NLS-1$
-
+ assertEquals("...", externalData[0]);
+ assertEquals(":::", externalData2[0]);
+
commit();
}
-
+
/**
* Tests that trigger commands are executed correctly when executing composite
* operations, including undo and redo.
@@ -562,49 +538,50 @@ protected void doExecute() {
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 = new Library[1];
-
+
// non-EMF "external" data to be modified by the composite
final String[] externalData = new String[1];
- externalData[0] = "..."; //$NON-NLS-1$
-
+ externalData[0] = "...";
+
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
composite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
- // 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
newLibrary[0] = EXTLibraryFactory.eINSTANCE.createLibrary();
root.getBranches().add(newLibrary[0]);
-
+
assertNull(newLibrary[0].getName());
assertTrue(newLibrary[0].getBooks().isEmpty());
- }});
-
+ }
+ });
+
// the operation will find the new book and set the externalData from its
- // title. Note that this depends on triggers of the previous operation!
+ // title. Note that this depends on triggers of the previous operation!
composite.add(new ChangeExternalData(externalData, newLibrary));
-
+
try {
composite.addContext(ctx);
history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
- assertEquals("New Library", newLibrary[0].getName()); //$NON-NLS-1$
+
+ assertEquals("New Library", newLibrary[0].getName());
assertEquals(1, newLibrary[0].getBooks().size());
- assertEquals("New Book", newLibrary[0].getBooks().get(0).getTitle()); //$NON-NLS-1$
- assertEquals("New Book", externalData[0]); //$NON-NLS-1$
-
+ assertEquals("New Book", newLibrary[0].getBooks().get(0).getTitle());
+ assertEquals("New Book", externalData[0]);
+
commit();
try {
@@ -613,81 +590,81 @@ protected void doExecute() {
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were undone
assertFalse(root.getBranches().contains(newLibrary[0]));
- assertEquals("...", externalData[0]); //$NON-NLS-1$
- assertFalse("New Library".equals(newLibrary[0].getName())); //$NON-NLS-1$
+ assertEquals("...", externalData[0]);
+ assertFalse("New Library".equals(newLibrary[0].getName()));
assertEquals(0, newLibrary[0].getBooks().size());
-
+
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[0]));
- assertEquals("New Library", newLibrary[0].getName()); //$NON-NLS-1$
+ assertEquals("New Library", newLibrary[0].getName());
assertEquals(1, newLibrary[0].getBooks().size());
- assertEquals("New Book", newLibrary[0].getBooks().get(0).getTitle()); //$NON-NLS-1$
- assertEquals("New Book", externalData[0]); //$NON-NLS-1$
-
+ assertEquals("New Book", newLibrary[0].getBooks().get(0).getTitle());
+ assertEquals("New Book", externalData[0]);
+
commit();
}
-
+
/**
* Tests that commands from aggregate pre-commit listeners are executed
- * correctly when executing composite operations, including undo and redo.
- * This is different from the non-aggregate case because they are
- * contributed only to the top-level transaction (which otherwise has no
- * changes of its own).
+ * correctly when executing composite operations, including undo and redo. This
+ * is different from the non-aggregate case because they are contributed only to
+ * the top-level transaction (which otherwise has no changes of its own).
*/
@Test
public void test_triggerCommands_aggregate() {
// one trigger sets default library names
domain.addResourceSetListener(new LibraryDefaultNameTrigger(true));
-
+
// another (distinct) trigger creates default books in new libraries
domain.addResourceSetListener(new LibraryDefaultBookTrigger(true));
-
+
final Library[] newLibrary = new Library[1];
-
+
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
composite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
- // 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
newLibrary[0] = EXTLibraryFactory.eINSTANCE.createLibrary();
root.getBranches().add(newLibrary[0]);
-
+
assertNull(newLibrary[0].getName());
assertTrue(newLibrary[0].getBooks().isEmpty());
- }});
-
+ }
+ });
+
try {
composite.addContext(ctx);
history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
- assertEquals("New Library", newLibrary[0].getName()); //$NON-NLS-1$
+
+ assertEquals("New Library", newLibrary[0].getName());
assertEquals(1, newLibrary[0].getBooks().size());
- assertEquals("New Book", newLibrary[0].getBooks().get(0).getTitle()); //$NON-NLS-1$
-
+ assertEquals("New Book", newLibrary[0].getBooks().get(0).getTitle());
+
commit();
try {
@@ -696,76 +673,78 @@ protected void doExecute() {
} catch (ExecutionException e) {
fail(e);
}
-
+
startReading();
-
+
// verify that the changes were undone
assertFalse(root.getBranches().contains(newLibrary[0]));
- assertFalse("New Library".equals(newLibrary[0].getName())); //$NON-NLS-1$
+ assertFalse("New Library".equals(newLibrary[0].getName()));
assertEquals(0, newLibrary[0].getBooks().size());
-
+
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[0]));
- assertEquals("New Library", newLibrary[0].getName()); //$NON-NLS-1$
+ assertEquals("New Library", newLibrary[0].getName());
assertEquals(1, newLibrary[0].getBooks().size());
- assertEquals("New Book", newLibrary[0].getBooks().get(0).getTitle()); //$NON-NLS-1$
-
+ assertEquals("New Book", newLibrary[0].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();
-
+
// non-EMF "external" data to be modified by the composite
final String[] externalData = new String[1];
- externalData[0] = "..."; //$NON-NLS-1$
-
+ externalData[0] = "...";
+
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
composite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
book.setTitle(newTitle);
- }});
-
+ }
+ });
+
composite.add(new ChangeExternalData(externalData, book));
-
+
composite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
newAuthor.getBooks().add(book);
- }});
-
+ }
+ });
+
IStatus status = null;
-
+
try {
validationEnabled = true;
composite.addContext(ctx);
@@ -776,509 +755,506 @@ protected void doExecute() {
} 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, *including* the non-EMF change
assertSame(oldTitle, book.getTitle());
- assertEquals("...", externalData[0]); //$NON-NLS-1$
+ assertEquals("...", externalData[0]);
assertSame(oldAuthor, book.getAuthor());
-
+
commit();
}
-
+
/**
* Tests error detection during execution.
*/
@Test
public void test_execute_error_123614() {
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
MarkerOperation marker1 = new MarkerOperation();
composite.add(marker1);
-
- FailCancelOperation op = new FailCancelOperation(
- ERROR_STATUS, Status.OK_STATUS, Status.OK_STATUS, false);
+
+ FailCancelOperation op = new FailCancelOperation(ERROR_STATUS, Status.OK_STATUS, Status.OK_STATUS, false);
composite.add(op);
-
+
MarkerOperation marker2 = new MarkerOperation();
composite.add(marker2);
-
+
IStatus status = null;
-
+
try {
composite.addContext(ctx);
status = history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were executed and which rolled back
assertTrue(marker1.wasExecuted);
assertFalse(marker2.wasExecuted);
assertTrue(marker1.wasUndone);
-
+
// check overall operation status
assertEquals(IStatus.ERROR, status.getSeverity());
}
-
+
/**
* Tests cancel-status detection during execution.
*/
@Test
public void test_execute_cancel_123614() {
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
MarkerOperation marker1 = new MarkerOperation();
composite.add(marker1);
-
- FailCancelOperation op = new FailCancelOperation(
- Status.CANCEL_STATUS, Status.OK_STATUS, Status.OK_STATUS, false);
+
+ FailCancelOperation op = new FailCancelOperation(Status.CANCEL_STATUS, Status.OK_STATUS, Status.OK_STATUS,
+ false);
composite.add(op);
-
+
MarkerOperation marker2 = new MarkerOperation();
composite.add(marker2);
-
+
IStatus status = null;
-
+
try {
composite.addContext(ctx);
status = history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were executed and which rolled back
assertTrue(marker1.wasExecuted);
assertFalse(marker2.wasExecuted);
assertTrue(marker1.wasUndone);
-
+
// check overall operation status
assertEquals(IStatus.CANCEL, status.getSeverity());
}
-
+
/**
* Tests monitor-cancel detection during execution.
*/
@Test
public void test_execute_cancelMonitor_123614() {
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
MarkerOperation marker1 = new MarkerOperation();
composite.add(marker1);
-
- FailCancelOperation op = new FailCancelOperation(
- Status.CANCEL_STATUS, Status.OK_STATUS, Status.OK_STATUS, true);
+
+ FailCancelOperation op = new FailCancelOperation(Status.CANCEL_STATUS, Status.OK_STATUS, Status.OK_STATUS,
+ true);
composite.add(op);
-
+
MarkerOperation marker2 = new MarkerOperation();
composite.add(marker2);
-
+
IStatus status = null;
-
+
try {
composite.addContext(ctx);
status = history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were executed and which rolled back
assertTrue(marker1.wasExecuted);
assertFalse(marker2.wasExecuted);
assertTrue(marker1.wasUndone);
-
+
// check overall operation status
assertEquals(IStatus.CANCEL, status.getSeverity());
}
-
+
/**
* Tests error detection during undo.
*/
@Test
public void test_undo_error_123614() {
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
MarkerOperation marker1 = new MarkerOperation();
composite.add(marker1);
-
- FailCancelOperation op = new FailCancelOperation(
- Status.OK_STATUS, ERROR_STATUS, Status.OK_STATUS, false);
+
+ FailCancelOperation op = new FailCancelOperation(Status.OK_STATUS, ERROR_STATUS, Status.OK_STATUS, false);
composite.add(op);
-
+
MarkerOperation marker2 = new MarkerOperation();
composite.add(marker2);
-
+
IStatus status = null;
-
+
try {
composite.addContext(ctx);
status = history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were executed and which rolled back
assertTrue(marker1.wasExecuted);
assertTrue(marker2.wasExecuted);
assertFalse(marker1.wasUndone);
-
+
// check overall operation status
assertEquals(IStatus.OK, status.getSeverity());
-
+
marker1.reset();
marker2.reset();
-
+
try {
status = history.undo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were undone and which were redone
assertFalse(marker1.wasUndone);
assertTrue(marker2.wasUndone);
assertTrue(marker2.wasRedone);
-
+
// check overall operation status
assertEquals(IStatus.ERROR, status.getSeverity());
}
-
+
/**
* Tests cancel-status detection during undo.
*/
@Test
public void test_undo_cancel_123614() {
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
MarkerOperation marker1 = new MarkerOperation();
composite.add(marker1);
-
- FailCancelOperation op = new FailCancelOperation(
- Status.OK_STATUS, Status.CANCEL_STATUS, Status.OK_STATUS, false);
+
+ FailCancelOperation op = new FailCancelOperation(Status.OK_STATUS, Status.CANCEL_STATUS, Status.OK_STATUS,
+ false);
composite.add(op);
-
+
MarkerOperation marker2 = new MarkerOperation();
composite.add(marker2);
-
+
IStatus status = null;
-
+
try {
composite.addContext(ctx);
status = history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were executed and which rolled back
assertTrue(marker1.wasExecuted);
assertTrue(marker2.wasExecuted);
assertFalse(marker1.wasUndone);
-
+
// check overall operation status
assertEquals(IStatus.OK, status.getSeverity());
-
+
marker1.reset();
marker2.reset();
-
+
try {
status = history.undo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were undone and which were redone
assertFalse(marker1.wasUndone);
assertTrue(marker2.wasUndone);
assertTrue(marker2.wasRedone);
-
+
// check overall operation status
assertEquals(IStatus.CANCEL, status.getSeverity());
}
-
+
/**
* Tests monitor-cancel detection during undo.
*/
@Test
public void test_undo_cancelMonitor_123614() {
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
MarkerOperation marker1 = new MarkerOperation();
composite.add(marker1);
-
- FailCancelOperation op = new FailCancelOperation(
- Status.OK_STATUS, Status.CANCEL_STATUS, Status.OK_STATUS, true);
+
+ FailCancelOperation op = new FailCancelOperation(Status.OK_STATUS, Status.CANCEL_STATUS, Status.OK_STATUS,
+ true);
composite.add(op);
-
+
MarkerOperation marker2 = new MarkerOperation();
composite.add(marker2);
-
+
IStatus status = null;
-
+
try {
composite.addContext(ctx);
status = history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were executed and which rolled back
assertTrue(marker1.wasExecuted);
assertTrue(marker2.wasExecuted);
assertFalse(marker1.wasUndone);
-
+
// check overall operation status
assertEquals(IStatus.OK, status.getSeverity());
-
+
marker1.reset();
marker2.reset();
-
+
try {
status = history.undo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were undone and which were redone
assertFalse(marker1.wasUndone);
assertTrue(marker2.wasUndone);
assertTrue(marker2.wasRedone);
-
+
// check overall operation status
assertEquals(IStatus.CANCEL, status.getSeverity());
}
-
+
/**
* Tests error detection during redo.
*/
@Test
public void test_redo_error_123614() {
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
MarkerOperation marker1 = new MarkerOperation();
composite.add(marker1);
-
- FailCancelOperation op = new FailCancelOperation(
- Status.OK_STATUS, Status.OK_STATUS, ERROR_STATUS, false);
+
+ FailCancelOperation op = new FailCancelOperation(Status.OK_STATUS, Status.OK_STATUS, ERROR_STATUS, false);
composite.add(op);
-
+
MarkerOperation marker2 = new MarkerOperation();
composite.add(marker2);
-
+
IStatus status = null;
-
+
try {
composite.addContext(ctx);
status = history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were executed and which rolled back
assertTrue(marker1.wasExecuted);
assertTrue(marker2.wasExecuted);
assertFalse(marker1.wasUndone);
-
+
// check overall operation status
assertEquals(IStatus.OK, status.getSeverity());
-
+
marker1.reset();
marker2.reset();
-
+
try {
status = history.undo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were undone and which were redone
assertTrue(marker1.wasUndone);
assertTrue(marker2.wasUndone);
assertFalse(marker2.wasRedone);
-
+
// check overall operation status
assertEquals(IStatus.OK, status.getSeverity());
-
+
marker1.reset();
marker2.reset();
-
+
try {
status = history.redo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were undone and which were redone
assertTrue(marker1.wasRedone);
assertFalse(marker2.wasRedone);
assertTrue(marker1.wasUndone);
-
+
// check overall operation status
assertEquals(IStatus.ERROR, status.getSeverity());
}
-
+
/**
* Tests cancel-status detection during redo.
*/
@Test
public void test_redo_cancel_123614() {
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
MarkerOperation marker1 = new MarkerOperation();
composite.add(marker1);
-
- FailCancelOperation op = new FailCancelOperation(
- Status.OK_STATUS, Status.OK_STATUS, Status.CANCEL_STATUS, false);
+
+ FailCancelOperation op = new FailCancelOperation(Status.OK_STATUS, Status.OK_STATUS, Status.CANCEL_STATUS,
+ false);
composite.add(op);
-
+
MarkerOperation marker2 = new MarkerOperation();
composite.add(marker2);
-
+
IStatus status = null;
-
+
try {
composite.addContext(ctx);
status = history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were executed and which rolled back
assertTrue(marker1.wasExecuted);
assertTrue(marker2.wasExecuted);
assertFalse(marker1.wasUndone);
-
+
// check overall operation status
assertEquals(IStatus.OK, status.getSeverity());
-
+
marker1.reset();
marker2.reset();
-
+
try {
status = history.undo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were undone and which were redone
assertTrue(marker1.wasUndone);
assertTrue(marker2.wasUndone);
assertFalse(marker2.wasRedone);
-
+
// check overall operation status
assertEquals(IStatus.OK, status.getSeverity());
-
+
marker1.reset();
marker2.reset();
-
+
try {
status = history.redo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were undone and which were redone
assertTrue(marker1.wasRedone);
assertFalse(marker2.wasRedone);
assertTrue(marker1.wasUndone);
-
+
// check overall operation status
assertEquals(IStatus.CANCEL, status.getSeverity());
}
-
+
/**
* Tests monitor-cancel detection during redo.
*/
@Test
public void test_redo_cancelMonitor_123614() {
IUndoContext ctx = new TestUndoContext();
-
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
MarkerOperation marker1 = new MarkerOperation();
composite.add(marker1);
-
- FailCancelOperation op = new FailCancelOperation(
- Status.OK_STATUS, Status.OK_STATUS, Status.CANCEL_STATUS, true);
+
+ FailCancelOperation op = new FailCancelOperation(Status.OK_STATUS, Status.OK_STATUS, Status.CANCEL_STATUS,
+ true);
composite.add(op);
-
+
MarkerOperation marker2 = new MarkerOperation();
composite.add(marker2);
-
+
IStatus status = null;
-
+
try {
composite.addContext(ctx);
status = history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were executed and which rolled back
assertTrue(marker1.wasExecuted);
assertTrue(marker2.wasExecuted);
assertFalse(marker1.wasUndone);
-
+
// check overall operation status
assertEquals(IStatus.OK, status.getSeverity());
-
+
marker1.reset();
marker2.reset();
-
+
try {
status = history.undo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were undone and which were redone
assertTrue(marker1.wasUndone);
assertTrue(marker2.wasUndone);
assertFalse(marker2.wasRedone);
-
+
// check overall operation status
assertEquals(IStatus.OK, status.getSeverity());
-
+
marker1.reset();
marker2.reset();
-
+
try {
status = history.redo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
// check which markers were undone and which were redone
assertTrue(marker1.wasRedone);
assertFalse(marker2.wasRedone);
assertTrue(marker1.wasUndone);
-
+
// check overall operation status
assertEquals(IStatus.CANCEL, status.getSeverity());
}
-
+
/**
* Tests that an pure EMF composite operation can use a single, unnested,
* transaction.
@@ -1287,64 +1263,67 @@ public void test_redo_cancelMonitor_123614() {
public void test_noTransactionNesting_pureEMF_135545() {
TransactionCapture capture = new TransactionCapture();
domain.addResourceSetListener(capture);
-
+
startReading();
-
+
int originalBranchCount = root.getBranches().size();
-
+
commit();
IUndoContext ctx = new TestUndoContext();
-
+
// create a nested composite operation structure
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
// tell the composite to reuse a single transaction
composite.setTransactionNestingEnabled(false);
-
+
composite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
// add a new library
root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
- }});
+ }
+ });
- CompositeEMFOperation nestedComposite = new CompositeEMFOperation(domain, "Nested"); //$NON-NLS-1$
+ CompositeEMFOperation nestedComposite = new CompositeEMFOperation(domain, "Nested");
nestedComposite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
// add a new library
root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
- }});
+ }
+ });
nestedComposite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
// add a new library
root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
- }});
+ }
+ });
composite.add(nestedComposite);
-
+
try {
composite.addContext(ctx);
history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
Transaction transaction = capture.getTransaction();
assertNotNull(transaction);
-
+
// only one transaction (contributing one change description to the composite)
Collection changes = getChanges(transaction);
assertEquals(1, changes.size());
-
+
capture.clear();
-
+
startReading();
-
+
assertEquals(originalBranchCount + 3, root.getBranches().size());
-
+
commit();
try {
@@ -1353,123 +1332,126 @@ protected void doExecute() {
} catch (ExecutionException e) {
fail(e);
}
-
+
transaction = capture.getTransaction();
assertNotNull(transaction);
-
+
// transaction didn't record any changes on undo
changes = getChanges(transaction);
assertEquals(0, changes.size());
-
+
startReading();
-
+
// verify that the changes were undone
assertEquals(originalBranchCount, root.getBranches().size());
-
+
commit();
-
+
try {
assertTrue(history.canRedo(ctx));
history.redo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
transaction = capture.getTransaction();
assertNotNull(transaction);
-
+
// transaction didn't record any changes on redo
changes = getChanges(transaction);
assertEquals(0, changes.size());
-
+
startReading();
-
+
// verify that the changes were redone
assertEquals(originalBranchCount + 3, root.getBranches().size());
-
+
commit();
}
-
+
/**
* Tests that a mixed EMF and non-EMF composite operation can use a single,
- * unnested, transaction as much as possible (some nesting must still occur
- * to account for non-EMF changes).
+ * unnested, transaction as much as possible (some nesting must still occur to
+ * account for non-EMF changes).
*/
@Test
public void test_noTransactionNesting_mixed_135545() {
TransactionCapture capture = new TransactionCapture();
domain.addResourceSetListener(capture);
-
+
startReading();
-
+
int originalBranchCount = root.getBranches().size();
- final Book book = (Book) find("root/Root Book"); //$NON-NLS-1$
+ final Book book = (Book) find("root/Root Book");
final String title = book.getTitle();
-
+
commit();
// non-EMF "external" data to be modified by the composite
final String[] externalData = new String[1];
- externalData[0] = "..."; //$NON-NLS-1$
-
+ externalData[0] = "...";
+
IUndoContext ctx = new TestUndoContext();
-
+
// create a nested composite operation structure
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
// tell the composite to reuse a single transaction
composite.setTransactionNestingEnabled(false);
-
+
composite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
// add a new library
root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
- }});
+ }
+ });
- CompositeEMFOperation nestedComposite = new CompositeEMFOperation(domain, "Nested"); //$NON-NLS-1$
- nestedComposite.add(new ChangeExternalData(externalData, book)); // non-EMF change
+ CompositeEMFOperation nestedComposite = new CompositeEMFOperation(domain, "Nested");
+ nestedComposite.add(new ChangeExternalData(externalData, book)); // non-EMF change
nestedComposite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
// add a new library
root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
- }});
+ }
+ });
nestedComposite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
// add a new library
root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
- }});
+ }
+ });
composite.add(nestedComposite);
-
+
try {
composite.addContext(ctx);
history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
Transaction transaction = capture.getTransaction();
assertNotNull(transaction);
-
- // only two transactions: the parent and a single child for the
- // non-EMF changes. These result in three changes: one change
- // before the non-EMF changes, one change for the non-EMF changes,
- // and one change for everything after. We would have 4 changes
- // without the no-nesting hint
+
+ // only two transactions: the parent and a single child for the
+ // non-EMF changes. These result in three changes: one change
+ // before the non-EMF changes, one change for the non-EMF changes,
+ // and one change for everything after. We would have 4 changes
+ // without the no-nesting hint
Collection changes = getChanges(transaction);
assertEquals(3, changes.size());
-
+
capture.clear();
-
+
startReading();
-
+
// verify that the changes were done
assertEquals(originalBranchCount + 3, root.getBranches().size());
assertEquals(title, externalData[0]);
-
+
commit();
try {
@@ -1478,45 +1460,45 @@ protected void doExecute() {
} catch (ExecutionException e) {
fail(e);
}
-
+
transaction = capture.getTransaction();
assertNotNull(transaction);
-
+
// transaction didn't record any changes on undo
changes = getChanges(transaction);
assertEquals(0, changes.size());
-
+
startReading();
-
+
// verify that the changes were undone
assertEquals(originalBranchCount, root.getBranches().size());
- assertEquals("...", externalData[0]); //$NON-NLS-1$
-
+ assertEquals("...", externalData[0]);
+
commit();
-
+
try {
assertTrue(history.canRedo(ctx));
history.redo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
transaction = capture.getTransaction();
assertNotNull(transaction);
-
+
// transaction didn't record any changes on redo
changes = getChanges(transaction);
assertEquals(0, changes.size());
-
+
startReading();
-
+
// verify that the changes were redone
assertEquals(originalBranchCount + 3, root.getBranches().size());
assertEquals(title, externalData[0]);
-
+
commit();
}
-
+
/**
* Tests that an EMF operation with different options forces nesting.
*/
@@ -1524,29 +1506,30 @@ protected void doExecute() {
public void test_noTransactionNesting_differentOptions_135545() {
TransactionCapture capture = new TransactionCapture();
domain.addResourceSetListener(capture);
-
+
startReading();
-
+
int originalBranchCount = root.getBranches().size();
-
+
commit();
IUndoContext ctx = new TestUndoContext();
-
+
// create a nested composite operation structure
- CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite"); //$NON-NLS-1$
-
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
+
// tell the composite to reuse a single transaction
composite.setTransactionNestingEnabled(false);
-
+
composite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
// add a new library
root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
- }});
+ }
+ });
- CompositeEMFOperation nestedComposite = new CompositeEMFOperation(domain, "Nested"); //$NON-NLS-1$
+ CompositeEMFOperation nestedComposite = new CompositeEMFOperation(domain, "Nested");
nestedComposite.add(new TestOperation(domain,
// this transaction has different options
Collections.singletonMap(Transaction.OPTION_NO_NOTIFICATIONS, Boolean.TRUE)) {
@@ -1554,46 +1537,49 @@ protected void doExecute() {
protected void doExecute() {
// add a new library
root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
- }});
+ }
+ });
nestedComposite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
// add a new library
root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
- }});
+ }
+ });
nestedComposite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
// add a new library
root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
- }});
+ }
+ });
composite.add(nestedComposite);
-
+
try {
composite.addContext(ctx);
history.execute(composite, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
Transaction transaction = capture.getTransaction();
assertNotNull(transaction);
-
- // only two transactions: the parent and a single child for the
- // non-EMF changes. These result in three changes: one change
- // before the different options, one change for the different options,
- // and one change for everything after. We would have 4 changes
- // without the no-nesting hint
+
+ // only two transactions: the parent and a single child for the
+ // non-EMF changes. These result in three changes: one change
+ // before the different options, one change for the different options,
+ // and one change for everything after. We would have 4 changes
+ // without the no-nesting hint
Collection changes = getChanges(transaction);
assertEquals(3, changes.size());
-
+
capture.clear();
-
+
startReading();
-
+
assertEquals(originalBranchCount + 4, root.getBranches().size());
-
+
commit();
try {
@@ -1602,43 +1588,43 @@ protected void doExecute() {
} catch (ExecutionException e) {
fail(e);
}
-
+
transaction = capture.getTransaction();
assertNotNull(transaction);
-
+
// transaction didn't record any changes on undo
changes = getChanges(transaction);
assertEquals(0, changes.size());
-
+
startReading();
-
+
// verify that the changes were undone
assertEquals(originalBranchCount, root.getBranches().size());
-
+
commit();
-
+
try {
assertTrue(history.canRedo(ctx));
history.redo(ctx, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
fail(e);
}
-
+
transaction = capture.getTransaction();
assertNotNull(transaction);
-
+
// transaction didn't record any changes on redo
changes = getChanges(transaction);
assertEquals(0, changes.size());
-
+
startReading();
-
+
// verify that the changes were redone
assertEquals(originalBranchCount + 4, root.getBranches().size());
-
+
commit();
}
-
+
@Test
public void test_errorInNestedAEO_transactionNesting_250253() {
AbstractEMFOperationTest.RollbackListener l = new AbstractEMFOperationTest.RollbackListener();
@@ -1655,16 +1641,14 @@ public void test_errorInNestedAEO_transactionNesting_250253() {
IUndoContext ctx = new TestUndoContext();
// create a nested composite operation structure
- CompositeEMFOperation composite = new CompositeEMFOperation(domain,
- "Composite"); //$NON-NLS-1$
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
composite.add(new TestOperation(domain) {
@Override
protected void doExecute() {
// add a new library
- root.getBranches().add(
- EXTLibraryFactory.eINSTANCE.createLibrary());
+ root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
}
});
@@ -1673,12 +1657,10 @@ protected void doExecute() {
@Override
protected void doExecute() {
// add a new library
- root.getBranches().add(
- EXTLibraryFactory.eINSTANCE.createLibrary());
+ root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
// then return an error status for some reason
- setStatus(new Status(IStatus.ERROR,
- "org.eclipse.emf.workspace.tests", "I want to fail")); //$NON-NLS-1$ //$NON-NLS-2$
+ setStatus(new Status(IStatus.ERROR, "org.eclipse.emf.workspace.tests", "I want to fail")); //$NON-NLS-2$
}
});
composite.add(new TestOperation(domain) {
@@ -1686,8 +1668,7 @@ protected void doExecute() {
@Override
protected void doExecute() {
// add a new library
- shouldNotCreate[0] = EXTLibraryFactory.eINSTANCE
- .createLibrary();
+ shouldNotCreate[0] = EXTLibraryFactory.eINSTANCE.createLibrary();
root.getBranches().add(shouldNotCreate[0]);
}
});
@@ -1698,7 +1679,7 @@ protected void doExecute() {
} catch (ExecutionException e) {
fail(e);
}
-
+
l.assertRolledBack();
startReading();
@@ -1707,14 +1688,14 @@ protected void doExecute() {
assertEquals(originalBranchCount, root.getBranches().size());
// and we didn't even execute the third command
- assertNull("Executed the third child command", shouldNotCreate[0]); //$NON-NLS-1$
+ assertNull(shouldNotCreate[0], "Executed the third child command");
commit();
} finally {
l.uninstall(domain);
}
}
-
+
@Test
public void test_errorInNestedAEO_noTransactionNesting_250253() {
AbstractEMFOperationTest.RollbackListener l = new AbstractEMFOperationTest.RollbackListener();
@@ -1731,8 +1712,7 @@ public void test_errorInNestedAEO_noTransactionNesting_250253() {
IUndoContext ctx = new TestUndoContext();
// create a nested composite operation structure
- CompositeEMFOperation composite = new CompositeEMFOperation(domain,
- "Composite"); //$NON-NLS-1$
+ CompositeEMFOperation composite = new CompositeEMFOperation(domain, "Composite");
// tell the composite to reuse a single transaction
composite.setTransactionNestingEnabled(false);
@@ -1742,8 +1722,7 @@ public void test_errorInNestedAEO_noTransactionNesting_250253() {
@Override
protected void doExecute() {
// add a new library
- root.getBranches().add(
- EXTLibraryFactory.eINSTANCE.createLibrary());
+ root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
}
});
@@ -1752,12 +1731,10 @@ protected void doExecute() {
@Override
protected void doExecute() {
// add a new library
- root.getBranches().add(
- EXTLibraryFactory.eINSTANCE.createLibrary());
+ root.getBranches().add(EXTLibraryFactory.eINSTANCE.createLibrary());
// then return an error status for some reason
- setStatus(new Status(IStatus.ERROR,
- "org.eclipse.emf.workspace.tests", "I want to fail")); //$NON-NLS-1$ //$NON-NLS-2$
+ setStatus(new Status(IStatus.ERROR, "org.eclipse.emf.workspace.tests", "I want to fail")); //$NON-NLS-2$
}
});
composite.add(new TestOperation(domain) {
@@ -1765,8 +1742,7 @@ protected void doExecute() {
@Override
protected void doExecute() {
// add a new library
- shouldNotCreate[0] = EXTLibraryFactory.eINSTANCE
- .createLibrary();
+ shouldNotCreate[0] = EXTLibraryFactory.eINSTANCE.createLibrary();
root.getBranches().add(shouldNotCreate[0]);
}
});
@@ -1786,18 +1762,18 @@ protected void doExecute() {
assertEquals(originalBranchCount, root.getBranches().size());
// and we didn't even execute the third command
- assertNull("Executed the third child command", shouldNotCreate[0]); //$NON-NLS-1$
+ assertNull(shouldNotCreate[0], "Executed the third child command");
commit();
} finally {
l.uninstall(domain);
}
}
-
+
//
// Test fixtures
//
-
+
/**
* Does a reflective hack to get the private changes field of a
* composite change description.
@@ -1806,166 +1782,164 @@ protected void doExecute() {
private Collection getChanges(Transaction tx) {
Collection result = null;
CompositeChangeDescription composite = (CompositeChangeDescription) tx.getChangeDescription();
-
+
try {
- Field changes = composite.getClass().getDeclaredField("changes"); //$NON-NLS-1$
+ Field changes = composite.getClass().getDeclaredField("changes");
changes.setAccessible(true);
result = (Collection) changes.get(composite);
} catch (Exception e) {
- Assert.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 02e4bf6a..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,11 +12,11 @@
*/
package org.eclipse.emf.workspace.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+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;
@@ -46,8 +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.Test;
-
+import org.junit.jupiter.api.Test;
/**
* Tests the {@link EMFCommandOperation} class.
@@ -56,49 +55,40 @@
*/
public class EMFCommandOperationTest extends AbstractTest {
-
@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 {
@@ -107,31 +97,31 @@ 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.
@@ -140,35 +130,31 @@ public void test_execute_undo_redo() {
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 {
@@ -177,32 +163,32 @@ 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.
@@ -211,39 +197,35 @@ public void test_triggerCommands() {
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,75 +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 {
@@ -329,31 +312,31 @@ 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).
@@ -362,36 +345,37 @@ protected void doExecute() {
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 {
@@ -400,66 +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);
@@ -469,25 +445,25 @@ 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() {
@@ -495,21 +471,22 @@ public void test_nonredoableCommand_138287() {
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.
@@ -524,158 +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.
- */
- @Test
- 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.
- */
+ }
+
+ /**
+ * 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")}; //$NON-NLS-1$
- final int newCopies = 30;
-
- final RecordingCommand trigger = new RecordingCommand(domain, "Test Trigger") { //$NON-NLS-1$
-
+ 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 8b72c97f..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,12 +12,12 @@
*/
package org.eclipse.emf.workspace.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+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;
@@ -42,8 +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.Assert;
-
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests the {@link EMFOperationCommand} class.
@@ -53,50 +53,44 @@
public class EMFOperationCommandTest extends AbstractTest {
/**
- * 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 {
@@ -105,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 {
@@ -199,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);
-
- Assert.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 {
@@ -362,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) {
@@ -427,7 +415,8 @@ protected void doExecute() {
@Override
public boolean canRedo() {
return false;
- }};
+ }
+ };
EMFOperationCommand operationCommand = new EMFOperationCommand(domain, operation);
getCommandStack().execute(operationCommand);
@@ -436,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);
@@ -449,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
-
- Assert.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
-
- Assert.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
-
- Assert.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) {
- Assert.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);
- Assert.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) {
- Assert.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) {
- Assert.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);
- Assert.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 d9e17235..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,9 +11,9 @@
*/
package org.eclipse.emf.workspace.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+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;
@@ -46,9 +46,8 @@
import org.eclipse.emf.workspace.AbstractEMFOperation;
import org.eclipse.emf.workspace.EMFOperationCommand;
import org.eclipse.emf.workspace.ResourceUndoContext;
-import org.junit.Assert;
-import org.junit.Test;
-
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests to check for memory leaks.
@@ -58,568 +57,576 @@
public class MemoryLeakTest extends AbstractTest {
/**
- *
- * 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.
- *
- */
+ *
+ * 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"); //$NON-NLS-1$
-
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- Command cmd = new RemoveCommand(domain, root, EXTLibraryPackage.Literals.LIBRARY__BRANCHES, level1) {
- @Override
+ // 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.
- *
- */
+ 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"); //$NON-NLS-1$
-
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- Command cmd = new RecordingCommand(domain, "Remove Branch") { //$NON-NLS-1$
- @Override
+ 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.
- *
- */
+ 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"); //$NON-NLS-1$
-
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- final Command trigger = new RemoveCommand(domain, root, EXTLibraryPackage.Literals.LIBRARY__BRANCHES, level1) {
- @Override
+ 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.
- *
- */
+ 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"); //$NON-NLS-1$
-
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- final Command trigger = new RecordingCommand(domain, "Remove Branch") { //$NON-NLS-1$
- @Override
+ 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.
- *
- */
+ 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"); //$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) {
- Assert.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) {
- Assert.fail("Failed to undo operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
- try {
- history.redo(ctx, null, null);
- } catch (ExecutionException e) {
- Assert.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_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"); //$NON-NLS-1$
-
- assertTrue(level1.eAdapters().contains(xrefAdapter));
-
- final Command trigger = new RecordingCommand(domain, "Remove Branch") { //$NON-NLS-1$
- @Override
+ 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) {
- Assert.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) {
- Assert.fail("Failed to undo operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
- try {
- history.redo(ctx, null, null);
- } catch (ExecutionException e) {
- Assert.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.
- *
- */
+ 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"); //$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) {
- Assert.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) {
- Assert.fail("Failed to undo operation: " + e.getLocalizedMessage()); //$NON-NLS-1$
- }
- try {
- history.redo(ctx, null, null);
- } catch (ExecutionException e) {
- Assert.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
+ 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 f2f32f17..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,8 +11,8 @@
*/
package org.eclipse.emf.workspace.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Collections;
import java.util.Set;
@@ -30,7 +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.Test;
+import org.junit.jupiter.api.Test;
/**
@@ -48,11 +48,11 @@ public class UndoContextTest extends AbstractTest {
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();
@@ -96,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 b01c7a71..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,13 @@
*/
package org.eclipse.emf.workspace.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;import org.junit.Test;
+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;
@@ -69,8 +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.Assert;
-
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests the {@link WorkbenchCommandStack} class.
@@ -87,90 +87,90 @@ public class WorkbenchCommandStackTest extends AbstractTest {
@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.
*/
@@ -178,644 +178,635 @@ public void test_mostRecentCommand() {
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();
- Assert.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();
- Assert.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());
+ }
+
+ @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
- 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.
- */
+
+ /**
+ * 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
+ 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).
- */
+ 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
+ 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.
- */
+ 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
+ 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) {
- Assert.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.
- */
+ 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
+ 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) {
- Assert.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.
- */
+ 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
+ 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) {
- Assert.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) {
- Assert.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) {
- Assert.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.
- */
+ 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;
- 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_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;
- 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_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") { //$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) {
- Assert.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.
- */
+ 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);
}
};
@@ -825,32 +816,31 @@ public IStatus undo(IProgressMonitor monitor, IAdaptable info)
try {
history.execute(operation, null, null);
} catch (ExecutionException e) {
- Assert.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();
@@ -859,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/fixtures/LogCapture.java b/tests/org.eclipse.emf.workspace.tests/src/org/eclipse/emf/workspace/tests/fixtures/LogCapture.java
index 220deab4..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,6 +11,8 @@
*/
package org.eclipse.emf.workspace.tests.fixtures;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
import java.util.List;
import org.eclipse.core.runtime.ILogListener;
@@ -21,7 +23,6 @@
import org.eclipse.emf.transaction.RollbackException;
import org.eclipse.emf.transaction.TransactionalCommandStack;
import org.eclipse.emf.workspace.tests.TestsPlugin;
-import org.junit.Assert;
import org.osgi.framework.Bundle;
/**
@@ -128,9 +129,9 @@ public List getLogs() {
*/
public void assertLogged(Throwable throwable) {
IStatus log = getLastLog();
- Assert.assertNotNull(log);
+ assertNotNull(log);
log = findStatus(log, throwable);
- Assert.assertNotNull(log);
+ assertNotNull(log);
}
private void record(IStatus log) {
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 b08c98c5..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
@@ -11,18 +11,18 @@
*/
package org.eclipse.emf.workspace.util.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+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.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+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.
@@ -30,17 +30,16 @@
* @author Christian W. Damus (cdamus)
*/
public class OperationChangeDescriptionTest {
-
+
private String[] externalData;
private String initialValue;
private String newValue;
private IUndoableOperation operation;
private OperationChangeDescription change;
-
/**
- * 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() {
@@ -49,7 +48,7 @@ public void test_emfChanges() {
assertTrue(change.getObjectsToAttach().isEmpty());
assertTrue(change.getObjectsToDetach().isEmpty());
}
-
+
/**
* Tests the canApply() method.
*/
@@ -57,80 +56,78 @@ public void test_emfChanges() {
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
//
-
- @Before
- public void setUp()
- throws Exception {
-
- initialValue = "Initial value";
- newValue = "New value";
- 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]);
}
-
- @After
- public 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();
- Assert.fail("Should not have thrown: " + e.getLocalizedMessage());
+ 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 d6b04448..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,9 +12,9 @@
*/
package org.eclipse.emf.workspace.util.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+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;
@@ -41,10 +41,10 @@
import org.eclipse.emf.workspace.ResourceUndoContext;
import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory;
import org.eclipse.emf.workspace.tests.fixtures.TestPackageBuilder;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+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.
@@ -255,7 +255,7 @@ public void test_unsettableManyReference_264220() {
assertEquals(expectedResources,
IResourceUndoContextPolicy.DEFAULT.getContextResources(null, listener.notifications));
} catch (ClassCastException e) {
- Assert.fail("Should not get CCE in the resource undo-context policy");
+ Assertions.fail("Should not get CCE in the resource undo-context policy");
}
}
@@ -263,8 +263,8 @@ public void test_unsettableManyReference_264220() {
// Fixture methods
//
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ public void setUp() {
TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE
.createEditingDomain(new DefaultOperationHistory());
@@ -288,8 +288,8 @@ public void setUp() throws Exception {
packageBuilder = new TestPackageBuilder();
}
- @After
- public void tearDown() throws Exception {
+ @AfterEach
+ public void tearDown() {
packageBuilder.dispose();
@@ -311,7 +311,7 @@ public void tearDown() throws Exception {
*/
protected void fail(Exception e) {
e.printStackTrace();
- Assert.fail("Should not have thrown: " + e.getLocalizedMessage());
+ Assertions.fail("Should not have thrown: " + e.getLocalizedMessage());
}
private static class Listener extends EContentAdapter {
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 62b8a5b2..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
@@ -10,10 +10,11 @@
* IBM - Initial API and implementation
*/
package org.eclipse.emf.workspace.util.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+
+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.Collections;
@@ -28,9 +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.Assert;
-import org.junit.Test;
-
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests validate-edit support.
@@ -38,119 +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);
- }
- }};
+
+ 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
+ @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);
-
- Assert.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 ea0fee4d..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,10 +12,10 @@
*/
package org.eclipse.emf.workspace.util.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+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;
@@ -42,8 +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.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests the {@link WorkspaceSynchronizer} class.
@@ -52,19 +52,20 @@
*/
@SuppressWarnings("nls")
public class WorkspaceSynchronizerTest extends AbstractTest {
-
+
private WorkspaceSynchronizer synch;
private TestDelegate delegate;
+
/**
* 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));
}
@@ -77,7 +78,7 @@ 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);
@@ -85,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);
@@ -93,55 +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,20 +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);
@@ -172,22 +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);
@@ -196,109 +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);
@@ -309,22 +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);
@@ -335,26 +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);
@@ -365,311 +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).
- */
+
+ /**
+ * 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); //$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_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); //$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_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); //$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_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 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"); //$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_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() {
-
+ 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) {
- Assert.fail("Should not have logged: " + logged[0].getException());
+ Assertions.fail("Should not have logged: " + logged[0].getException());
}
} catch (CoreException e) {
- Assert.fail("Failed to delete project: " + e.getLocalizedMessage());
+ Assertions.fail("Failed to delete project: " + e.getLocalizedMessage());
} catch (InterruptedException e) {
- Assert.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) {
@@ -677,7 +663,7 @@ protected IStatus run(IProgressMonitor monitor) {
}
}
}
-
+
/**
* Delegate implementation for testing, basically tracking the call-backs
* received from the workspace synchronizer.
@@ -685,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();