ScalaSnippetExecutor extends AbstractSnippetExecutor<ScalaSnippetExecutorOptions> { protected String buildSourceCode(final CodeSnippet codeSnippet) throws IOException { final StringBuilder sourceCode = new StringBuilder(); if (hasImports(codeSnippet)) { sourceCode.append(getImports(codeSnippet)).append("\n\n"); } sourceCode.append(getStartClassDefinition(codeSnippet)).append("\n"); if (mustBeWrappedIn(codeSnippet, WRAP_IN_MAIN_PROPERTY)) { sourceCode.append("\tdef main(args: Array[String]) {\n") .append(codeSnippet.getCode()) .append("\n\t}"); } else { sourceCode.append(codeSnippet.getCode()); } sourceCode.append("\n}"); return sourceCode.toString(); } ScalaSnippetExecutor(); @Override Parent getUI(final CodeSnippet codeSnippet); @Override Node getConfigurationUI(); @Override void saveNewOptions(); @Override ObservableList<String> execute(final CodeSnippet codeSnippet);  }
@Test public void buildSourceCodeWithoutImportsAndWithoutWrapInMainAndWithoutClassName() throws IOException { final CodeSnippet snippet = new CodeSnippet(); snippet.setCode("def main(args: Array[String]) {\n\tprintln(\"Hello\")\n}"); final String expected = IOUtils.read(ScalaSnippetExecutorTest.class.getResourceAsStream("/com/twasyl/slideshowfx/snippet/executor/scala/buildSourceCodeWithoutImportsAndWithoutWrapInMainAndWithoutClassName_expected.txt")); assertEquals(expected, snippetExecutor.buildSourceCode(snippet)); }
@Test public void buildSourceCodeWithoutImportsAndWithoutWrapInMain() throws IOException { final CodeSnippet snippet = new CodeSnippet(); snippet.getProperties().put(CLASS_NAME_PROPERTY, "TestScala"); snippet.setCode("def main(args: Array[String]) {\n\tprintln(\"Hello\")\n}"); final String expected = IOUtils.read(ScalaSnippetExecutorTest.class.getResourceAsStream("/com/twasyl/slideshowfx/snippet/executor/scala/buildSourceCodeWithoutImportsAndWithoutWrapInMain_expected.txt")); assertEquals(expected, snippetExecutor.buildSourceCode(snippet)); }
@Test public void buildSourceCodeWithoutWrapInMain() throws IOException { final CodeSnippet snippet = new CodeSnippet(); snippet.getProperties().put(CLASS_NAME_PROPERTY, "TestScala"); snippet.getProperties().put(IMPORTS_PROPERTY, "import mypackage\nmysecondpackage"); snippet.setCode("def main(args: Array[String]) {\n\tprintln(\"Hello\")\n}"); final String expected = IOUtils.read(ScalaSnippetExecutorTest.class.getResourceAsStream("/com/twasyl/slideshowfx/snippet/executor/scala/buildSourceCodeWithoutWrapInMain_expected.txt")); assertEquals(expected, snippetExecutor.buildSourceCode(snippet)); }
@Test public void buildSourceCode() throws IOException { final CodeSnippet snippet = new CodeSnippet(); snippet.getProperties().put(CLASS_NAME_PROPERTY, "TestScala"); snippet.getProperties().put(IMPORTS_PROPERTY, "import mypackage\nmysecondpackage"); snippet.getProperties().put(WRAP_IN_MAIN_PROPERTY, "true"); snippet.setCode("println(\"Hello\")"); final String expected = IOUtils.read(ScalaSnippetExecutorTest.class.getResourceAsStream("/com/twasyl/slideshowfx/snippet/executor/scala/buildSourceCode_expected.txt")); assertEquals(expected, snippetExecutor.buildSourceCode(snippet)); }