aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCheng Chen2012-05-09 00:00:59 (EDT)
committerCheng Chen2012-05-09 00:00:59 (EDT)
commit216f02f83b77deb1b1925702988f9920e04e5dfc (patch)
treea163cd1b14b56170961eea6d1a8b61220bfd0545
parent68a6654fd30ce7c156da8039cbdaebc61cc85829 (diff)
downloadorg.eclipse.recommenders-216f02f83b77deb1b1925702988f9920e04e5dfc.zip
org.eclipse.recommenders-216f02f83b77deb1b1925702988f9920e04e5dfc.tar.gz
org.eclipse.recommenders-216f02f83b77deb1b1925702988f9920e04e5dfc.tar.bz2
[snipmatch] add and format SnippetParser unit test classrefs/changes/92/5892/3
Signed-off-by: Cheng Chen <chengchendoc@gmail.com> Change-Id: I028bc42e5a03e3805c020a1f0a07f606e929968d
-rw-r--r--tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/SnippetParserTest.java178
1 files changed, 178 insertions, 0 deletions
diff --git a/tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/SnippetParserTest.java b/tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/SnippetParserTest.java
new file mode 100644
index 0000000..2d486d7
--- /dev/null
+++ b/tests/org.eclipse.recommenders.tests.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/core/SnippetParserTest.java
@@ -0,0 +1,178 @@
+/**
+ * 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>SnippetParserTest</code> contains tests for the class <code>{@link SnippetParser}</code>.
+ *
+ * @author Cheng Chen
+ */
+public class SnippetParserTest {
+ private StringBuilder json;
+
+ /**
+ * Run the ISnippetNode[] parseSnippetNodes(Effect) method test.
+ *
+ * @throws Exception
+ *
+ */
+ @Test
+ public void testParseSnippetNodes_1() throws Exception {
+ Effect effect = GsonUtil.deserialize(json, Effect.class);
+
+ ISnippetNode[] result = SnippetParser.parseSnippetNodes(effect);
+
+ assertNotNull(result);
+ assertEquals(3, result.length);
+ }
+
+ /**
+ * Run the ISnippetNode[] parseSnippetNodes(Effect) method test.
+ *
+ * @throws Exception
+ *
+ */
+ @Test
+ public void testParseSnippetNodes_2() throws Exception {
+ Effect effect = GsonUtil.deserialize(json, Effect.class);
+ effect.setCode("new code here");
+
+ ISnippetNode[] result = SnippetParser.parseSnippetNodes(effect);
+
+ assertNotNull(result);
+ assertEquals(1, result.length);
+ }
+
+ /**
+ * Run the ISnippetNode[] parseSnippetNodes(Effect) method test.
+ *
+ * @throws Exception
+ *
+ */
+ @Test
+ public void testParseSnippetNodes_3() throws Exception {
+ Effect effect = GsonUtil.deserialize(json, Effect.class);
+ effect.setCode("code with two parameters ${value1} and ${value2}");
+
+ ISnippetNode[] result = SnippetParser.parseSnippetNodes(effect);
+
+ assertNotNull(result);
+ assertEquals(4, result.length);
+ }
+
+ /**
+ * Run the ISnippetNode[] parseSnippetNodes(Effect) method test.
+ *
+ * @throws Exception
+ *
+ */
+ @Test
+ public void testParseSnippetNodes_4() throws Exception {
+ Effect effect = GsonUtil.deserialize(json, Effect.class);
+ effect.setCode("${just a parameter}");
+
+ ISnippetNode[] result = SnippetParser.parseSnippetNodes(effect);
+
+ assertNotNull(result);
+ assertEquals(2, result.length);
+ }
+
+ /**
+ * Run the ISnippetNode[] parseSnippetNodes(Effect) method test.
+ *
+ * @throws Exception
+ *
+ */
+ @Test
+ public void testParseSnippetNodes_5() throws Exception {
+ Effect effect = GsonUtil.deserialize(json, Effect.class);
+ effect.setCode("for(int i=0; i<${value};i++) System.out.println(${value});");
+
+ ISnippetNode[] result = SnippetParser.parseSnippetNodes(effect);
+
+ assertNotNull(result);
+ assertEquals(5, result.length);
+ }
+
+ /**
+ * Run the ISnippetNode[] parseSnippetNodes(Effect) method test.
+ *
+ * @throws Exception
+ *
+ */
+ @Test
+ public void testParseSnippetNodes_6() throws Exception {
+ Effect effect = GsonUtil.deserialize(json, Effect.class);
+ effect.setCode("System.out.println(\"helloworld\")");
+
+ ISnippetNode[] result = SnippetParser.parseSnippetNodes(effect);
+
+ assertNotNull(result);
+ assertEquals(1, result.length);
+ }
+
+ /**
+ * 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(SnippetParserTest.class);
+ }
+} \ No newline at end of file