aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCheng Chen2012-05-17 03:15:47 (EDT)
committerCheng Chen2012-05-17 03:15:47 (EDT)
commit74c9efc86285074e736db04dc6ac073e584e980f (patch)
tree5820a03bd14daf7e7d233fa191629dd41865c32e
parent02beb390c8e00b1f610b54d465db2b0e41f297c8 (diff)
downloadorg.eclipse.recommenders-74c9efc86285074e736db04dc6ac073e584e980f.zip
org.eclipse.recommenders-74c9efc86285074e736db04dc6ac073e584e980f.tar.gz
org.eclipse.recommenders-74c9efc86285074e736db04dc6ac073e584e980f.tar.bz2
[snipmatch] add EffectMatchNode unit test classrefs/changes/12/6012/1
Change-Id: I2969f0e793fcc0fdb66aa90720a1c1d39e5f429c Signed-off-by: Cheng Chen <chengchendoc@gmail.com>
-rw-r--r--tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/EffectMatchNodeTest.java108
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/EffectMatchNodeTest.java b/tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/EffectMatchNodeTest.java
new file mode 100644
index 0000000..cf44fee
--- /dev/null
+++ b/tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/EffectMatchNodeTest.java
@@ -0,0 +1,108 @@
+/**
+ * Copyright (c) 2011, University of Science and Technology Beijing
+ * 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>EffectMatchNodeTest</code> contains tests for the class <code>{@link EffectMatchNode}</code>.
+ *
+ * @author Cheng Chen
+ */
+public class EffectMatchNodeTest {
+ private StringBuilder json;
+ private String newLine = "\n";
+
+ /**
+ * Run the EffectMatchNode(Effect,String,MatchNode[]) constructor test.
+ *
+ * @throws Exception
+ *
+ */
+ @Test
+ public void testEffectMatchNode_1() throws Exception {
+ Effect effect = GsonUtil.deserialize(json, Effect.class);
+ String pattern = "print $obj";
+ MatchNode[] children = new MatchNode[effect.getParameters().length];
+ for (int i = 0; i < children.length; i++) {
+ EffectParameter param = effect.getParameters()[i];
+ ArgumentMatchNode childNode = new ArgumentMatchNode(param.getName(), param);
+ children[i] = childNode;
+ }
+
+ EffectMatchNode result = new EffectMatchNode(effect, pattern, children);
+
+ assertNotNull(result);
+ assertEquals(true, result.isComplete());
+ assertEquals(1, result.numChildren());
+ assertEquals(false, result.isEmpty());
+ assertEquals("print $obj", result.getPattern());
+ assertEquals(null, result.getMatchType());
+ assertEquals(null, result.getParent());
+
+ MatchNode[] nodes = result.getChildren();
+ assertEquals(nodes.length, 1);
+ }
+
+ /**
+ * 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(EffectMatchNodeTest.class);
+ }
+} \ No newline at end of file