Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Vosburgh2016-01-28 18:59:07 +0000
committerBrian Vosburgh2017-05-18 22:35:51 +0000
commit2482daff01310995722fd5abe9452a347e673fb6 (patch)
tree27f523e051bb6c62143fccb6df8843e2d8d4bf4a /common/tests
parent992195860fb65621aabfd088ca9ef1f2485033d0 (diff)
downloadwebtools.dali-2482daff01310995722fd5abe9452a347e673fb6.tar.gz
webtools.dali-2482daff01310995722fd5abe9452a347e673fb6.tar.xz
webtools.dali-2482daff01310995722fd5abe9452a347e673fb6.zip
add ReadWriteLockMapWrapper
Diffstat (limited to 'common/tests')
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/JptCommonUtilityCollectionTests.java3
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/ReadWriteLockMapWrapperTests.java259
2 files changed, 261 insertions, 1 deletions
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/JptCommonUtilityCollectionTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/JptCommonUtilityCollectionTests.java
index 77363e4645..f968a3dec2 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/JptCommonUtilityCollectionTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/JptCommonUtilityCollectionTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2016 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.
@@ -29,6 +29,7 @@ public class JptCommonUtilityCollectionTests {
suite.addTestSuite(MapToolsTests.class);
suite.addTestSuite(NullElementListTests.class);
suite.addTestSuite(NullListTests.class);
+ suite.addTestSuite(ReadWriteLockMapWrapperTests.class);
suite.addTestSuite(RepeatingElementListTests.class);
suite.addTestSuite(SynchronizedBagTests.class);
suite.addTestSuite(TightMapTests.class);
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/ReadWriteLockMapWrapperTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/ReadWriteLockMapWrapperTests.java
new file mode 100644
index 0000000000..0c8bdbc750
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/ReadWriteLockMapWrapperTests.java
@@ -0,0 +1,259 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.collection;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.jpt.common.utility.internal.collection.ReadWriteLockMapWrapper;
+import org.eclipse.jpt.common.utility.internal.collection.MapTools;
+import junit.framework.TestCase;
+
+@SuppressWarnings("nls")
+public class ReadWriteLockMapWrapperTests
+ extends TestCase
+{
+ private Map<String, String> map;
+ private ReadWriteLockMapWrapper<String, String> wrapper;
+
+ public ReadWriteLockMapWrapperTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.map = this.buildMap();
+ this.wrapper = this.buildWrapper(this.map);
+ }
+
+ protected Map<String, String> buildMap() {
+ return new HashMap<>();
+ }
+
+ protected ReadWriteLockMapWrapper<String, String> buildWrapper(Map<String, String> m) {
+ return MapTools.readWriteLockWrapper(m);
+ }
+
+ public void testSize() throws Exception {
+ assertEquals(this.map.size(), this.wrapper.size());
+ this.map.put("foo", "foo value 1");
+ assertEquals(this.map.size(), this.wrapper.size());
+ this.map.put("foo", "foo value 2");
+ assertEquals(this.map.size(), this.wrapper.size());
+ this.map.put("bar", "bar value");
+ assertEquals(this.map.size(), this.wrapper.size());
+ this.map.put("baz", "baz value");
+ assertEquals(this.map.size(), this.wrapper.size());
+ }
+
+ public void testIsEmpty() throws Exception {
+ assertEquals(this.map.isEmpty(), this.wrapper.isEmpty());
+ this.map.put("foo", "foo value 1");
+ assertEquals(this.map.isEmpty(), this.wrapper.isEmpty());
+ this.map.put("foo", "foo value 2");
+ assertEquals(this.map.isEmpty(), this.wrapper.isEmpty());
+ this.map.put("bar", "bar value");
+ assertEquals(this.map.isEmpty(), this.wrapper.isEmpty());
+ this.map.put("baz", "baz value");
+ assertEquals(this.map.isEmpty(), this.wrapper.isEmpty());
+ }
+
+ public void testContainsValue() throws Exception {
+ assertEquals(this.map.containsValue("foo value 1"), this.wrapper.containsValue("foo value 1"));
+ assertEquals(this.map.containsValue("foo value 2"), this.wrapper.containsValue("foo value 2"));
+
+ this.map.put("foo", "foo value 1");
+ assertEquals(this.map.containsValue("foo value 1"), this.wrapper.containsValue("foo value 1"));
+ assertEquals(this.map.containsValue("foo value 2"), this.wrapper.containsValue("foo value 2"));
+
+ this.map.put("foo", "foo value 2");
+ assertEquals(this.map.containsValue("foo value 1"), this.wrapper.containsValue("foo value 1"));
+ assertEquals(this.map.containsValue("foo value 2"), this.wrapper.containsValue("foo value 2"));
+
+ this.map.put("bar", "bar value");
+ assertEquals(this.map.containsValue("foo value 1"), this.wrapper.containsValue("foo value 1"));
+ assertEquals(this.map.containsValue("foo value 2"), this.wrapper.containsValue("foo value 2"));
+ assertEquals(this.map.containsValue("bar value"), this.wrapper.containsValue("bar value"));
+
+ this.map.put("baz", "baz value");
+ assertEquals(this.map.containsValue("foo value 2"), this.wrapper.containsValue("foo value 2"));
+ assertEquals(this.map.containsValue("foo value 1"), this.wrapper.containsValue("foo value 1"));
+ assertEquals(this.map.containsValue("bar value"), this.wrapper.containsValue("bar value"));
+ assertEquals(this.map.containsValue("baz value"), this.wrapper.containsValue("baz value"));
+ }
+
+ public void testContainsKey() throws Exception {
+ assertEquals(this.map.containsKey("foo"), this.wrapper.containsKey("foo"));
+ assertEquals(this.map.containsKey("bar"), this.wrapper.containsKey("bar"));
+
+ this.map.put("foo", "foo value 1");
+ assertEquals(this.map.containsKey("foo"), this.wrapper.containsKey("foo"));
+ assertEquals(this.map.containsKey("bar"), this.wrapper.containsKey("bar"));
+
+ this.map.put("foo", "foo value 2");
+ assertEquals(this.map.containsKey("foo"), this.wrapper.containsKey("foo"));
+ assertEquals(this.map.containsKey("bar"), this.wrapper.containsKey("bar"));
+
+ this.map.put("bar", "bar value");
+ assertEquals(this.map.containsKey("foo"), this.wrapper.containsKey("foo"));
+ assertEquals(this.map.containsKey("bar"), this.wrapper.containsKey("bar"));
+ assertEquals(this.map.containsKey("baz"), this.wrapper.containsKey("baz"));
+
+ this.map.put("baz", "baz value");
+ assertEquals(this.map.containsKey("foo"), this.wrapper.containsKey("foo"));
+ assertEquals(this.map.containsKey("bar"), this.wrapper.containsKey("bar"));
+ assertEquals(this.map.containsKey("baz"), this.wrapper.containsKey("baz"));
+ }
+
+ public void testGet() throws Exception {
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+
+ this.map.put("foo", "foo value 1");
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+
+ this.map.put("foo", "foo value 2");
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+
+ this.map.put("bar", "bar value");
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+ assertEquals(this.map.get("baz"), this.wrapper.get("baz"));
+
+ this.map.put("baz", "baz value");
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+ assertEquals(this.map.get("baz"), this.wrapper.get("baz"));
+ }
+
+ public void testToString() throws Exception {
+ assertEquals(this.map.toString(), this.wrapper.toString());
+
+ this.map.put("foo", "foo value 1");
+ assertEquals(this.map.toString(), this.wrapper.toString());
+
+ this.map.put("foo", "foo value 2");
+ assertEquals(this.map.toString(), this.wrapper.toString());
+
+ this.map.put("bar", "bar value");
+ assertEquals(this.map.toString(), this.wrapper.toString());
+
+ this.map.put("baz", "baz value");
+ assertEquals(this.map.toString(), this.wrapper.toString());
+ }
+
+ public void testPut() throws Exception {
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+
+ assertEquals(null, this.wrapper.put("foo", "foo value 1"));
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+
+ assertEquals("foo value 1", this.wrapper.put("foo", "foo value 2"));
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+
+ assertEquals(null, this.wrapper.put("bar", "bar value"));
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+ assertEquals(this.map.get("baz"), this.wrapper.get("baz"));
+
+ assertEquals(null, this.wrapper.put("baz", "baz value"));
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+ assertEquals(this.map.get("baz"), this.wrapper.get("baz"));
+ }
+
+ public void testRemove() throws Exception {
+ this.wrapper.put("foo", "foo value 1");
+ this.wrapper.put("foo", "foo value 2");
+ this.wrapper.put("bar", "bar value");
+ this.wrapper.put("baz", "baz value");
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+ assertEquals(this.map.get("baz"), this.wrapper.get("baz"));
+
+ assertEquals("baz value", this.wrapper.remove("baz"));
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+ assertEquals(this.map.get("baz"), this.wrapper.get("baz"));
+
+ assertEquals("bar value", this.wrapper.remove("bar"));
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+ assertEquals(this.map.get("baz"), this.wrapper.get("baz"));
+
+ assertEquals("foo value 2", this.wrapper.remove("foo"));
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+ assertEquals(this.map.get("baz"), this.wrapper.get("baz"));
+
+ assertEquals(null, this.wrapper.remove("foo"));
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+ assertEquals(this.map.get("baz"), this.wrapper.get("baz"));
+ }
+
+ public void testPutAll() throws Exception {
+ Map<String, String> map2 = new HashMap<>();
+ map2.put("foo", "foo value 1");
+ map2.put("foo", "foo value 2");
+ map2.put("bar", "bar value");
+ map2.put("baz", "baz value");
+ this.wrapper.putAll(map2);
+ assertEquals("foo value 2", this.map.get("foo"));
+ assertEquals("bar value", this.map.get("bar"));
+ assertEquals("baz value", this.map.get("baz"));
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+ assertEquals(this.map.get("baz"), this.wrapper.get("baz"));
+ }
+
+ public void testClear() throws Exception {
+ this.wrapper.put("foo", "foo value 1");
+ this.wrapper.put("foo", "foo value 2");
+ this.wrapper.put("bar", "bar value");
+ this.wrapper.put("baz", "baz value");
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+ assertEquals(this.map.get("baz"), this.wrapper.get("baz"));
+
+ this.wrapper.clear();
+ assertTrue(this.wrapper.isEmpty());
+ assertEquals(this.map.get("foo"), this.wrapper.get("foo"));
+ assertEquals(this.map.get("bar"), this.wrapper.get("bar"));
+ assertEquals(this.map.get("baz"), this.wrapper.get("baz"));
+ }
+
+ public void testCtor_NPE_map() throws Exception {
+ boolean exCaught = false;
+ try {
+ ReadWriteLockMapWrapper<String, String> w = MapTools.readWriteLockWrapper(null);
+ fail("bogus: " + w);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCtor_NPE_lock() throws Exception {
+ boolean exCaught = false;
+ try {
+ ReadWriteLockMapWrapper<String, String> w = MapTools.readWriteLockWrapper(this.map, null);
+ fail("bogus: " + w);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+}

Back to the top