Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Vosburgh2016-06-08 17:14:28 +0000
committerBrian Vosburgh2017-05-18 22:36:55 +0000
commit0ccea216e75653bb75ab14cff9ed8f43a7bf4782 (patch)
treee7bb082018d280f38e0e21308ea2de605bc34b42 /common/tests
parente827a4f8b802b3dfd3c9511ea273d495d545ba18 (diff)
downloadwebtools.dali-0ccea216e75653bb75ab14cff9ed8f43a7bf4782.tar.gz
webtools.dali-0ccea216e75653bb75ab14cff9ed8f43a7bf4782.tar.xz
webtools.dali-0ccea216e75653bb75ab14cff9ed8f43a7bf4782.zip
add CollectionFirstElementTransformer and
CollectionSingleElementTransformer
Diffstat (limited to 'common/tests')
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionFirstElementTransformerTests.java50
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionSingleElementTransformerTests.java50
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/JptCommonUtilityTransformerTests.java4
3 files changed, 103 insertions, 1 deletions
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionFirstElementTransformerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionFirstElementTransformerTests.java
new file mode 100644
index 0000000000..298dd4b2ca
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionFirstElementTransformerTests.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * 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.transformer;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools;
+import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+import junit.framework.TestCase;
+
+@SuppressWarnings("nls")
+public class CollectionFirstElementTransformerTests
+ extends TestCase
+{
+ public CollectionFirstElementTransformerTests(String name) {
+ super(name);
+ }
+
+ public void testEvaluate() {
+ Collection<String> list = new ArrayList<>();
+ Transformer<Collection<String>, String> transformer = TransformerTools.collectionFirstElementTransformer();
+ assertNull(transformer.transform(list));
+ list.add("foo");
+ assertEquals("foo", transformer.transform(list));
+ list.add("bar");
+ assertEquals("foo", transformer.transform(list));
+ list.remove("foo");
+ assertEquals("bar", transformer.transform(list));
+ list.remove("bar");
+ assertNull(transformer.transform(list));
+ }
+
+ public void testToString() {
+ Transformer<Collection<String>, String> transformer = TransformerTools.collectionFirstElementTransformer();
+ assertEquals("CollectionFirstElementTransformer", transformer.toString());
+ }
+
+ public void testSerialization() throws Exception {
+ Transformer<Collection<String>, String> transformer = TransformerTools.collectionFirstElementTransformer();
+ assertSame(transformer, TestTools.serialize(transformer));
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionSingleElementTransformerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionSingleElementTransformerTests.java
new file mode 100644
index 0000000000..845cb635d3
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionSingleElementTransformerTests.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * 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.transformer;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools;
+import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+import junit.framework.TestCase;
+
+@SuppressWarnings("nls")
+public class CollectionSingleElementTransformerTests
+ extends TestCase
+{
+ public CollectionSingleElementTransformerTests(String name) {
+ super(name);
+ }
+
+ public void testEvaluate() {
+ Collection<String> list = new ArrayList<>();
+ Transformer<Collection<String>, String> transformer = TransformerTools.collectionSingleElementTransformer();
+ assertNull(transformer.transform(list));
+ list.add("foo");
+ assertEquals("foo", transformer.transform(list));
+ list.add("bar");
+ assertNull(transformer.transform(list));
+ list.remove("foo");
+ assertEquals("bar", transformer.transform(list));
+ list.remove("bar");
+ assertNull(transformer.transform(list));
+ }
+
+ public void testToString() {
+ Transformer<Collection<String>, String> transformer = TransformerTools.collectionSingleElementTransformer();
+ assertEquals("CollectionSingleElementTransformer", transformer.toString());
+ }
+
+ public void testSerialization() throws Exception {
+ Transformer<Collection<String>, String> transformer = TransformerTools.collectionSingleElementTransformer();
+ assertSame(transformer, TestTools.serialize(transformer));
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/JptCommonUtilityTransformerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/JptCommonUtilityTransformerTests.java
index f8a0f4ffaa..a087f1d57e 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/JptCommonUtilityTransformerTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/JptCommonUtilityTransformerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Oracle. All rights reserved.
+ * Copyright (c) 2012, 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.
@@ -20,6 +20,8 @@ public class JptCommonUtilityTransformerTests {
public static Test suite() {
TestSuite suite = new TestSuite(JptCommonUtilityTransformerTests.class.getPackage().getName());
+ suite.addTestSuite(CollectionFirstElementTransformerTests.class);
+ suite.addTestSuite(CollectionSingleElementTransformerTests.class);
suite.addTestSuite(XMLStringDecoderTests.class);
suite.addTestSuite(XMLStringEncoderTests.class);

Back to the top