Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions com.rescripter.editor.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,9 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: RescripterEditorTests
Bundle-SymbolicName: com.rescripter.editor.test;singleton:=true
Fragment-Host: com.rescripter.editor
Bundle-Version: 1.0.7.qualifier
Require-Bundle: com.rescripter.jmock,
com.rescripter.rhino,
com.rescripter.editor,
org.eclipse.ui,
org.eclipse.ui.editors,
org.eclipse.core.resources,
org.eclipse.core.runtime,
org.eclipse.jface.text,
org.eclipse.ui.ide,
org.eclipse.jdt.core,
org.eclipse.jdt.ui,
org.junit4
Comment: org.junit must be after jmock, so Hamcrest 1.2 is used instead of 1.1 which comes with JUnit.
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ClassPath: .
2 changes: 1 addition & 1 deletion com.rescripter.editor.test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<parent>
<groupId>com.rescripter</groupId>
<artifactId>Rescripter</artifactId>
<artifactId>com.rescripter.parent</artifactId>
<version>1.0.7-SNAPSHOT</version>
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
package com.rescripter;

import static com.rescripter.ASTIntegrationTest.ASTNodeMatcher.a_node;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

import java.io.IOException;
import java.util.List;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.hamcrest.Description;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.junit.Test;

import com.rescripter.script.RunScript;

