Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java5
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EvalTests.java98
2 files changed, 101 insertions, 2 deletions
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java
index 951a0052f..4b99e3edf 100644
--- a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java
@@ -17,6 +17,7 @@ import org.eclipse.eef.tests.internal.controllers.EEFRadioControllerTests;
import org.eclipse.eef.tests.internal.controllers.EEFSelectControllerTests;
import org.eclipse.eef.tests.internal.controllers.EEFTextControllerTests;
import org.eclipse.eef.tests.internal.core.EEFDomainClassTesterTests;
+import org.eclipse.eef.tests.internal.core.EvalTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -27,8 +28,8 @@ import org.junit.runners.Suite.SuiteClasses;
* @author sbegaudeau
*/
@RunWith(Suite.class)
-@SuiteClasses({ EEFDataTests.class, EEFTextControllerTests.class, EEFLabelControllerTests.class, EEFButtonControllerTests.class,
- EEFCheckboxControllerTests.class, EEFRadioControllerTests.class, EEFSelectControllerTests.class, EEFDomainClassTesterTests.class })
+@SuiteClasses({ EvalTests.class, EEFDataTests.class, EEFTextControllerTests.class, EEFLabelControllerTests.class, EEFButtonControllerTests.class,
+ EEFCheckboxControllerTests.class, EEFRadioControllerTests.class, EEFSelectControllerTests.class, EEFDomainClassTesterTests.class })
public final class AllTests {
/**
* The constructor.
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EvalTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EvalTests.java
new file mode 100644
index 000000000..c8c643b03
--- /dev/null
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EvalTests.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.eef.tests.internal.core;
+
+import java.util.Map;
+
+import org.eclipse.eef.core.api.utils.EvalFactory;
+import org.eclipse.sirius.common.interpreter.api.EvaluationResult;
+import org.eclipse.sirius.common.interpreter.api.IInterpreter;
+import org.eclipse.sirius.common.interpreter.api.IVariableManager;
+import org.eclipse.sirius.common.interpreter.api.VariableManagerFactory;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+
+/**
+ * Tests of the {@link EvalFactory} utility class.
+ *
+ * @author sbegaudeau
+ */
+@SuppressWarnings({ "checkstyle:javadocmethod" })
+public class EvalTests {
+
+ /**
+ * The first AQL based expression used for the test.
+ */
+ private static final String FIRST_EXPRESSION = "aql:self.name"; //$NON-NLS-1$
+
+ /**
+ * The result of the first AQL based expression.
+ */
+ private static final String FIRST_RESULT = "John Doe"; //$NON-NLS-1$
+
+ /**
+ * The second AQL based expression used for the test.
+ */
+ private static final String SECOND_EXPRESSION = "aql:self.abstract"; //$NON-NLS-1$
+
+ /**
+ * The result of the second AQL based expression.
+ */
+ private static final boolean SECOND_RESULT = true;
+
+ @Test
+ public void testGetResult() {
+ IInterpreter interpreter = (Map<String, Object> variables, String expressionBody) -> {
+ if (FIRST_EXPRESSION.equals(expressionBody)) {
+ return EvaluationResult.of(FIRST_RESULT);
+ }
+ return EvaluationResult.of(Boolean.valueOf(SECOND_RESULT));
+ };
+
+ IVariableManager variableManager = new VariableManagerFactory().createVariableManager();
+ Object result = EvalFactory.of(interpreter, variableManager).evaluate(FIRST_EXPRESSION);
+ assertThat(result, is(FIRST_RESULT));
+ }
+
+ @Test
+ public void testGetDefaultValue() {
+ IInterpreter interpreter = (Map<String, Object> variables, String expressionBody) -> {
+ return EvaluationResult.of(null);
+ };
+ IVariableManager variableManager = new VariableManagerFactory().createVariableManager();
+
+ assertThat(EvalFactory.of(interpreter, variableManager).evaluate(FIRST_EXPRESSION), nullValue());
+
+ Object result = EvalFactory.of(interpreter, variableManager).defaultValue(FIRST_RESULT).evaluate(FIRST_EXPRESSION);
+ assertThat(result, is(FIRST_RESULT));
+ }
+
+ @Test
+ public void testGetCastValue() {
+ IInterpreter interpreter = (Map<String, Object> variables, String expressionBody) -> {
+ if (FIRST_EXPRESSION.equals(expressionBody)) {
+ return EvaluationResult.of(FIRST_RESULT);
+ }
+ return EvaluationResult.of(Boolean.valueOf(SECOND_RESULT));
+ };
+
+ IVariableManager variableManager = new VariableManagerFactory().createVariableManager();
+
+ String stringResult = EvalFactory.of(interpreter, variableManager).logIfInvalidType(String.class).evaluate(FIRST_EXPRESSION);
+ assertThat(stringResult, is(FIRST_RESULT));
+
+ Boolean booleanResult = EvalFactory.of(interpreter, variableManager).logIfInvalidType(Boolean.class).evaluate(SECOND_EXPRESSION);
+ assertThat(booleanResult, is(SECOND_RESULT));
+ }
+}

Back to the top