summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorCheng Chen2012-05-21 04:29:58 (EDT)
committer Cheng Chen2012-05-21 04:29:58 (EDT)
commit0134095a1180bdfa9a0a8f8b04c08940ffbedf3e (patch)
tree72d19cac2b3e64c908ff307a2a171aac87987ab9
parent9d065bb87fd4f7d7069293769e82016aefe01836 (diff)
downloadorg.eclipse.recommenders-0134095a1180bdfa9a0a8f8b04c08940ffbedf3e.zip
org.eclipse.recommenders-0134095a1180bdfa9a0a8f8b04c08940ffbedf3e.tar.gz
org.eclipse.recommenders-0134095a1180bdfa9a0a8f8b04c08940ffbedf3e.tar.bz2
[snipmatch] add unit test case for FormulaSnippetNode classrefs/changes/44/6044/1
Change-Id: I8f911baff3350662084370b7f3c2a185153d26b5 Signed-off-by: Cheng Chen <chengchendoc@gmail.com>
-rw-r--r--tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/FormulaSnippetNodeTest.java129
1 files changed, 129 insertions, 0 deletions
diff --git a/tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/FormulaSnippetNodeTest.java b/tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/FormulaSnippetNodeTest.java
new file mode 100644
index 0000000..3dc3865
--- /dev/null
+++ b/tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/FormulaSnippetNodeTest.java
@@ -0,0 +1,129 @@
+/**
+ * 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:
+ * Cheng Chen - initial API and implementation.
+ */
+package org.eclipse.recommenders.snipmatch.core;
+
+import org.eclipse.recommenders.utils.gson.GsonUtil;
+import org.junit.*;
+import static org.junit.Assert.*;
+
+/**
+ * The class <code>FormulaSnippetNodeTest</code> contains tests for the class <code>{@link FormulaSnippetNode}</code>.
+ *
+ * @author Cheng Chen
+ */
+public class FormulaSnippetNodeTest {
+ private StringBuilder json;
+ /**
+ * Run the FormulaSnippetNode(String,String[],Effect) constructor test.
+ *
+ * @throws Exception
+ *
+ */
+ @Test
+ public void testFormulaSnippetNode_1()
+ throws Exception {
+ String name = "name";
+ String[] args = new String[] {"args0", "args1"};
+ Effect effect = GsonUtil.deserialize(json, Effect.class);
+
+ FormulaSnippetNode result = new FormulaSnippetNode(name, args, effect);
+
+ assertNotNull(result);
+ assertEquals(null, result.getNewVariableName());
+ assertEquals(2, result.numArguments());
+ assertEquals("name", result.getName());
+ assertEquals(result.getArgument(0), "args0");
+ assertEquals(result.getArgument(1), "args1");
+
+ result.setNewVariableName("newVarName");
+ assertEquals(result.getNewVariableName(), "newVarName");
+ }
+
+ /**
+ * Run the FormulaSnippetNode(String,String[],Effect) constructor test.
+ *
+ * @throws Exception
+ *
+ */
+ @Test
+ public void testFormulaSnippetNode_2()
+ throws Exception {
+ String name = "print value";
+ String[] args = new String[] {"value1", "value2", "value3"};
+ Effect effect = new Effect();
+
+ FormulaSnippetNode result = new FormulaSnippetNode(name, args, effect);
+
+ assertNotNull(result);
+ assertEquals(null, result.getNewVariableName());
+ assertEquals(3, result.numArguments());
+ assertEquals("print value", result.getName());
+
+ assertEquals(result.getArgument(0), "value1");
+ assertEquals(result.getArgument(1), "value2");
+ assertEquals(result.getArgument(2), "value3");
+
+ result.setNewVariableName("variable name");
+ assertEquals(result.getNewVariableName(), "variable name");
+ }
+
+ /**
+ * Perform pre-test initialization.
+ *
+ * @throws Exception
+ * if the initialization fails for some reason
+ *
+ */
+ @Before
+ public void setUp()
+ throws Exception {
+ json = new StringBuilder();
+ json.append(" {");
+ json.append(" \"patterns\": [");
+ json.append(" \"print $obj\"");
+ json.append(" ],");
+ json.append(" \"params\": [");
+ json.append(" {");
+ json.append(" \"name\": \"obj\",");
+ json.append(" \"majorType\": \"expr\",");
+ json.append(" \"minorType\": \"\"");
+ json.append(" }");
+ json.append(" ],");
+ json.append(" \"envName\": \"javasnippet\",");
+ json.append(" \"majorType\": \"stmt\",");
+ json.append(" \"minorType\": \"\",");
+ json.append(" \"code\": \"System.out.print(${obj});\",");
+ json.append(" \"summary\": \"Print to standard output.\",");
+ json.append(" \"id\": \"\"");
+ json.append(" }");
+ }
+
+ /**
+ * Perform post-test clean-up.
+ *
+ * @throws Exception
+ * if the clean-up fails for some reason
+ *
+ */
+ @After
+ public void tearDown()
+ throws Exception {
+ }
+
+ /**
+ * Launch the test.
+ *
+ * @param args the command line arguments
+ *
+ */
+ public static void main(String[] args) {
+ new org.junit.runner.JUnitCore().run(FormulaSnippetNodeTest.class);
+ }
+} \ No newline at end of file