public class ASTIntegrationTest extends BaseRescripterIntegrationTest {

@Test public void
parses_compilation_unit() throws IOException, CoreException {
RunScript runScript = new RunScript(getWindow());
runScript.withContents(
"var person = Find.typeByName('Person');\n" +
"var ast = AST.parseCompilationUnit(person.getCompilationUnit());\n", null, "inline script");

ASTNode ast = runScript.getProperty(ASTNode.class, "ast");

assertThat(ast, is(notNullValue()));
assertThat(ast.toString(), containsString("public class Person"));
assertThat(ast.toString(), containsString("public Person("));
}

@SuppressWarnings("unchecked")
@Test public void
finds_covered_node() throws IOException, CoreException {
RunScript runScript = new RunScript(getWindow());
String methodCallText = "person.setName(\"Bob\")";
IType personType = getJavaProject().findType("com.example.Person");
String personSource = personType.getCompilationUnit().getSource();
int offsetOfCall = personSource.indexOf(methodCallText);
runScript.withContents(
"var person = Find.typeByName('Person');\n" +
"var ast = AST.parseCompilationUnit(person.getCompilationUnit());\n" +
"var node = AST.findCoveredNode(ast, " + offsetOfCall + ", " + methodCallText.length() + ");\n"
, null, "inline script");

MethodInvocation node = runScript.getProperty(MethodInvocation.class, "node");

assertThat(node, is(notNullValue()));
assertThat(node.getExpression().toString(), is("person"));
assertThat(node.getName().toString(), is("setName"));
assertThat((List<ASTNode>) node.arguments(),
Matchers.<ASTNode>hasItems(a_node().with_text_representation("\"Bob\"")));
}

public static final class ASTNodeMatcher extends TypeSafeDiagnosingMatcher<ASTNode> {
public static final ASTNodeMatcher a_node() {
return new ASTNodeMatcher();
}

private String text;

private ASTNodeMatcher() { }

public ASTNodeMatcher with_text_representation(String text) {
this.text = text;
return this;
}

public void describeTo(Description description) {
description.appendText("an ASTNode");
if (text != null) {
description.appendText(" with text representation '" + text + "'");
}
}

@Override
protected boolean matchesSafely(ASTNode node, Description description) {
description.appendText("an ASTNode");
if (text != null && !node.toString().equals(text)) {
description.appendText(" with text representation '" + node.toString() + "'");
return false;
}
return true;
}
}
}
package com.rescripter;
import static com.rescripter.ASTIntegrationTest.ASTNodeMatcher.a_node;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import java.io.IOException;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.hamcrest.Description;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.junit.Test;
import com.rescripter.script.RunScript;
public class ASTIntegrationTest extends BaseRescripterIntegrationTest {
@Test public void
parses_compilation_unit() throws IOException {
RunScript runScript = new RunScript(getWindow());
runScript.withContents(
"var person = Find.typeByName('Person');\n" +
"var ast = AST.parseCompilationUnit(person.getCompilationUnit());\n", null, "inline script");
ASTNode ast = runScript.getProperty(ASTNode.class, "ast");
assertThat(ast, is(notNullValue()));
assertThat(ast.toString(), containsString("public class Person"));
assertThat(ast.toString(), containsString("public Person("));
}
@SuppressWarnings("unchecked")
@Test public void
finds_covered_node() throws IOException, CoreException {
RunScript runScript = new RunScript(getWindow());
String methodCallText = "person.setName(\"Bob\")";
IType personType = getJavaProject().findType("com.example.Person");
String personSource = personType.getCompilationUnit().getSource();
int offsetOfCall = personSource.indexOf(methodCallText);
runScript.withContents(
"var person = Find.typeByName('Person');\n" +
"var ast = AST.parseCompilationUnit(person.getCompilationUnit());\n" +
"var node = AST.findCoveredNode(ast, " + offsetOfCall + ", " + methodCallText.length() + ");\n"
, null, "inline script");
MethodInvocation node = runScript.getProperty(MethodInvocation.class, "node");
assertThat(node, is(notNullValue()));
assertThat(node.getExpression().toString(), is("person"));
assertThat(node.getName().toString(), is("setName"));
assertThat((List<ASTNode>) node.arguments(),
Matchers.<ASTNode>hasItems(a_node().with_text_representation("\"Bob\"")));
}
public static final class ASTNodeMatcher extends TypeSafeDiagnosingMatcher<ASTNode> {
public static final ASTNodeMatcher a_node() {
return new ASTNodeMatcher();
}
private String text;
private ASTNodeMatcher() { }
public ASTNodeMatcher with_text_representation(String textRepresentation) {
this.text = textRepresentation;
return this;
}
public void describeTo(Description description) {
description.appendText("an ASTNode");
if (text != null) {
description.appendText(" with text representation '" + text + "'");
}
}
@Override
protected boolean matchesSafely(ASTNode node, Description description) {
description.appendText("an ASTNode");
if (text != null && !node.toString().equals(text)) {
description.appendText(" with text representation '" + node.toString() + "'");
return false;
}
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
package com.rescripter;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

import java.io.IOException;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.junit.Test;

import com.rescripter.script.RunScript;

public class FindIntegrationTest extends BaseRescripterIntegrationTest {
@Test public void
finds_types_by_name() throws IOException, CoreException {
RunScript runScript = new RunScript(getWindow());
runScript.withContents("var person = Find.typeByName('Person');\n", null, "inline script");
IType type = runScript.getProperty(IType.class, "person");
assertThat(type, is(notNullValue()));
assertThat(type, is(getJavaProject().findType("com.example.Person")));
}

@Test(expected=Exception.class) public void
fails_to_find_missing_type_by_name() throws IOException, CoreException {
RunScript runScript = new RunScript(getWindow());
runScript.withContents("var person = Find.typeByName('NotAPerson');\n", null, "inline script");
}

@Test public void
finds_method_by_name() throws IOException, CoreException {
RunScript runScript = new RunScript(getWindow());
runScript.withContents(
"var person = Find.typeByName('Person');\n" +
"var getName = Find.methodByName(person, 'getName');\n", null, "inline script");
assertThat(runScript.getProperty(IMethod.class, "getName"), is(notNullValue()));
}

@Test(expected=Exception.class) public void
fails_to_find_missing_method_by_name() throws IOException, CoreException {
RunScript runScript = new RunScript(getWindow());
runScript.withContents(
"var person = Find.typeByName('Person');\n" +
"var getName = Find.methodByName(person, 'noSuchGetName');\n", null, "inline script");
}
}
package com.rescripter;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import java.io.IOException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.junit.Test;
import com.rescripter.script.RunScript;
public class FindIntegrationTest extends BaseRescripterIntegrationTest {
@Test public void
finds_types_by_name() throws IOException, CoreException {
RunScript runScript = new RunScript(getWindow());
runScript.withContents("var person = Find.typeByName('Person');\n", null, "inline script");
IType type = runScript.getProperty(IType.class, "person");
assertThat(type, is(notNullValue()));
assertThat(type, is(getJavaProject().findType("com.example.Person")));
}
@Test(expected=Exception.class) public void
fails_to_find_missing_type_by_name() throws IOException {
RunScript runScript = new RunScript(getWindow());
runScript.withContents("var person = Find.typeByName('NotAPerson');\n", null, "inline script");
}
@Test public void
finds_method_by_name() throws IOException {
RunScript runScript = new RunScript(getWindow());
runScript.withContents(
"var person = Find.typeByName('Person');\n" +
"var getName = Find.methodByName(person, 'getName');\n", null, "inline script");
assertThat(runScript.getProperty(IMethod.class, "getName"), is(notNullValue()));
}
@Test(expected=Exception.class) public void
fails_to_find_missing_method_by_name() throws IOException {
RunScript runScript = new RunScript(getWindow());
runScript.withContents(
"var person = Find.typeByName('Person');\n" +
"var getName = Find.methodByName(person, 'noSuchGetName');\n", null, "inline script");
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
package com.rescripter;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

import java.io.IOException;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.JavaModelException;
import org.junit.Test;

import com.rescripter.script.RunScript;

public class RescripterIntegrationTest extends BaseRescripterIntegrationTest {

@Test public void
populates_java_project() throws JavaModelException {
assertThat(getJavaProject().findType("com.example.Person"), is(notNullValue()));
}

@Test public void
runs_basic_script() throws IOException, CoreException {
RunScript runScript = new RunScript(getWindow());
runScript.withContents("var response = 42;\n", null, "inline script");
assertThat(runScript.getIntegerProperty("response"), is(42));
}

}
package com.rescripter;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

import java.io.IOException;

import org.eclipse.jdt.core.JavaModelException;
import org.junit.Test;

import com.rescripter.script.RunScript;

public class RescripterIntegrationTest extends BaseRescripterIntegrationTest {

@Test public void
populates_java_project() throws JavaModelException {
assertThat(getJavaProject().findType("com.example.Person"), is(notNullValue()));
}

@Test public void
runs_basic_script() throws IOException {
RunScript runScript = new RunScript(getWindow());
runScript.withContents("var response = 42;\n", null, "inline script");
assertThat(runScript.getIntegerProperty("response"), is(42));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public class RunRescripterHandlerTest {
}});

RunRescripterHandler handler = new RunRescripterHandler() {
@Override protected IWorkbenchWindow getWindow(ExecutionEvent event) throws ExecutionException {
@Override protected IWorkbenchWindow getWindow(ExecutionEvent evnt) {
return window;
}
@Override protected ITextEditor getEditor() {
return editor;
}
@Override protected RunScript createRunScript(IWorkbenchWindow window) {
@Override protected RunScript createRunScript(IWorkbenchWindow win) {
return runScript;
}
};
Expand Down
Loading