summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorCheng Chen2012-05-13 22:21:35 (EDT)
committer Cheng Chen2012-05-13 22:21:35 (EDT)
commitc99e466ff198ce81ca01c2c8f46908c05ab0b2ab (patch)
tree337834fd3a29d514f6908d06eb1ad24df4cbb7b6
parentc10cf83aceb1adf00c601e5d8d630dfdc0e4efba (diff)
downloadorg.eclipse.recommenders-c99e466ff198ce81ca01c2c8f46908c05ab0b2ab.zip
org.eclipse.recommenders-c99e466ff198ce81ca01c2c8f46908c05ab0b2ab.tar.gz
org.eclipse.recommenders-c99e466ff198ce81ca01c2c8f46908c05ab0b2ab.tar.bz2
[snipmatch] add TextSnippetNode unit test coderefs/changes/67/5967/1
Change-Id: Ic26f51cd1afc90219b42c3bfa00e0231b6207373 Signed-off-by: Cheng Chen <chengchendoc@gmail.com>
-rw-r--r--tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/TextSnippetNodeTest.java134
1 files changed, 134 insertions, 0 deletions
diff --git a/tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/TextSnippetNodeTest.java b/tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/TextSnippetNodeTest.java
new file mode 100644
index 0000000..8be113a
--- /dev/null
+++ b/tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/TextSnippetNodeTest.java
@@ -0,0 +1,134 @@
+/**
+ * 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>TextSnippetNodeTest</code> contains tests for the class <code>{@link TextSnippetNode}</code>.
+ *
+ * @author Cheng Chen
+ */
+public class TextSnippetNodeTest {
+ private StringBuilder json;
+
+ /**
+ * Run the TextSnippetNode(String,Effect) constructor test.
+ *
+ * @throws Exception
+ *
+ */
+ @Test
+ public void testTextSnippetNode_1() throws Exception {
+ String text = "text summary";
+ Effect effect = new Effect();
+
+ TextSnippetNode result = new TextSnippetNode(text, effect);
+
+ assertNotNull(result);
+ assertEquals("text summary", result.getText());
+ }
+
+ /**
+ * Run the Effect getEffect() method test.
+ *
+ * @throws Exception
+ *
+ */
+ @Test
+ public void testGetEffect_1() throws Exception {
+ TextSnippetNode fixture = new TextSnippetNode("", (Effect) GsonUtil.deserialize(json, Effect.class));
+
+ Effect result = fixture.getEffect();
+
+ assertNotNull(result);
+
+ assertEquals(1, result.numParameters());
+ assertEquals("Print to standard output.", result.getSummary());
+ assertEquals("", result.getMinorType());
+ assertEquals("stmt", result.getFullType());
+ assertEquals(1, result.numPatterns());
+ assertEquals("stmt", result.getMajorType());
+ assertEquals("javasnippet", result.getEnvironmentName());
+ assertEquals("", result.getId());
+ assertEquals("System.out.print(${obj});", result.getCode());
+ }
+
+ /**
+ * Run the String getText() method test.
+ *
+ * @throws Exception
+ *
+ */
+ @Test
+ public void testGetText_1() throws Exception {
+ TextSnippetNode fixture = new TextSnippetNode("new text", new Effect());
+
+ String result = fixture.getText();
+
+ assertEquals("new text", result);
+ }
+
+ /**
+ * 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 {
+ // Add additional tear down code here
+ }
+
+ /**
+ * Launch the test.
+ *
+ * @param args
+ * the command line arguments
+ *
+ */
+ public static void main(String[] args) {
+ new org.junit.runner.JUnitCore().run(TextSnippetNodeTest.class);
+ }
+} \ No newline at end of file