Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Vosburgh2016-06-17 15:54:49 +0000
committerBrian Vosburgh2017-05-18 22:37:09 +0000
commit3a8dfb1cc77dd0abeea0c9f6f39f2694fc9927bc (patch)
tree265a37948b38abf4bd7aa6b9c55011ec89de2976 /common/tests
parentca0a01ec044bf1b071ece5c16913d864e4513298 (diff)
downloadwebtools.dali-3a8dfb1cc77dd0abeea0c9f6f39f2694fc9927bc.tar.gz
webtools.dali-3a8dfb1cc77dd0abeea0c9f6f39f2694fc9927bc.tar.xz
webtools.dali-3a8dfb1cc77dd0abeea0c9f6f39f2694fc9927bc.zip
add [Nullable]BooleanClosure
Diffstat (limited to 'common/tests')
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/closure/BooleanClosureTests.java81
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/closure/JptCommonUtilityClosureTests.java33
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/closure/NullableBooleanClosureTests.java80
3 files changed, 194 insertions, 0 deletions
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/closure/BooleanClosureTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/closure/BooleanClosureTests.java
new file mode 100644
index 0000000000..5ad60d9955
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/closure/BooleanClosureTests.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * 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.closure;
+
+import org.eclipse.jpt.common.utility.closure.Closure;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.internal.closure.BooleanClosure;
+import org.eclipse.jpt.common.utility.internal.closure.ClosureTools;
+import junit.framework.TestCase;
+
+@SuppressWarnings("nls")
+public class BooleanClosureTests
+ extends TestCase
+{
+ public BooleanClosureTests(String name) {
+ super(name);
+ }
+
+ public void testExecute() {
+ Adapter adapter = new Adapter();
+ assertNull(adapter.value);
+ Closure<Boolean> closure = ClosureTools.booleanClosure(adapter);
+ closure.execute(Boolean.TRUE);
+ assertEquals("foo", adapter.value);
+ closure.execute(Boolean.FALSE);
+ assertEquals("bar", adapter.value);
+ }
+
+ public void testExecute_NPE() {
+ Adapter adapter = new Adapter();
+ assertNull(adapter.value);
+ Closure<Boolean> closure = ClosureTools.booleanClosure(adapter);
+ closure.execute(Boolean.TRUE);
+ assertEquals("foo", adapter.value);
+ boolean exCaught = false;
+ try {
+ closure.execute(null);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCtor_NPE() {
+ boolean exCaught = false;
+ try {
+ Closure<Boolean> closure = ClosureTools.booleanClosure(null);
+ fail("bogus closure: " + closure);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testToString() {
+ Adapter adapter = new Adapter();
+ assertNull(adapter.value);
+ Closure<Boolean> closure = ClosureTools.booleanClosure(adapter);
+ assertTrue(closure.toString().indexOf("Adapter") != -1);
+ }
+
+ public static class Adapter
+ implements BooleanClosure.Adapter
+ {
+ String value = null;
+ public void execute(boolean argument) {
+ this.value = (argument ? "foo" : "bar");
+ }
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this);
+ }
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/closure/JptCommonUtilityClosureTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/closure/JptCommonUtilityClosureTests.java
new file mode 100644
index 0000000000..40f8b348ec
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/closure/JptCommonUtilityClosureTests.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.closure;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * decentralize test creation code
+ */
+public class JptCommonUtilityClosureTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(JptCommonUtilityClosureTests.class.getPackage().getName());
+
+ suite.addTestSuite(BooleanClosureTests.class);
+ suite.addTestSuite(NullableBooleanClosureTests.class);
+
+ return suite;
+ }
+
+ private JptCommonUtilityClosureTests() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/closure/NullableBooleanClosureTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/closure/NullableBooleanClosureTests.java
new file mode 100644
index 0000000000..74b775bfca
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/closure/NullableBooleanClosureTests.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * 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.closure;
+
+import org.eclipse.jpt.common.utility.closure.Closure;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.internal.closure.BooleanClosure;
+import org.eclipse.jpt.common.utility.internal.closure.ClosureTools;
+import junit.framework.TestCase;
+
+@SuppressWarnings("nls")
+public class NullableBooleanClosureTests
+ extends TestCase
+{
+ public NullableBooleanClosureTests(String name) {
+ super(name);
+ }
+
+ public void testExecute() {
+ Adapter adapter = new Adapter();
+ assertNull(adapter.value);
+ Closure<Boolean> closure = ClosureTools.nullableBooleanClosure(adapter);
+ closure.execute(Boolean.TRUE);
+ assertEquals("foo", adapter.value);
+ closure.execute(Boolean.FALSE);
+ assertEquals("bar", adapter.value);
+ }
+
+ public void testExecute_NPE() {
+ Adapter adapter = new Adapter();
+ assertNull(adapter.value);
+ Closure<Boolean> closure = ClosureTools.nullableBooleanClosure(adapter);
+ closure.execute(Boolean.TRUE);
+ assertEquals("foo", adapter.value);
+ closure.execute(null);
+ assertEquals("bar", adapter.value);
+ closure.execute(Boolean.TRUE);
+ assertEquals("foo", adapter.value);
+ closure.execute(Boolean.FALSE);
+ assertEquals("bar", adapter.value);
+ }
+
+ public void testCtor_NPE() {
+ boolean exCaught = false;
+ try {
+ Closure<Boolean> closure = ClosureTools.nullableBooleanClosure(null);
+ fail("bogus closure: " + closure);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testToString() {
+ Adapter adapter = new Adapter();
+ assertNull(adapter.value);
+ Closure<Boolean> closure = ClosureTools.nullableBooleanClosure(adapter);
+ assertTrue(closure.toString().indexOf("Adapter") != -1);
+ }
+
+ public static class Adapter
+ implements BooleanClosure.Adapter
+ {
+ String value = null;
+ public void execute(boolean argument) {
+ this.value = (argument ? "foo" : "bar");
+ }
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this);
+ }
+ }
+}

Back to the top