Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbvosburgh2012-02-10 15:49:25 -0500
committerbvosburgh2012-02-10 15:49:25 -0500
commit4716e39927cfe910fa7424870986a195d608b51f (patch)
tree800ca22e27d3d87fbd1f64968ca69efa5ceba413 /common/tests/org.eclipse.jpt.common.utility.tests
parent52f37be9bfbf1b7c0d451e99d938725ac497eed0 (diff)
downloadwebtools.dali-4716e39927cfe910fa7424870986a195d608b51f.tar.gz
webtools.dali-4716e39927cfe910fa7424870986a195d608b51f.tar.xz
webtools.dali-4716e39927cfe910fa7424870986a195d608b51f.zip
rework JpaProjectManager
Diffstat (limited to 'common/tests/org.eclipse.jpt.common.utility.tests')
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/META-INF/MANIFEST.MF1
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ExceptionHandlerTests.java22
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/FilterTests.java9
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java10
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/MultiThreadedTestCase.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedIntTests.java5
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedObjectTests.java5
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/TestCommand.java18
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/AsynchronousCommandExecutorTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/AsynchronousCommandExecutorTests.java)18
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/AsynchronousRepeatingCommandWrapperTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/AsynchronousSynchronizerTests.java)126
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandExecutorTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandExecutorTests.java)33
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandRunnableTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandRunnableTests.java)9
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandTests.java)17
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CompositeCommandTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeCommandTests.java)11
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/JptUtilityCommandTests.java37
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java14
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java24
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionAspectAdapterTests.java22
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositePropertyValueModelTests.java14
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java118
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoublePropertyValueModelTests.java223
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java19
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptUtilityModelValueTests.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListAspectAdapterTests.java27
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyAspectAdapterTests.java15
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java35
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TreeAspectAdapterTests.java362
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/JptUtilitySynchronizersTests.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/SynchronousSynchronizerTests.java5
30 files changed, 644 insertions, 579 deletions
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/META-INF/MANIFEST.MF b/common/tests/org.eclipse.jpt.common.utility.tests/META-INF/MANIFEST.MF
index eeb203128b..2e830623fa 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/META-INF/MANIFEST.MF
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/META-INF/MANIFEST.MF
@@ -9,6 +9,7 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.jpt.common.utility;bundle-version="[2.0.0,3.0.0)",
org.junit;bundle-version="3.8.0"
Export-Package: org.eclipse.jpt.common.utility.tests.internal;x-internal:=true,
+ org.eclipse.jpt.common.utility.tests.internal.command;x-internal:=true,
org.eclipse.jpt.common.utility.tests.internal.enumerations;x-internal:=true,
org.eclipse.jpt.common.utility.tests.internal.iterables;x-internal:=true,
org.eclipse.jpt.common.utility.tests.internal.iterators;x-internal:=true,
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ExceptionHandlerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ExceptionHandlerTests.java
index 23097f3ab5..90f9977935 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ExceptionHandlerTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ExceptionHandlerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,7 +11,7 @@ package org.eclipse.jpt.common.utility.tests.internal;
import junit.framework.TestCase;
-import org.eclipse.jpt.common.utility.internal.ExceptionHandler;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
public class ExceptionHandlerTests extends TestCase {
@@ -29,8 +29,8 @@ public class ExceptionHandlerTests extends TestCase {
assertNotNull(exceptionHandler.toString());
}
- public void testRuntimeExceptionHandler() {
- Exception npe = new NullPointerException();
+ public void testRuntimeExceptionHandler1() {
+ Exception npe = new Exception();
ExceptionHandler exceptionHandler = ExceptionHandler.Runtime.instance();
boolean exCaught = false;
try {
@@ -43,6 +43,20 @@ public class ExceptionHandlerTests extends TestCase {
assertTrue(exCaught);
}
+ public void testRuntimeExceptionHandler2() {
+ Exception npe = new NullPointerException();
+ ExceptionHandler exceptionHandler = ExceptionHandler.Runtime.instance();
+ boolean exCaught = false;
+ try {
+ exceptionHandler.handleException(npe);
+ fail();
+ } catch (RuntimeException ex) {
+ assertSame(npe, ex);
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
public void testRuntimeExceptionHandlerToString() {
ExceptionHandler exceptionHandler = ExceptionHandler.Runtime.instance();
assertNotNull(exceptionHandler.toString());
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/FilterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/FilterTests.java
index b27a0a3543..44ec8ce09a 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/FilterTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/FilterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -21,19 +21,19 @@ public class FilterTests extends TestCase {
}
public void testNullFilter() {
- Filter<String> filter = Filter.Null.instance();
+ Filter<String> filter = Filter.Transparent.instance();
assertTrue(filter.accept(""));
assertTrue(filter.accept("foo"));
assertTrue(filter.accept("bar"));
}
public void testNullFilter_toString() {
- Filter<String> filter = Filter.Null.instance();
+ Filter<String> filter = Filter.Transparent.instance();
assertNotNull(filter.toString());
}
public void testNullFilter_serialization() throws Exception {
- Filter<String> filter = Filter.Null.instance();
+ Filter<String> filter = Filter.Transparent.instance();
assertSame(filter, TestTools.serialize(filter));
}
@@ -75,5 +75,4 @@ public class FilterTests extends TestCase {
Filter<String> filter = Filter.Disabled.instance();
assertSame(filter, TestTools.serialize(filter));
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java
index 883607e128..c62bad8a82 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,6 +11,7 @@ package org.eclipse.jpt.common.utility.tests.internal;
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.eclipse.jpt.common.utility.tests.internal.command.JptUtilityCommandTests;
import org.eclipse.jpt.common.utility.tests.internal.enumerations.JptUtilityEnumerationsTests;
import org.eclipse.jpt.common.utility.tests.internal.iterables.JptUtilityIterablesTests;
import org.eclipse.jpt.common.utility.tests.internal.iterators.JptUtilityIteratorsTests;
@@ -26,6 +27,7 @@ public class JptCommonUtilityTests {
public static Test suite() {
TestSuite suite = new TestSuite(JptCommonUtilityTests.class.getPackage().getName());
+ suite.addTest(JptUtilityCommandTests.suite());
suite.addTest(JptUtilityEnumerationsTests.suite());
suite.addTest(JptUtilityIterablesTests.suite());
suite.addTest(JptUtilityIteratorsTests.suite());
@@ -34,7 +36,6 @@ public class JptCommonUtilityTests {
suite.addTest(JptUtilitySynchronizersTests.suite());
suite.addTestSuite(ArrayToolsTests.class);
- suite.addTestSuite(AsynchronousCommandExecutorTests.class);
suite.addTestSuite(BagTests.class);
suite.addTestSuite(BidiFilterTests.class);
suite.addTestSuite(BidiStringConverterTests.class);
@@ -45,10 +46,6 @@ public class JptCommonUtilityTests {
suite.addTestSuite(ClasspathTests.class);
suite.addTestSuite(ClassNameTests.class);
suite.addTestSuite(CollectionToolsTests.class);
- suite.addTestSuite(CommandExecutorTests.class);
- suite.addTestSuite(CommandRunnableTests.class);
- suite.addTestSuite(CommandTests.class);
- suite.addTestSuite(CompositeCommandTests.class);
suite.addTestSuite(ExceptionHandlerTests.class);
suite.addTestSuite(FileToolsTests.class);
suite.addTestSuite(FilterTests.class);
@@ -87,5 +84,4 @@ public class JptCommonUtilityTests {
super();
throw new UnsupportedOperationException();
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/MultiThreadedTestCase.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/MultiThreadedTestCase.java
index 10ac313cc0..749253a198 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/MultiThreadedTestCase.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/MultiThreadedTestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -133,7 +133,7 @@ public abstract class MultiThreadedTestCase
public void run() {
try {
this.runnable.run();
- } catch (Throwable ex) {
+ } catch (RuntimeException ex) {
MultiThreadedTestCase.this.exceptions.add(ex);
}
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedIntTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedIntTests.java
index 18df9552c5..b666004427 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedIntTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedIntTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -310,7 +310,7 @@ public class SynchronizedIntTests
return new Command() {
public void execute(final SynchronizedInt sInt) throws InterruptedException {
sInt.execute(
- new org.eclipse.jpt.common.utility.Command() {
+ new org.eclipse.jpt.common.utility.command.Command() {
public void execute() {
// pretend to perform some long initialization process
try {
@@ -358,5 +358,4 @@ public class SynchronizedIntTests
private interface Command {
void execute(SynchronizedInt sInt) throws InterruptedException;
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedObjectTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedObjectTests.java
index cffe99690a..d0fa703b62 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedObjectTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedObjectTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -187,7 +187,7 @@ public class SynchronizedObjectTests
return new Command() {
public void execute(final SynchronizedObject<Object> sObject) throws InterruptedException {
sObject.execute(
- new org.eclipse.jpt.common.utility.Command() {
+ new org.eclipse.jpt.common.utility.command.Command() {
public void execute() {
// pretend to perform some long initialization process
try {
@@ -235,5 +235,4 @@ public class SynchronizedObjectTests
private interface Command {
void execute(SynchronizedObject<Object> so) throws InterruptedException;
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/TestCommand.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/TestCommand.java
new file mode 100644
index 0000000000..34040e489f
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/TestCommand.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal;
+
+/**
+ * Command that can be used to execute tests; i.e. a command that allows its
+ * implementation to throw exceptions.
+ */
+public interface TestCommand {
+ void execute() throws Exception;
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/AsynchronousCommandExecutorTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/AsynchronousCommandExecutorTests.java
index f8b32dcd28..767882fbd9 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/AsynchronousCommandExecutorTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/AsynchronousCommandExecutorTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,11 +7,13 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal;
+package org.eclipse.jpt.common.utility.tests.internal.command;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.internal.AsynchronousCommandExecutor;
-import org.eclipse.jpt.common.utility.internal.StatefulCommandExecutor;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.StatefulCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.command.AsynchronousExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.tests.internal.MultiThreadedTestCase;
public class AsynchronousCommandExecutorTests
extends MultiThreadedTestCase
@@ -22,7 +24,10 @@ public class AsynchronousCommandExecutorTests
public void testExecution() throws Exception {
TestCommand command = new TestCommand();
- StatefulCommandExecutor commandExecutor = new AsynchronousCommandExecutor(this.buildThreadFactory());
+ AsynchronousExtendedCommandExecutor.SimpleConfig config = new AsynchronousExtendedCommandExecutor.SimpleConfig();
+ config.setThreadFactory(this.buildThreadFactory());
+ config.setExceptionHandler(ExceptionHandler.Runtime.instance());
+ StatefulCommandExecutor commandExecutor = new AsynchronousExtendedCommandExecutor(config);
commandExecutor.start();
commandExecutor.execute(command);
commandExecutor.execute(command);
@@ -38,5 +43,4 @@ public class AsynchronousCommandExecutorTests
this.count++;
}
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/AsynchronousSynchronizerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/AsynchronousRepeatingCommandWrapperTests.java
index 3ddbadc460..975cf6aff4 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/AsynchronousSynchronizerTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/AsynchronousRepeatingCommandWrapperTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,31 +7,33 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal.synchronizers;
+package org.eclipse.jpt.common.utility.tests.internal.command;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.internal.CompositeException;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.RepeatingCommand;
+import org.eclipse.jpt.common.utility.internal.CollectingExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.ConsumerThreadCoordinator;
import org.eclipse.jpt.common.utility.internal.ReflectionTools;
-import org.eclipse.jpt.common.utility.internal.synchronizers.AsynchronousSynchronizer;
-import org.eclipse.jpt.common.utility.synchronizers.Synchronizer;
+import org.eclipse.jpt.common.utility.internal.command.AsynchronousRepeatingCommandWrapper;
import org.eclipse.jpt.common.utility.tests.internal.MultiThreadedTestCase;
@SuppressWarnings("nls")
-public class AsynchronousSynchronizerTests
+public class AsynchronousRepeatingCommandWrapperTests
extends MultiThreadedTestCase
{
PrimaryModel1 primaryModel1;
SecondaryModel1 secondaryModel1;
Command command1;
- Synchronizer synchronizer1;
+ RepeatingCommand repeatingCommand1;
PrimaryModel2 primaryModel2;
SecondaryModel2 secondaryModel2;
Command command2;
- Synchronizer synchronizer2;
+ RepeatingCommand repeatingCommand2;
- public AsynchronousSynchronizerTests(String name) {
+ public AsynchronousRepeatingCommandWrapperTests(String name) {
super(name);
}
@@ -41,20 +43,20 @@ public class AsynchronousSynchronizerTests
this.primaryModel1 = new PrimaryModel1();
this.secondaryModel1 = new SecondaryModel1(this.primaryModel1);
this.command1 = new SynchronizeSecondaryModelCommand1(this.secondaryModel1);
- this.synchronizer1 = new AsynchronousSynchronizer(this.command1, this.buildThreadFactory());
- this.primaryModel1.setSynchronizer(this.synchronizer1);
+ this.repeatingCommand1 = new AsynchronousRepeatingCommandWrapper(this.command1, this.buildThreadFactory(), null, ExceptionHandler.Runtime.instance());
+ this.primaryModel1.setSynchronizer(this.repeatingCommand1);
this.primaryModel2 = new PrimaryModel2();
this.secondaryModel2 = new SecondaryModel2(this.primaryModel2);
this.command2 = new SynchronizeSecondaryModelCommand2(this.primaryModel2, this.secondaryModel2);
- this.synchronizer2 = new AsynchronousSynchronizer(this.command2, this.buildThreadFactory());
- this.primaryModel2.setSynchronizer(this.synchronizer2);
+ this.repeatingCommand2 = new AsynchronousRepeatingCommandWrapper(this.command2, this.buildThreadFactory(), null, ExceptionHandler.Runtime.instance());
+ this.primaryModel2.setSynchronizer(this.repeatingCommand2);
}
@Override
protected void tearDown() throws Exception {
- this.synchronizer1.stop();
- this.synchronizer2.stop();
+ this.repeatingCommand1.stop();
+ this.repeatingCommand2.stop();
super.tearDown();
}
@@ -63,7 +65,7 @@ public class AsynchronousSynchronizerTests
}
public void testToString() {
- assertNotNull(this.synchronizer1.toString());
+ assertNotNull(this.repeatingCommand1.toString());
}
public void testChange() throws Exception {
@@ -71,34 +73,34 @@ public class AsynchronousSynchronizerTests
this.primaryModel1.setCount(7);
this.sleep(TICK);
- this.synchronizer1.stop();
+ this.repeatingCommand1.stop();
this.sleep(TICK);
assertEquals(14, this.secondaryModel1.getDoubleCount());
// re-start so tear-down works
- this.synchronizer1.start();
+ this.repeatingCommand1.start();
}
public void testStart() throws Exception {
assertEquals(4, this.secondaryModel1.getDoubleCount());
- this.primaryModel1.setSynchronizer(Synchronizer.Null.instance());
+ this.primaryModel1.setSynchronizer(RepeatingCommand.Null.instance());
this.primaryModel1.setCount(7);
assertEquals(4, this.secondaryModel1.getDoubleCount());
- this.primaryModel1.setSynchronizer(this.synchronizer1);
+ this.primaryModel1.setSynchronizer(this.repeatingCommand1);
// the async synchronizer does not synchronize at start-up
assertEquals(4, this.secondaryModel1.getDoubleCount());
this.primaryModel1.setCount(8);
this.sleep(TICK);
- this.synchronizer1.stop();
+ this.repeatingCommand1.stop();
this.sleep(TICK);
assertEquals(16, this.secondaryModel1.getDoubleCount());
// re-start so tear-down works
- this.synchronizer1.start();
+ this.repeatingCommand1.start();
}
public void testStop() throws Exception {
@@ -108,7 +110,7 @@ public class AsynchronousSynchronizerTests
assertEquals(4, this.secondaryModel1.getDoubleCount());
// re-start so tear-down works
- this.synchronizer1.start();
+ this.repeatingCommand1.start();
}
public void testDoubleStart() throws Exception {
@@ -124,13 +126,13 @@ public class AsynchronousSynchronizerTests
this.primaryModel1.setCount(7);
this.sleep(TICK);
- this.synchronizer1.stop();
+ this.repeatingCommand1.stop();
this.sleep(TICK);
assertEquals(14, this.secondaryModel1.getDoubleCount());
// re-start so tear-down works
- this.synchronizer1.start();
+ this.repeatingCommand1.start();
}
public void testDoubleStop() throws Exception {
@@ -148,7 +150,7 @@ public class AsynchronousSynchronizerTests
assertEquals(4, this.secondaryModel1.getDoubleCount());
// re-start so tear-down works
- this.synchronizer1.start();
+ this.repeatingCommand1.start();
}
public void testRecursiveChange() throws Exception {
@@ -166,7 +168,7 @@ public class AsynchronousSynchronizerTests
public void testNullCommand() {
boolean exCaught = false;
try {
- Synchronizer s = new AsynchronousSynchronizer(null, this.buildThreadFactory());
+ RepeatingCommand s = new AsynchronousRepeatingCommandWrapper(null, this.buildThreadFactory(), null, ExceptionHandler.Runtime.instance());
fail("bogus: " + s);
} catch (NullPointerException ex) {
exCaught = true;
@@ -174,8 +176,8 @@ public class AsynchronousSynchronizerTests
assertTrue(exCaught);
}
- public void testThreadName() {
- Synchronizer s = new AsynchronousSynchronizer(this.command1, this.buildThreadFactory(), "sync");
+ public void testThreadName() throws Exception {
+ RepeatingCommand s = new AsynchronousRepeatingCommandWrapper(this.command1, this.buildThreadFactory(), "sync", ExceptionHandler.Runtime.instance());
s.start();
ConsumerThreadCoordinator ctc = (ConsumerThreadCoordinator) ReflectionTools.getFieldValue(s, "consumerThreadCoordinator");
Thread t = (Thread) ReflectionTools.getFieldValue(ctc, "thread");
@@ -183,11 +185,11 @@ public class AsynchronousSynchronizerTests
s.stop();
}
- public void testSynchronizeCalledBeforeStart() throws Exception {
+ public void testExecuteCalledBeforeStart() throws Exception {
SimpleCommand command = new SimpleCommand();
- Synchronizer synchronizer = new AsynchronousSynchronizer(command, this.buildThreadFactory());
+ RepeatingCommand synchronizer = new AsynchronousRepeatingCommandWrapper(command, this.buildThreadFactory(), null, ExceptionHandler.Runtime.instance());
- synchronizer.synchronize();
+ synchronizer.execute();
synchronizer.start();
this.sleep(TICK);
synchronizer.stop();
@@ -203,24 +205,18 @@ public class AsynchronousSynchronizerTests
public void testException() throws Exception {
BogusCommand command = new BogusCommand();
- Synchronizer synchronizer = new AsynchronousSynchronizer(command, this.buildThreadFactory());
+ CollectingExceptionHandler exHandler = new CollectingExceptionHandler();
+ RepeatingCommand synchronizer = new AsynchronousRepeatingCommandWrapper(command, this.buildThreadFactory(), null, exHandler);
synchronizer.start();
- synchronizer.synchronize();
+ synchronizer.execute();
this.sleep(TICK);
- synchronizer.synchronize();
+ synchronizer.execute();
this.sleep(TICK);
- boolean exCaught = false;
- try {
- synchronizer.stop();
- fail();
- } catch (CompositeException ex) {
- assertEquals(2, ex.getExceptions().length);
- exCaught = true;
- }
- assertTrue(exCaught);
+ synchronizer.stop();
+ assertEquals(2, CollectionTools.size(exHandler.getExceptions()));
assertEquals(2, command.count);
}
@@ -234,7 +230,10 @@ public class AsynchronousSynchronizerTests
// ********** synchronize commands **********
- public static class SynchronizeSecondaryModelCommand1 implements Command {
+
+ public static class SynchronizeSecondaryModelCommand1
+ implements Command
+ {
private final SecondaryModel1 secondaryModel;
public SynchronizeSecondaryModelCommand1(SecondaryModel1 secondaryModel) {
@@ -245,13 +244,14 @@ public class AsynchronousSynchronizerTests
public void execute() {
this.secondaryModel.synchronize();
}
-
}
/**
* the primary model (subclass) has to synchronize with itself (superclass)
*/
- public static class SynchronizeSecondaryModelCommand2 extends SynchronizeSecondaryModelCommand1 {
+ public static class SynchronizeSecondaryModelCommand2
+ extends SynchronizeSecondaryModelCommand1
+ {
private final PrimaryModel2 primaryModel;
public SynchronizeSecondaryModelCommand2(PrimaryModel2 primaryModel, SecondaryModel2 secondaryModel) {
@@ -264,21 +264,22 @@ public class AsynchronousSynchronizerTests
super.execute();
this.primaryModel.synchronize();
}
-
}
+
// ********** primary models **********
+
/**
* this object will call the synchronizer whenever its count changes,
* allowing interested parties to synchronize with the change
*/
public static class PrimaryModel1 {
- protected Synchronizer synchronizer;
+ protected RepeatingCommand synchronizer;
protected int count = 2;
public PrimaryModel1() {
super();
- this.setSynchronizer_(Synchronizer.Null.instance());
+ this.setSynchronizer_(RepeatingCommand.Null.instance());
}
public int getCount() {
@@ -292,10 +293,10 @@ public class AsynchronousSynchronizerTests
}
protected void stateChanged() {
- this.synchronizer.synchronize();
+ this.synchronizer.execute();
}
- public void setSynchronizer(Synchronizer synchronizer) {
+ public void setSynchronizer(RepeatingCommand synchronizer) throws InterruptedException {
if (synchronizer == null) {
throw new NullPointerException();
}
@@ -303,7 +304,7 @@ public class AsynchronousSynchronizerTests
this.setSynchronizer_(synchronizer);
}
- protected void setSynchronizer_(Synchronizer synchronizer) {
+ protected void setSynchronizer_(RepeatingCommand synchronizer) {
this.synchronizer = synchronizer;
this.synchronizer.start();
}
@@ -311,7 +312,7 @@ public class AsynchronousSynchronizerTests
public void startSynchronizer() {
this.synchronizer.start(); // this should cause an exception
}
- public void dispose() {
+ public void dispose() throws InterruptedException {
this.synchronizer.stop();
}
@@ -328,7 +329,6 @@ public class AsynchronousSynchronizerTests
sb.append("count=");
sb.append(this.count);
}
-
}
/**
@@ -336,7 +336,9 @@ public class AsynchronousSynchronizerTests
* with the change. Whenever the [inherited] 'count' changes, 'countPlus3'
* is updated appropriately and another synchronize is initiated if appropriate.
*/
- public static class PrimaryModel2 extends PrimaryModel1 {
+ public static class PrimaryModel2
+ extends PrimaryModel1
+ {
private int countPlus3 = 0;
public PrimaryModel2() {
@@ -365,10 +367,11 @@ public class AsynchronousSynchronizerTests
sb.append(", countPlus3=");
sb.append(this.countPlus3);
}
-
}
+
// ********** secondary models **********
+
/**
* This dependent object updates its 'doubleCount' whenever the
* PrimaryModel1's 'count' changes, via the 'synchronizer'.
@@ -404,10 +407,11 @@ public class AsynchronousSynchronizerTests
sb.append("doubleCount=");
sb.append(this.doubleCount);
}
-
}
- public static class SecondaryModel2 extends SecondaryModel1 {
+ public static class SecondaryModel2
+ extends SecondaryModel1
+ {
private int doubleCountPlus3 = 0;
public SecondaryModel2(PrimaryModel2 extendedPrimaryModel) {
@@ -437,7 +441,5 @@ public class AsynchronousSynchronizerTests
sb.append(", doubleCountPlus3=");
sb.append(this.doubleCountPlus3);
}
-
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandExecutorTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandExecutorTests.java
index 693b9c91b4..cb7d75ea1e 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandExecutorTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandExecutorTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,11 +7,14 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal;
+package org.eclipse.jpt.common.utility.tests.internal.command;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.CommandExecutor;
-import org.eclipse.jpt.common.utility.internal.ThreadLocalCommandExecutor;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.command.ThreadLocalExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.tests.internal.MultiThreadedTestCase;
+import org.eclipse.jpt.common.utility.tests.internal.TestTools;
public class CommandExecutorTests
extends MultiThreadedTestCase
@@ -48,12 +51,12 @@ public class CommandExecutorTests
}
public void testThreadLocalCommandExecutor_toString() throws Exception {
- CommandExecutor commandExecutor = new ThreadLocalCommandExecutor();
+ CommandExecutor commandExecutor = new ThreadLocalExtendedCommandExecutor();
assertNotNull(commandExecutor.toString());
}
public void testThreadLocalCommandExecutor() throws Exception {
- ThreadLocalCommandExecutor threadLocalCommandExecutor = new ThreadLocalCommandExecutor();
+ ThreadLocalExtendedCommandExecutor threadLocalCommandExecutor = new ThreadLocalExtendedCommandExecutor();
TestRunnable testRunnable1 = new TestRunnable(threadLocalCommandExecutor, 1);
Thread thread1 = this.buildThread(testRunnable1);
thread1.run();
@@ -80,23 +83,30 @@ public class CommandExecutorTests
assertNull(testRunnable3.testCommandExecutor);
}
- static class TestCommandExecutor implements CommandExecutor {
+ static class TestCommandExecutor implements ExtendedCommandExecutor {
int count = 0;
public void execute(Command command) {
this.count++;
command.execute();
}
+ public void waitToExecute(Command command) {
+ this.execute(command);
+ }
+ public boolean waitToExecute(Command command, long timeout) {
+ this.execute(command);
+ return true;
+ }
}
static class TestRunnable implements Runnable {
- final ThreadLocalCommandExecutor threadLocalCommandExecutor;
+ final ThreadLocalExtendedCommandExecutor threadLocalCommandExecutor;
final int executionCount;
final TestCommand testCommand = new TestCommand();
final TestCommandExecutor testCommandExecutor;
- TestRunnable(ThreadLocalCommandExecutor threadLocalCommandExecutor, int executionCount) {
+ TestRunnable(ThreadLocalExtendedCommandExecutor threadLocalCommandExecutor, int executionCount) {
this(threadLocalCommandExecutor, executionCount, new TestCommandExecutor());
}
- TestRunnable(ThreadLocalCommandExecutor threadLocalCommandExecutor, int executionCount, TestCommandExecutor testCommandExecutor) {
+ TestRunnable(ThreadLocalExtendedCommandExecutor threadLocalCommandExecutor, int executionCount, TestCommandExecutor testCommandExecutor) {
super();
this.threadLocalCommandExecutor = threadLocalCommandExecutor;
this.executionCount = executionCount;
@@ -109,5 +119,4 @@ public class CommandExecutorTests
}
}
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandRunnableTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandRunnableTests.java
index 623b2b2449..d5dce4e56c 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandRunnableTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandRunnableTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,12 +7,12 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal;
+package org.eclipse.jpt.common.utility.tests.internal.command;
import junit.framework.TestCase;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.internal.CommandRunnable;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.internal.command.CommandRunnable;
@SuppressWarnings("nls")
public class CommandRunnableTests extends TestCase {
@@ -51,5 +51,4 @@ public class CommandRunnableTests extends TestCase {
}
};
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandTests.java
index 0eb8392e8b..266a0101e4 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,13 +7,15 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal;
+package org.eclipse.jpt.common.utility.tests.internal.command;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.CommandExecutor;
-import org.eclipse.jpt.common.utility.internal.CommandRunnable;
-import org.eclipse.jpt.common.utility.internal.RunnableCommand;
-import org.eclipse.jpt.common.utility.internal.ThreadLocalCommand;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+import org.eclipse.jpt.common.utility.internal.command.CommandRunnable;
+import org.eclipse.jpt.common.utility.internal.command.RunnableCommand;
+import org.eclipse.jpt.common.utility.internal.command.ThreadLocalCommand;
+import org.eclipse.jpt.common.utility.tests.internal.MultiThreadedTestCase;
+import org.eclipse.jpt.common.utility.tests.internal.TestTools;
public class CommandTests
extends MultiThreadedTestCase
@@ -133,5 +135,4 @@ public class CommandTests
}
}
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeCommandTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CompositeCommandTests.java
index cfabc54bef..69aa1f8c8d 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeCommandTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CompositeCommandTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,13 +7,13 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal;
+package org.eclipse.jpt.common.utility.tests.internal.command;
import junit.framework.TestCase;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.internal.CommandRunnable;
-import org.eclipse.jpt.common.utility.internal.CompositeCommand;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.internal.command.CommandRunnable;
+import org.eclipse.jpt.common.utility.internal.command.CompositeCommand;
public class CompositeCommandTests extends TestCase {
boolean command1Executed = false;
@@ -57,5 +57,4 @@ public class CompositeCommandTests extends TestCase {
}
};
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/JptUtilityCommandTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/JptUtilityCommandTests.java
new file mode 100644
index 0000000000..6d40c97327
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/JptUtilityCommandTests.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.command;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * decentralize test creation code
+ */
+public class JptUtilityCommandTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(JptUtilityCommandTests.class.getPackage().getName());
+
+ suite.addTestSuite(AsynchronousCommandExecutorTests.class);
+ suite.addTestSuite(AsynchronousRepeatingCommandWrapperTests.class);
+ suite.addTestSuite(CommandExecutorTests.class);
+ suite.addTestSuite(CommandRunnableTests.class);
+ suite.addTestSuite(CommandTests.class);
+ suite.addTestSuite(CompositeCommandTests.class);
+
+ return suite;
+ }
+
+ private JptUtilityCommandTests() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java
index f17f265cf1..f7c7e31cef 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,11 +10,10 @@
package org.eclipse.jpt.common.utility.tests.internal.model.value;
import junit.framework.TestCase;
-
import org.eclipse.jpt.common.utility.internal.BidiTransformer;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
-import org.eclipse.jpt.common.utility.internal.model.value.CachingTransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
@@ -39,7 +38,7 @@ public class CachingTransformationPropertyValueModelTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
this.objectHolder = new SimplePropertyValueModel<Person>(new Person("Karen", "Peggy", null));
- this.transformationObjectHolder = new CachingTransformationPropertyValueModel<Person, Person>(this.objectHolder, this.buildTransformer());
+ this.transformationObjectHolder = new TransformationPropertyValueModel<Person, Person>(this.objectHolder, this.buildTransformer());
}
private BidiTransformer<Person, Person> buildTransformer() {
@@ -192,8 +191,9 @@ public class CachingTransformationPropertyValueModelTests extends TestCase {
}
- class Person extends AbstractModel {
-
+ class Person
+ extends AbstractModel
+ {
private String name;
public static final String NAME_PROPERTY = "name";
@@ -235,7 +235,5 @@ public class CachingTransformationPropertyValueModelTests extends TestCase {
public Person getChild() {
return this.child;
}
-
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java
index 3560f4a814..2304cd293e 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,11 +10,10 @@
package org.eclipse.jpt.common.utility.tests.internal.model.value;
import junit.framework.TestCase;
-
-import org.eclipse.jpt.common.utility.internal.BidiTransformer;
+import org.eclipse.jpt.common.utility.internal.Transformer;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
-import org.eclipse.jpt.common.utility.internal.model.value.CachingTransformationWritablePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.TransformationWritablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
@@ -23,7 +22,9 @@ import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.common.utility.tests.internal.TestTools;
@SuppressWarnings("nls")
-public class CachingTransformationWritablePropertyValueModelTests extends TestCase {
+public class CachingTransformationWritablePropertyValueModelTests
+ extends TestCase
+{
private WritablePropertyValueModel<Person> objectHolder;
PropertyChangeEvent event;
@@ -38,15 +39,20 @@ public class CachingTransformationWritablePropertyValueModelTests extends TestCa
protected void setUp() throws Exception {
super.setUp();
this.objectHolder = new SimplePropertyValueModel<Person>(new Person("Karen", "Peggy", null));
- this.transformationObjectHolder = new CachingTransformationWritablePropertyValueModel<Person, Person>(this.objectHolder, this.buildTransformer());
+ this.transformationObjectHolder = new TransformationWritablePropertyValueModel<Person, Person>(this.objectHolder, this.buildTransformer(), this.buildReverseTransformer());
}
- private BidiTransformer<Person, Person> buildTransformer() {
- return new BidiTransformer<Person, Person>() {
+ private Transformer<Person, Person> buildTransformer() {
+ return new Transformer<Person, Person>() {
public Person transform(Person p) {
return (p == null) ? null : p.getParent();
}
- public Person reverseTransform(Person p) {
+ };
+ }
+
+ private Transformer<Person, Person> buildReverseTransformer() {
+ return new Transformer<Person, Person>() {
+ public Person transform(Person p) {
return (p == null) ? null : p.getChild();
}
};
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionAspectAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionAspectAdapterTests.java
index b9542f9d21..470b3cf096 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionAspectAdapterTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionAspectAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -326,22 +326,22 @@ public class CollectionAspectAdapterTests extends TestCase {
@Override
protected Iterator<String> iterator_() {
- if (this.collectionNames[0] == TestSubject.NAMES_COLLECTION) {
+ if (this.aspectNames[0] == TestSubject.NAMES_COLLECTION) {
return this.subject.names();
}
- if (this.collectionNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) {
+ if (this.aspectNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) {
return this.subject.descriptions();
}
- throw new IllegalStateException("invalid aspect name: " + this.collectionNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
public void add(String item) {
- if (this.collectionNames[0] == TestSubject.NAMES_COLLECTION) {
+ if (this.aspectNames[0] == TestSubject.NAMES_COLLECTION) {
this.subject.addName(item);
- } else if (this.collectionNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) {
this.subject.addDescription(item);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.collectionNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
@@ -352,12 +352,12 @@ public class CollectionAspectAdapterTests extends TestCase {
}
public void remove(Object item) {
- if (this.collectionNames[0] == TestSubject.NAMES_COLLECTION) {
+ if (this.aspectNames[0] == TestSubject.NAMES_COLLECTION) {
this.subject.removeName((String) item);
- } else if (this.collectionNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) {
this.subject.removeDescription((String) item);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.collectionNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
@@ -366,7 +366,5 @@ public class CollectionAspectAdapterTests extends TestCase {
this.remove(stream.next());
}
}
-
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java
index 559c12635d..7791fb2b37 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java
@@ -189,7 +189,7 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
* otherwise the value is false
*/
static class LocalAdapter
- extends CollectionPropertyValueModelAdapter<Boolean>
+ extends CollectionPropertyValueModelAdapter<Boolean, String>
implements WritablePropertyValueModel<Boolean>
{
private String item;
@@ -234,7 +234,5 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
private boolean booleanValueOf(Object b) {
return (b == null) ? false : ((Boolean) b).booleanValue();
}
-
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositePropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositePropertyValueModelTests.java
index 5fa2413fea..a9cd9c9cdb 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositePropertyValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositePropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -57,21 +57,16 @@ public class CompositePropertyValueModelTests extends TestCase {
this.compositePVM = this.buildCompositePVM(cvm);
}
- private <T extends PropertyValueModel<?>> PropertyValueModel<Integer> buildCompositePVM(CollectionValueModel<T> pvms) {
- return new CompositePropertyValueModel<Integer>(pvms) {
+ private <T extends PropertyValueModel<Integer>> PropertyValueModel<Integer> buildCompositePVM(CollectionValueModel<T> pvms) {
+ return new CompositePropertyValueModel<Integer, Integer>(pvms) {
@Override
protected Integer buildValue() {
int sum = 0;
- for (PropertyValueModel<Integer> each : this.getCollectionModel()) {
+ for (PropertyValueModel<? extends Integer> each : this.collectionModel) {
sum += each.getValue().intValue();
}
return Integer.valueOf(sum);
}
- @Override
- @SuppressWarnings("unchecked")
- protected CollectionValueModel<PropertyValueModel<Integer>> getCollectionModel() {
- return (CollectionValueModel<PropertyValueModel<Integer>>) super.getCollectionModel();
- }
};
}
@@ -195,5 +190,4 @@ public class CompositePropertyValueModelTests extends TestCase {
assertEquals(Integer.valueOf(oldValue), this.event.getOldValue());
assertEquals(Integer.valueOf(newValue), this.event.getNewValue());
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java
new file mode 100644
index 0000000000..785f5ec099
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.model.value;
+
+import org.eclipse.jpt.common.utility.internal.model.value.DoubleModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
+
+@SuppressWarnings("nls")
+public class DoubleModifiablePropertyValueModelTests
+ extends DoublePropertyValueModelTests
+{
+ public DoubleModifiablePropertyValueModelTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected PropertyValueModel<String> buildDoubleModel() {
+ return new DoubleModifiablePropertyValueModel<String>(this.stringModelModel);
+ }
+
+ protected WritablePropertyValueModel<String> getDoubleModel() {
+ return (WritablePropertyValueModel<String>) this.doubleModel;
+ }
+
+ public void testSetValue() {
+ assertEquals("foo", this.stringModel.getValue());
+ assertEquals(this.stringModel, this.stringModelModel.getValue());
+ assertNull(this.doubleModel.getValue());
+ this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ assertEquals("foo", this.doubleModel.getValue());
+
+ this.getDoubleModel().setValue("bar");
+ assertEquals("bar", this.stringModel.getValue());
+ assertEquals("bar", this.doubleModel.getValue());
+
+ this.stringModelModel.setValue(null);
+ assertNull(this.doubleModel.getValue());
+ this.getDoubleModel().setValue("TTT"); // NOP?
+ assertEquals("bar", this.stringModel.getValue());
+ assertNull(this.doubleModel.getValue());
+ }
+
+ public void testPropertyChange3() {
+ this.stringModel.addChangeListener(this.stringModelListener);
+ this.stringModelModel.addChangeListener(this.stringModelModelListener);
+ this.doubleModel.addChangeListener(this.doubleModelListener);
+ this.verifyPropertyChanges2();
+ }
+
+ public void testPropertyChange4() {
+ this.stringModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.stringModelListener);
+ this.stringModelModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.stringModelModelListener);
+ this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ this.verifyPropertyChanges2();
+ }
+
+ protected void verifyPropertyChanges2() {
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.getDoubleModel().setValue("bar");
+ this.verifyEvent(this.stringModelEvent, this.stringModel, "foo", "bar");
+ assertNull(this.stringModelModelEvent);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "foo", "bar");
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.getDoubleModel().setValue(null);
+ this.verifyEvent(this.stringModelEvent, this.stringModel, "bar", null);
+ assertNull(this.stringModelModelEvent);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "bar", null);
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.getDoubleModel().setValue("foo");
+ this.verifyEvent(this.stringModelEvent, this.stringModel, null, "foo");
+ assertNull(this.stringModelModelEvent);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, null, "foo");
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ WritablePropertyValueModel<String> stringModel2 = new SimplePropertyValueModel<String>("TTT");
+ this.stringModelModel.setValue(stringModel2);
+ assertNull(this.stringModelEvent);
+ this.verifyEvent(this.stringModelModelEvent, this.stringModelModel, this.stringModel, stringModel2);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "foo", "TTT");
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.getDoubleModel().setValue("XXX");
+ assertNull(this.stringModelEvent);
+ assertNull(this.stringModelModelEvent);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "TTT", "XXX");
+ assertEquals("foo", this.stringModel.getValue());
+ assertEquals("XXX", stringModel2.getValue());
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.stringModelModel.setValue(this.stringModel);
+ assertNull(this.stringModelEvent);
+ this.verifyEvent(this.stringModelModelEvent, this.stringModelModel, stringModel2, this.stringModel);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "XXX", "foo");
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoublePropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoublePropertyValueModelTests.java
new file mode 100644
index 0000000000..b8d8be9684
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoublePropertyValueModelTests.java
@@ -0,0 +1,223 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.model.value;
+
+import junit.framework.TestCase;
+import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
+import org.eclipse.jpt.common.utility.internal.model.value.DoublePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
+import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
+import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+
+@SuppressWarnings("nls")
+public class DoublePropertyValueModelTests
+ extends TestCase
+{
+ protected WritablePropertyValueModel<String> stringModel;
+ protected ChangeListener stringModelListener;
+ protected PropertyChangeEvent stringModelEvent;
+
+ protected WritablePropertyValueModel<WritablePropertyValueModel<String>> stringModelModel;
+ protected ChangeListener stringModelModelListener;
+ protected PropertyChangeEvent stringModelModelEvent;
+
+ protected PropertyValueModel<String> doubleModel;
+ protected ChangeListener doubleModelListener;
+ protected PropertyChangeEvent doubleModelEvent;
+
+ public DoublePropertyValueModelTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.stringModel = new SimplePropertyValueModel<String>("foo");
+ this.stringModelListener = new StringModelListener();
+
+ this.stringModelModel = new SimplePropertyValueModel<WritablePropertyValueModel<String>>(stringModel);
+ this.stringModelModelListener = new StringModelModelListener();
+
+ this.doubleModel = this.buildDoubleModel();
+ this.doubleModelListener = new DoubleModelListener();
+ }
+
+ protected PropertyValueModel<String> buildDoubleModel() {
+ return new DoublePropertyValueModel<String>(this.stringModelModel);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TestTools.clear(this);
+ super.tearDown();
+ }
+
+ public void testGetValue1() {
+ assertEquals("foo", this.stringModel.getValue());
+ assertEquals(this.stringModel, this.stringModelModel.getValue());
+ assertNull(this.doubleModel.getValue());
+ this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ assertEquals("foo", this.doubleModel.getValue());
+
+ this.stringModel.setValue("bar");
+ assertEquals("bar", this.stringModel.getValue());
+ assertEquals("bar", this.doubleModel.getValue());
+
+ this.stringModel.setValue("baz");
+ assertEquals("baz", this.stringModel.getValue());
+ assertEquals("baz", this.doubleModel.getValue());
+
+ this.stringModel.setValue(null);
+ assertNull(this.stringModel.getValue());
+ assertNull(this.doubleModel.getValue());
+
+ this.stringModel.setValue("foo");
+ assertEquals("foo", this.stringModel.getValue());
+ assertEquals("foo", this.doubleModel.getValue());
+ }
+
+ public void testGetValue2() {
+ assertNull(this.doubleModel.getValue());
+ this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ assertEquals("foo", this.doubleModel.getValue());
+
+ this.stringModelModel.setValue(null);
+ assertNull(this.doubleModel.getValue());
+
+ WritablePropertyValueModel<String> stringModel2 = new SimplePropertyValueModel<String>("TTT");
+ this.stringModelModel.setValue(stringModel2);
+ assertEquals("TTT", this.doubleModel.getValue());
+
+ this.stringModelModel.setValue(this.stringModel);
+ assertEquals("foo", this.doubleModel.getValue());
+ }
+
+ public void testLazyListening() {
+ assertTrue(((AbstractModel) this.stringModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.stringModelModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.doubleModel.addChangeListener(this.doubleModelListener);
+ assertTrue(((AbstractModel) this.stringModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.stringModelModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.doubleModel.removeChangeListener(this.doubleModelListener);
+ assertTrue(((AbstractModel) this.stringModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.stringModelModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ assertTrue(((AbstractModel) this.stringModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.doubleModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ assertTrue(((AbstractModel) this.stringModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ WritablePropertyValueModel<String> stringModel2 = new SimplePropertyValueModel<String>("TTT");
+ assertTrue(((AbstractModel) this.stringModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) stringModel2).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.stringModelModel.setValue(stringModel2);
+ assertTrue(((AbstractModel) this.stringModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) stringModel2).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.stringModelModel.setValue(this.stringModel);
+ assertTrue(((AbstractModel) this.stringModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) stringModel2).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ }
+
+ public void testPropertyChange1() {
+ this.stringModel.addChangeListener(this.stringModelListener);
+ this.stringModelModel.addChangeListener(this.stringModelModelListener);
+ this.doubleModel.addChangeListener(this.doubleModelListener);
+ this.verifyPropertyChanges1();
+ }
+
+ public void testPropertyChange2() {
+ this.stringModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.stringModelListener);
+ this.stringModelModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.stringModelModelListener);
+ this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ this.verifyPropertyChanges1();
+ }
+
+ protected void verifyPropertyChanges1() {
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.stringModel.setValue("bar");
+ this.verifyEvent(this.stringModelEvent, this.stringModel, "foo", "bar");
+ assertNull(this.stringModelModelEvent);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "foo", "bar");
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.stringModel.setValue(null);
+ this.verifyEvent(this.stringModelEvent, this.stringModel, "bar", null);
+ assertNull(this.stringModelModelEvent);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "bar", null);
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.stringModel.setValue("foo");
+ this.verifyEvent(this.stringModelEvent, this.stringModel, null, "foo");
+ assertNull(this.stringModelModelEvent);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, null, "foo");
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ WritablePropertyValueModel<String> stringModel2 = new SimplePropertyValueModel<String>("TTT");
+ this.stringModelModel.setValue(stringModel2);
+ assertNull(this.stringModelEvent);
+ this.verifyEvent(this.stringModelModelEvent, this.stringModelModel, this.stringModel, stringModel2);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "foo", "TTT");
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.stringModelModel.setValue(this.stringModel);
+ assertNull(this.stringModelEvent);
+ this.verifyEvent(this.stringModelModelEvent, this.stringModelModel, stringModel2, this.stringModel);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "TTT", "foo");
+ }
+
+ protected void verifyEvent(PropertyChangeEvent event, Object source, Object oldValue, Object newValue) {
+ assertEquals(source, event.getSource());
+ assertEquals(PropertyValueModel.VALUE, event.getPropertyName());
+ assertEquals(oldValue, event.getOldValue());
+ assertEquals(newValue, event.getNewValue());
+ }
+
+ protected class StringModelListener
+ extends ChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ DoublePropertyValueModelTests.this.stringModelEvent = event;
+ }
+ }
+
+ protected class StringModelModelListener
+ extends ChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ DoublePropertyValueModelTests.this.stringModelModelEvent = event;
+ }
+ }
+
+ protected class DoubleModelListener
+ extends ChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ DoublePropertyValueModelTests.this.doubleModelEvent = event;
+ }
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java
index a20db7f063..1f081b1b0f 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,8 +10,7 @@
package org.eclipse.jpt.common.utility.tests.internal.model.value;
import junit.framework.TestCase;
-
-import org.eclipse.jpt.common.utility.internal.BidiFilter;
+import org.eclipse.jpt.common.utility.Filter;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
import org.eclipse.jpt.common.utility.internal.model.value.FilteringWritablePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
@@ -38,15 +37,20 @@ public class FilteringPropertyValueModelTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
this.objectHolder = new SimplePropertyValueModel<String>("foo");
- this.filteredObjectHolder = new FilteringWritablePropertyValueModel<String>(this.objectHolder, this.buildFilter());
+ this.filteredObjectHolder = new FilteringWritablePropertyValueModel<String>(this.objectHolder, this.buildFilter(), this.buildSetFilter());
}
- private BidiFilter<String> buildFilter() {
- return new BidiFilter<String>() {
+ private Filter<String> buildFilter() {
+ return new Filter<String>() {
public boolean accept(String s) {
return (s != null) && s.startsWith("b");
}
- public boolean reverseAccept(String s) {
+ };
+ }
+
+ private Filter<String> buildSetFilter() {
+ return new Filter<String>() {
+ public boolean accept(String s) {
return (s != null) && s.startsWith("b");
}
};
@@ -187,5 +191,4 @@ public class FilteringPropertyValueModelTests extends TestCase {
assertEquals(oldValue, e.getOldValue());
assertEquals(newValue, e.getNewValue());
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptUtilityModelValueTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptUtilityModelValueTests.java
index 9812dd32bd..8f256b46f3 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptUtilityModelValueTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptUtilityModelValueTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,13 +15,13 @@ import org.eclipse.jpt.common.utility.tests.internal.model.value.prefs.JptUtilit
import org.eclipse.jpt.common.utility.tests.internal.model.value.swing.JptUtilityModelValueSwingTests;
public class JptUtilityModelValueTests {
-
+
public static Test suite() {
TestSuite suite = new TestSuite(JptUtilityModelValueTests.class.getPackage().getName());
suite.addTest(JptUtilityModelValuePrefsTests.suite());
suite.addTest(JptUtilityModelValueSwingTests.suite());
-
+
suite.addTestSuite(BufferedWritablePropertyValueModelTests.class);
suite.addTestSuite(CachingTransformationPropertyValueModelTests.class);
suite.addTestSuite(CachingTransformationWritablePropertyValueModelTests.class);
@@ -32,6 +32,8 @@ public class JptUtilityModelValueTests {
suite.addTestSuite(CompositeCollectionValueModelTests.class);
suite.addTestSuite(CompositeListValueModelTests.class);
suite.addTestSuite(CompositePropertyValueModelTests.class);
+ suite.addTestSuite(DoublePropertyValueModelTests.class);
+ suite.addTestSuite(DoubleModifiablePropertyValueModelTests.class);
suite.addTestSuite(ExtendedListValueModelWrapperTests.class);
suite.addTestSuite(FilteringCollectionValueModelTests.class);
suite.addTestSuite(FilteringPropertyValueModelTests.class);
@@ -61,7 +63,6 @@ public class JptUtilityModelValueTests {
suite.addTestSuite(TransformationListValueModelTests.class);
suite.addTestSuite(TransformationListValueModelTests.TransformerTests.class);
suite.addTestSuite(TransformationPropertyValueModelTests.class);
- suite.addTestSuite(TreeAspectAdapterTests.class);
suite.addTestSuite(ValueCollectionAdapterTests.class);
suite.addTestSuite(ValueListAdapterTests.class);
suite.addTestSuite(ValuePropertyAdapterTests.class);
@@ -69,10 +70,9 @@ public class JptUtilityModelValueTests {
return suite;
}
-
+
private JptUtilityModelValueTests() {
super();
throw new UnsupportedOperationException();
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListAspectAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListAspectAdapterTests.java
index d6f3fd2999..e0a12398d7 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListAspectAdapterTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListAspectAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -419,22 +419,22 @@ public class ListAspectAdapterTests extends TestCase {
@Override
protected ListIterator<String> listIterator_() {
- if (this.listNames[0] == TestSubject.NAMES_LIST) {
+ if (this.aspectNames[0] == TestSubject.NAMES_LIST) {
return this.subject.names();
- } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTIONS_LIST) {
return this.subject.descriptions();
} else {
- throw new IllegalStateException("invalid aspect name: " + this.listNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
public void add(int index, Object item) {
- if (this.listNames[0] == TestSubject.NAMES_LIST) {
+ if (this.aspectNames[0] == TestSubject.NAMES_LIST) {
this.subject.addName(index, (String) item);
- } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTIONS_LIST) {
this.subject.addDescription(index, (String) item);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.listNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
@@ -445,12 +445,12 @@ public class ListAspectAdapterTests extends TestCase {
}
public String remove(int index) {
- if (this.listNames[0] == TestSubject.NAMES_LIST) {
+ if (this.aspectNames[0] == TestSubject.NAMES_LIST) {
return this.subject.removeName(index);
- } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTIONS_LIST) {
return this.subject.removeDescription(index);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.listNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
@@ -463,14 +463,13 @@ public class ListAspectAdapterTests extends TestCase {
}
public Object replace(int index, Object item) {
- if (this.listNames[0] == TestSubject.NAMES_LIST) {
+ if (this.aspectNames[0] == TestSubject.NAMES_LIST) {
return this.subject.setName(index, (String) item);
- } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTIONS_LIST) {
return this.subject.setDescription(index, (String) item);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.listNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyAspectAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyAspectAdapterTests.java
index a9a4ec6c28..3e6aaae055 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyAspectAdapterTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyAspectAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -59,22 +59,22 @@ public class PropertyAspectAdapterTests extends TestCase {
// this is not a aspect adapter - the value is determined by the aspect name
@Override
protected String buildValue_() {
- if (this.propertyNames[0] == TestSubject.NAME_PROPERTY) {
+ if (this.aspectNames[0] == TestSubject.NAME_PROPERTY) {
return this.subject.getName();
- } else if (this.propertyNames[0] == TestSubject.DESCRIPTION_PROPERTY) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTION_PROPERTY) {
return this.subject.getDescription();
} else {
- throw new IllegalStateException("invalid aspect name: " + this.propertyNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
@Override
protected void setValue_(String value) {
- if (this.propertyNames[0] == TestSubject.NAME_PROPERTY) {
+ if (this.aspectNames[0] == TestSubject.NAME_PROPERTY) {
this.subject.setName(value);
- } else if (this.propertyNames[0] == TestSubject.DESCRIPTION_PROPERTY) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTION_PROPERTY) {
this.subject.setDescription(value);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.propertyNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
};
@@ -340,5 +340,4 @@ public class PropertyAspectAdapterTests extends TestCase {
this.firePropertyChanged(DESCRIPTION_PROPERTY, old, description);
}
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java
index 8344919d69..156cf8115a 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,8 +10,7 @@
package org.eclipse.jpt.common.utility.tests.internal.model.value;
import junit.framework.TestCase;
-
-import org.eclipse.jpt.common.utility.internal.BidiTransformer;
+import org.eclipse.jpt.common.utility.internal.Transformer;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationWritablePropertyValueModel;
@@ -23,7 +22,9 @@ import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.common.utility.tests.internal.TestTools;
@SuppressWarnings("nls")
-public class TransformationPropertyValueModelTests extends TestCase {
+public class TransformationPropertyValueModelTests
+ extends TestCase
+{
private WritablePropertyValueModel<String> objectHolder;
PropertyChangeEvent event;
@@ -38,15 +39,20 @@ public class TransformationPropertyValueModelTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
this.objectHolder = new SimplePropertyValueModel<String>("foo");
- this.transformationObjectHolder = new TransformationWritablePropertyValueModel<String, String>(this.objectHolder, this.buildTransformer());
+ this.transformationObjectHolder = new TransformationWritablePropertyValueModel<String, String>(this.objectHolder, this.buildTransformer(), this.buildReverseTransformer());
}
- private BidiTransformer<String, String> buildTransformer() {
- return new BidiTransformer<String, String>() {
+ private Transformer<String, String> buildTransformer() {
+ return new Transformer<String, String>() {
public String transform(String s) {
return (s == null) ? null : s.toUpperCase();
}
- public String reverseTransform(String s) {
+ };
+ }
+
+ private Transformer<String, String> buildReverseTransformer() {
+ return new Transformer<String, String>() {
+ public String transform(String s) {
return (s == null) ? null : s.toLowerCase();
}
};
@@ -60,6 +66,9 @@ public class TransformationPropertyValueModelTests extends TestCase {
public void testValue() {
assertEquals("foo", this.objectHolder.getValue());
+ assertNull(this.transformationObjectHolder.getValue());
+ ChangeListener listener = this.buildTransformationListener();
+ this.transformationObjectHolder.addChangeListener(listener);
assertEquals("FOO", this.transformationObjectHolder.getValue());
this.objectHolder.setValue("bar");
@@ -84,17 +93,26 @@ public class TransformationPropertyValueModelTests extends TestCase {
assertEquals("bar", this.objectHolder.getValue());
assertEquals("BAR", this.transformationObjectHolder.getValue());
+ // NB: odd behavior(!)
this.transformationObjectHolder.setValue("Foo");
assertEquals("foo", this.objectHolder.getValue());
+ assertEquals("Foo", this.transformationObjectHolder.getValue());
+ ChangeListener listener = this.buildTransformationListener();
+ this.transformationObjectHolder.addChangeListener(listener);
assertEquals("FOO", this.transformationObjectHolder.getValue());
+ this.transformationObjectHolder.removeChangeListener(listener);
this.transformationObjectHolder.setValue(null);
assertNull(this.objectHolder.getValue());
assertNull(this.transformationObjectHolder.getValue());
+ // NB: odd behavior(!)
this.transformationObjectHolder.setValue("baz");
assertEquals("baz", this.objectHolder.getValue());
+ assertEquals("baz", this.transformationObjectHolder.getValue());
+ this.transformationObjectHolder.addChangeListener(listener);
assertEquals("BAZ", this.transformationObjectHolder.getValue());
+ this.transformationObjectHolder.removeChangeListener(listener);
}
public void testLazyListening() {
@@ -185,5 +203,4 @@ public class TransformationPropertyValueModelTests extends TestCase {
assertEquals(oldValue, e.getOldValue());
assertEquals(newValue, e.getNewValue());
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TreeAspectAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TreeAspectAdapterTests.java
deleted file mode 100644
index 22ffb59825..0000000000
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TreeAspectAdapterTests.java
+++ /dev/null
@@ -1,362 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal.model.value;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.eclipse.jpt.common.utility.internal.CollectionTools;
-import org.eclipse.jpt.common.utility.internal.HashBag;
-import org.eclipse.jpt.common.utility.internal.iterators.ChainIterator;
-import org.eclipse.jpt.common.utility.internal.iterators.ReadOnlyIterator;
-import org.eclipse.jpt.common.utility.internal.iterators.TransformationIterator;
-import org.eclipse.jpt.common.utility.internal.iterators.TreeIterator;
-import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
-import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.TreeAspectAdapter;
-import org.eclipse.jpt.common.utility.model.event.TreeAddEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeChangeEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeClearEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeRemoveEvent;
-import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
-import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
-import org.eclipse.jpt.common.utility.model.listener.TreeChangeListener;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.TreeValueModel;
-import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
-import org.eclipse.jpt.common.utility.tests.internal.TestTools;
-
-@SuppressWarnings("nls")
-public class TreeAspectAdapterTests extends TestCase {
- private TestSubject subject1;
- private WritablePropertyValueModel<TestSubject> subjectHolder1;
- private TreeAspectAdapter<TestSubject, List<TestNode>> aa1;
- private TreeEvent event1;
- private TreeChangeListener listener1;
-
- private TestSubject subject2;
-
-
- public TreeAspectAdapterTests(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- this.subject1 = new TestSubject();
- TestNode root, node;
-
- root = this.subject1.getRootNameNode();
- node = this.subject1.addName(root, "name 1.1");
- this.subject1.addName(node, "name 1.1.1");
- this.subject1.addName(node, "name 1.1.2");
- node = this.subject1.addName(root, "name 1.2");
- this.subject1.addName(node, "name 1.2.1");
- node = this.subject1.addName(root, "name 1.3");
-
- root = this.subject1.getRootDescriptionNode();
- node = this.subject1.addDescription(root, "description 1.1");
- this.subject1.addDescription(node, "description 1.1.1");
- this.subject1.addDescription(node, "description 1.1.2");
- node = this.subject1.addDescription(root, "description 1.2");
- this.subject1.addDescription(node, "description 1.2.1");
- node = this.subject1.addDescription(root, "description 1.3");
-
- this.subjectHolder1 = new SimplePropertyValueModel<TestSubject>(this.subject1);
- this.aa1 = this.buildAspectAdapter(this.subjectHolder1);
- this.listener1 = this.buildValueChangeListener1();
- this.aa1.addTreeChangeListener(TreeValueModel.NODES, this.listener1);
- this.event1 = null;
-
- this.subject2 = new TestSubject();
-
- root = this.subject2.getRootNameNode();
- node = this.subject2.addName(root, "name 2.1");
- this.subject2.addName(node, "name 2.1.1");
- this.subject2.addName(node, "name 2.1.2");
- node = this.subject2.addName(root, "name 2.2");
- this.subject2.addName(node, "name 2.2.1");
- node = this.subject2.addName(root, "name 2.3");
-
- root = this.subject2.getRootDescriptionNode();
- node = this.subject2.addDescription(root, "description 2.1");
- this.subject2.addDescription(node, "description 2.1.1");
- this.subject2.addDescription(node, "description 2.1.2");
- node = this.subject2.addDescription(root, "description 2.2");
- this.subject2.addDescription(node, "description 2.2.1");
- node = this.subject2.addDescription(root, "description 2.3");
- }
-
- private TreeAspectAdapter<TestSubject, List<TestNode>> buildAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) {
- return new TreeAspectAdapter<TestSubject, List<TestNode>>(subjectHolder, TestSubject.NAMES_TREE) {
- // this is not a typical aspect adapter - the value is determined by the aspect name
- @Override
- protected Iterator<List<TestNode>> nodes_() {
- if (this.treeNames[0] == TestSubject.NAMES_TREE) {
- return this.subject.namePaths();
- }
- if (this.treeNames[0] == TestSubject.DESCRIPTIONS_TREE) {
- return this.subject.descriptionPaths();
- }
- throw new IllegalStateException("invalid aspect name: " + this.treeNames[0]);
- }
- };
- }
-
- private ChangeListener buildValueChangeListener1() {
- return new ChangeAdapter() {
- @Override
- public void nodeAdded(TreeAddEvent e) {
- TreeAspectAdapterTests.this.value1Changed(e);
- }
- @Override
- public void nodeRemoved(TreeRemoveEvent e) {
- TreeAspectAdapterTests.this.value1Changed(e);
- }
- @Override
- public void treeCleared(TreeClearEvent e) {
- TreeAspectAdapterTests.this.value1Changed(e);
- }
- @Override
- public void treeChanged(TreeChangeEvent e) {
- TreeAspectAdapterTests.this.value1Changed(e);
- }
- };
- }
-
- void value1Changed(TreeEvent e) {
- this.event1 = e;
- }
-
- @Override
- protected void tearDown() throws Exception {
- TestTools.clear(this);
- super.tearDown();
- }
-
- public void testSubjectHolder() {
- assertNull(this.event1);
-
- this.subjectHolder1.setValue(this.subject2);
- assertNotNull(this.event1);
- assertEquals(this.aa1, this.event1.getSource());
- assertEquals(TreeValueModel.NODES, this.event1.getTreeName());
-
- this.event1 = null;
- this.subjectHolder1.setValue(null);
- assertNotNull(this.event1);
- assertEquals(this.aa1, this.event1.getSource());
- assertEquals(TreeValueModel.NODES, this.event1.getTreeName());
-
- this.event1 = null;
- this.subjectHolder1.setValue(this.subject1);
- assertNotNull(this.event1);
- assertEquals(this.aa1, this.event1.getSource());
- assertEquals(TreeValueModel.NODES, this.event1.getTreeName());
- }
-
- public void testTreeStructureChange() {
- assertNull(this.event1);
-
- this.subject1.addTwoNames(this.subject1.getRootNameNode(), "jam", "jaz");
- assertNotNull(this.event1);
- assertEquals(this.aa1, this.event1.getSource());
- assertEquals(TreeValueModel.NODES, this.event1.getTreeName());
- assertTrue(this.subject1.containsNameNode("jam"));
- assertTrue(this.subject1.containsNameNode("jaz"));
- }
-
- public void testNodes() {
- assertEquals(this.convertToNames(this.subject1.namePaths()), this.convertToNames(this.aa1.nodes()));
- }
-
- private Collection<String> convertToNames(Iterator<List<TestNode>> namePaths) {
- Collection<String> result = new HashBag<String>();
- while (namePaths.hasNext()) {
- List<TestNode> path = namePaths.next();
- StringBuffer sb = new StringBuffer();
- sb.append('[');
- for (int i = 0; i < path.size(); i++) {
- sb.append(path.get(i).getText());
- if (i < path.size() - 1) {
- sb.append(':');
- }
- }
- sb.append(']');
- result.add(sb.toString());
- }
- return result;
- }
-
- public void testHasListeners() {
- assertTrue(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES));
- assertTrue(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE));
- this.aa1.removeTreeChangeListener(TreeValueModel.NODES, this.listener1);
- assertFalse(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE));
- assertFalse(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES));
-
- ChangeListener listener2 = this.buildValueChangeListener1();
- this.aa1.addChangeListener(listener2);
- assertTrue(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES));
- assertTrue(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE));
- this.aa1.removeChangeListener(listener2);
- assertFalse(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE));
- assertFalse(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES));
- }
-
- // ********** inner classes **********
-
- class TestSubject extends AbstractModel {
- private TestNode rootNameNode;
- public static final String NAMES_TREE = "names";
- private TestNode rootDescriptionNode;
- public static final String DESCRIPTIONS_TREE = "descriptions";
-
- public TestSubject() {
- this.rootNameNode = new TestNode("root name");
- this.rootDescriptionNode = new TestNode("root description");
- }
- public TestNode getRootNameNode() {
- return this.rootNameNode;
- }
- public Iterator<TestNode> nameNodes() {
- return new TreeIterator<TestNode>(this.rootNameNode) {
- @Override
- public Iterator<TestNode> children(TestNode next) {
- return next.children();
- }
- };
- }
- public Iterator<List<TestNode>> namePaths() {
- return new TransformationIterator<TestNode, List<TestNode>>(this.nameNodes()) {
- @Override
- protected List<TestNode> transform(TestNode next) {
- return next.getPath();
- }
- };
- }
- public TestNode addName(TestNode parent, String name) {
- TestNode child = new TestNode(name);
- parent.addChild(child);
- this.fireNodeAdded(NAMES_TREE, child.getPath());
- return child;
- }
- public void addTwoNames(TestNode parent, String name1, String name2) {
- parent.addChild(new TestNode(name1));
- parent.addChild(new TestNode(name2));
- this.fireTreeChanged(NAMES_TREE, parent.getPath());
- }
- public void removeNameNode(TestNode nameNode) {
- nameNode.getParent().removeChild(nameNode);
- this.fireNodeRemoved(NAMES_TREE, nameNode.getPath());
- }
- public boolean containsNameNode(String name) {
- return this.nameNode(name) != null;
- }
- public TestNode nameNode(String name) {
- for (Iterator<TestNode> stream = this.nameNodes(); stream.hasNext(); ) {
- TestNode node = stream.next();
- if (node.getText().equals(name)) {
- return node;
- }
- }
- return null;
- }
- public TestNode getRootDescriptionNode() {
- return this.rootDescriptionNode;
- }
- public Iterator<TestNode> descriptionNodes() {
- return new TreeIterator<TestNode>(this.rootDescriptionNode) {
- @Override
- public Iterator<TestNode> children(TestNode next) {
- return next.children();
- }
- };
- }
- public Iterator<List<TestNode>> descriptionPaths() {
- return new TransformationIterator<TestNode, List<TestNode>>(this.descriptionNodes()) {
- @Override
- protected List<TestNode> transform(TestNode next) {
- return next.getPath();
- }
- };
- }
- public TestNode addDescription(TestNode parent, String description) {
- TestNode child = new TestNode(description);
- parent.addChild(child);
- this.fireNodeAdded(DESCRIPTIONS_TREE, child.getPath());
- return child;
- }
- public void removeDescriptionNode(TestNode descriptionNode) {
- descriptionNode.getParent().removeChild(descriptionNode);
- this.fireNodeRemoved(DESCRIPTIONS_TREE, descriptionNode.getPath());
- }
- public boolean containsDescriptionNode(String name) {
- for (Iterator<TestNode> stream = this.descriptionNodes(); stream.hasNext(); ) {
- TestNode node = stream.next();
- if (node.getText().equals(name)) {
- return true;
- }
- }
- return false;
- }
- }
-
- class TestNode {
- private final String text;
- private TestNode parent;
- private final Collection<TestNode> children;
-
- public TestNode(String text) {
- this.text = text;
- this.children = new HashBag<TestNode>();
- }
- public String getText() {
- return this.text;
- }
- public TestNode getParent() {
- return this.parent;
- }
- private void setParent(TestNode parent) {
- this.parent = parent;
- }
- public Iterator<TestNode> children() {
- return new ReadOnlyIterator<TestNode>(this.children);
- }
- public void addChild(TestNode child) {
- this.children.add(child);
- child.setParent(this);
- }
- public void removeChild(TestNode child) {
- this.children.remove(child);
- }
- public List<TestNode> getPath() {
- return CollectionTools.reverseList(this.buildAntiPath());
- }
- private Iterator<TestNode> buildAntiPath() {
- return new ChainIterator<TestNode>(this) {
- @Override
- protected TestNode nextLink(TestNode currentLink) {
- return currentLink.getParent();
- }
- };
- }
- @Override
- public String toString() {
- return "TestNode(" + this.text + ")";
- }
- }
-
-}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/JptUtilitySynchronizersTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/JptUtilitySynchronizersTests.java
index 96acf3075b..da7ad6f1f1 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/JptUtilitySynchronizersTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/JptUtilitySynchronizersTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -20,7 +20,6 @@ public class JptUtilitySynchronizersTests {
public static Test suite() {
TestSuite suite = new TestSuite(JptUtilitySynchronizersTests.class.getPackage().getName());
- suite.addTestSuite(AsynchronousSynchronizerTests.class);
suite.addTestSuite(SynchronizerTests.class);
suite.addTestSuite(SynchronousSynchronizerTests.class);
@@ -31,5 +30,4 @@ public class JptUtilitySynchronizersTests {
super();
throw new UnsupportedOperationException();
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/SynchronousSynchronizerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/SynchronousSynchronizerTests.java
index e7601bc657..4bec15e68c 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/SynchronousSynchronizerTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/SynchronousSynchronizerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,7 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal.synchronizers;
-import org.eclipse.jpt.common.utility.Command;
+import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.common.utility.internal.CompositeException;
import org.eclipse.jpt.common.utility.internal.SynchronizedBoolean;
import org.eclipse.jpt.common.utility.internal.synchronizers.SynchronousSynchronizer;
@@ -752,5 +752,4 @@ public class SynchronousSynchronizerTests
public static String timestamp() {
return String.valueOf((System.currentTimeMillis() % 10000) / 1000f);
}
-
}

Back to the top